using OrderedDict to preserve key order

This commit is contained in:
Gregor Aisch 2013-12-20 00:01:26 +01:00
parent 03cca31b5b
commit 2566581442
2 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,9 @@
import logging
from itertools import count
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict # Python < 2.7 drop-in
from sqlalchemy.sql import and_, expression
from sqlalchemy.schema import Column, Index
@ -280,7 +284,7 @@ class Table(object):
rp = self.database.executable.execute(query)
data = rp.fetchone()
if data is not None:
return dict(zip(rp.keys(), data))
return OrderedDict(zip(rp.keys(), data))
def _args_to_order_by(self, order_by):
if order_by[0] == '-':

View File

@ -1,5 +1,9 @@
from datetime import datetime
from inspect import isgenerator
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict # Python < 2.7 drop-in
from sqlalchemy import Integer, UnicodeText, Float, DateTime, Boolean
@ -46,7 +50,7 @@ class ResultIter(object):
else:
# stop here
raise StopIteration
return dict(zip(self.keys, row))
return OrderedDict(zip(self.keys, row))
def __iter__(self):
return self