From 48742e0185fe1d0c1babe0db188cffe284d6ce88 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Thu, 24 May 2018 16:56:09 +0200 Subject: [PATCH] PyTables Row class based in list class for allow json serialization --- datasette_pytables/__init__.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 5d9fb22..d9530ae 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -232,12 +232,29 @@ class Connection: else: raise Exception("SQLite queries cannot be executed with this connector") -class Row(OrderedDict): - def __getitem__(self, label): - if type(label) is int: - return super(OrderedDict, self).__getitem__(list(self.keys())[label]) +class Row(list): + def __init__(self, values=None): + self.labels = [] + self.values = [] + if values: + for idx in values: + self.__setitem__(idx, values[idx]) + + def __setitem__(self, idx, value): + if type(idx) is str: + if idx in self.labels: + self.values[self.labels.index(idx)] = value + else: + self.labels.append(idx) + self.values.append(value) + else: + self.values[idx] = value + + def __getitem__(self, idx): + if type(idx) is str: + return self.values[self.labels.index(idx)] else: - return super(OrderedDict, self).__getitem__(label) + return self.values[idx] def __iter__(self): - return self.values().__iter__() + return self.values.__iter__() -- 2.39.5