Created
March 27, 2015 18:52
-
-
Save bpollack/07f29256eccfe66b43eb to your computer and use it in GitHub Desktop.
My Favorite Python ORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.