Skip to content

Instantly share code, notes, and snippets.

@bpollack
Created March 27, 2015 18:52
Show Gist options
  • Save bpollack/07f29256eccfe66b43eb to your computer and use it in GitHub Desktop.
Save bpollack/07f29256eccfe66b43eb to your computer and use it in GitHub Desktop.
My Favorite Python ORM
db = sqlite3.connect(path_to_db)
db.row_factory = sqlite3.Row
def q(db, query, args=(), one=False):
cur = db.execute(query, args)
rv = cur.fetchall()
return (rv[0] if rv else None) if one else rv
def c(db, query=None, args=(), one=False):
if query:
q(db, query, args, one)
db.commit()
@bpollack
Copy link
Author

BTW, this is adapted from something I stole from someone else; it's not original with me. If I knew where I'd stole it from, I'd link them, but I just don't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment