41 ms·
This is amazingly well-timed. Just yesterday I was complaining that the Python SQL libraries are annoying and verbose, and that I wished there was a library as
by yahelc 11y ago
This is amazingly well-timed. Just yesterday I was complaining that the Python SQL libraries are annoying and verbose, and that I wished there was a library as good as requests is for HTTP.
- masklinn 11y agowrt 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.