Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
923013173031
Commit
91bd33ca
authored
Apr 01, 2011
by
Sylvain Thénault
Browse files
[dataimport] new 'lazydbtable' generator function to feed data from a database table
--HG-- branch : stable
parent
3bcccd3ab6b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
dataimport.py
View file @
92301317
...
...
@@ -146,6 +146,19 @@ def lazytable(reader):
for
row
in
reader
:
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
):
"""Return a dict made from sanitized mapped values.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment