Continue to refactor the import for "dataset"
This commit is contained in:
parent
ef535a4855
commit
22255c3894
13
dataset/persistence/util.py
Normal file
13
dataset/persistence/util.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
def resultiter(rp):
|
||||||
|
""" SQLAlchemy ResultProxies are not iterable to get a
|
||||||
|
list of dictionaries. This is to wrap them. """
|
||||||
|
keys = rp.keys()
|
||||||
|
while True:
|
||||||
|
row = rp.fetchone()
|
||||||
|
if row is None:
|
||||||
|
break
|
||||||
|
yield dict(zip(keys, row))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -2,19 +2,11 @@ import logging
|
|||||||
from itertools import count
|
from itertools import count
|
||||||
|
|
||||||
from sqlalchemy.sql import expression, and_
|
from sqlalchemy.sql import expression, and_
|
||||||
from sqlaload.schema import _ensure_columns, get_table
|
from dataset.schema import _ensure_columns, get_table
|
||||||
|
from dataset.persistence.util import resultiter
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
def resultiter(rp):
|
|
||||||
""" SQLAlchemy ResultProxies are not iterable to get a
|
|
||||||
list of dictionaries. This is to wrap them. """
|
|
||||||
keys = rp.keys()
|
|
||||||
while True:
|
|
||||||
row = rp.fetchone()
|
|
||||||
if row is None:
|
|
||||||
break
|
|
||||||
yield dict(zip(keys, row))
|
|
||||||
|
|
||||||
def find_one(engine, table, **kw):
|
def find_one(engine, table, **kw):
|
||||||
table = get_table(engine, table)
|
table = get_table(engine, table)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user