Skip to content

Instantly share code, notes, and snippets.

@cloverstd
Forked from qpleple/torndb-examples.py
Created October 19, 2013 12:05
Show Gist options
  • Save cloverstd/7055170 to your computer and use it in GitHub Desktop.
Save cloverstd/7055170 to your computer and use it in GitHub Desktop.
from torndb import Connection
db = Connection('/tmp/mysql.sock', 'research', user='root', password='root')
# Official doc: http://torndb.readthedocs.org/en/latest/
# Retreive one object
post = db.get("SELECT * FROM posts LIMIT 1")
# Retreive several objects
for post in db.query("SELECT * FROM posts"):
print post.title
# INSERT
db.execute("INSERT INTO posts (user_id, content) VALUES (%s, %s)", 12, "hello world !")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment