Treat columns as ordered throughout code

The set() does not make anything any easier,
lists are closer to underlying representation.
This commit is contained in:
Stefan Wehrmeyer 2014-01-31 20:42:04 +01:00
parent 89ebd62732
commit 8f4cd59c9a
3 changed files with 8 additions and 6 deletions

View File

@ -25,7 +25,7 @@ class Table(object):
""" """
Get a listing of all columns that exist in the table. Get a listing of all columns that exist in the table.
""" """
return set(self.table.columns.keys()) return list(self.table.columns.keys())
def drop(self): def drop(self):
""" """
@ -184,7 +184,10 @@ class Table(object):
self.database.executable.execute(stmt) self.database.executable.execute(stmt)
def _ensure_columns(self, row, types={}): def _ensure_columns(self, row, types={}):
for column in set(row.keys()) - set(self.table.columns.keys()): # Keep order of inserted columns
for column in row.keys():
if column in self.table.columns.keys():
continue
if column in types: if column in types:
_type = types[column] _type = types[column]
else: else:

View File

@ -76,8 +76,8 @@ database:
Now, let's list all columns available in the table ``user``: Now, let's list all columns available in the table ``user``:
>>> print db['user'].columns >>> print(db['user'].columns)
set([u'id', u'name', u'email', u'pwd', u'country']) [u'id', u'name', u'email', u'pwd', u'country']
Using ``len()`` we can get the total number of rows in a table: Using ``len()`` we can get the total number of rows in a table:

View File

@ -229,8 +229,7 @@ class TableTestCase(unittest.TestCase):
def test_columns(self): def test_columns(self):
cols = self.tbl.columns cols = self.tbl.columns
assert isinstance(cols, set), 'columns should be a set' assert len(list(cols)) == 4, 'column count mismatch'
assert len(cols) == 4, 'column count mismatch'
assert 'date' in cols and 'temperature' in cols and 'place' in cols assert 'date' in cols and 'temperature' in cols and 'place' in cols
def test_iter(self): def test_iter(self):