3 ms·
wrt basic behaviour, this library seems to save all of two lines which can easily be bundled in a convenience function: def query(connection, q): c
by masklinn 11y ago
wrt basic behaviour, this library seems to save all of two lines which can easily be bundled in a convenience function:
def query(connection, q):
cursor = connection.cursor(cursor_factory=psycopg2.extras.DictCursor)
cursor.execute(q)
return iter(cursor.fetchone, None)
# db = records.Database('postgres://...')
db = psycopg2.connect('postgres://...')
# rows = db.query('select * from active_users')
rows = query(db, 'select * from active_users')
# rows.next()
next(rows)
# for row in rows:
# spam_user(name=row['name'], email=row['user_email'])
for row in rows:
spam_user(name=row['name'], email=row['user_email'])
# rows.all()
list(rows)
- monkmartinez 11y agoYou are right, thanks for the example. I checked the psycopg2 library after reading the announcement which drove my confusion. Psycopg is a super straightforward db driver. I wonder if this is the start of an orm built on top of psycopg2...? color me confused.