Commit 91bd33ca authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[dataimport] new 'lazydbtable' generator function to feed data from a database table

--HG--
branch : stable
parent 3bcccd3ab6b6
...@@ -146,6 +146,19 @@ def lazytable(reader): ...@@ -146,6 +146,19 @@ def lazytable(reader):
for row in reader: for row in reader:
yield dict(zip(header, row)) yield dict(zip(header, row))
def lazydbtable(cu, table, headers):
"""return an iterator on rows of a sql table. On each row, fetch columns
defined in headers and return values as a dictionary.
>>> data = lazydbtable(cu, 'experimentation', ('id', 'nickname', 'gps'))
"""
cu.execute('SELECT %s FROM %s' % (','.join(headers), table,))
while True:
row = cu.fetchone()
if row is None:
break
yield dict(zip(headers, row))
def mk_entity(row, map): def mk_entity(row, map):
"""Return a dict made from sanitized mapped values. """Return a dict made from sanitized mapped values.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment