tornado.database — Simple MySQL client wrapper
A lightweight wrapper around MySQLdb.
-
class tornado.database.Connection(host, database, user=None, password=None, max_idle_time=25200)[source]
A lightweight wrapper around MySQLdb DB-API connections.
The main value we provide is wrapping rows in a dict/object so that
columns can be accessed by name. Typical usage:
db = database.Connection("localhost", "mydatabase")
for article in db.query("SELECT * FROM articles"):
print article.title
Cursors are hidden by the implementation, but other than that, the methods
are very similar to the DB-API.
We explicitly set the timezone to UTC and the character encoding to
UTF-8 on all connections to avoid time zone and encoding errors.
-
close()[source]
Closes this database connection.
-
reconnect()[source]
Closes the existing database connection and re-opens it.
-
iter(query, *parameters)[source]
Returns an iterator for the given query and parameters.
-
query(query, *parameters)[source]
Returns a row list for the given query and parameters.
-
get(query, *parameters)[source]
Returns the first row returned for the given query.
-
execute(query, *parameters)[source]
Executes the given query, returning the lastrowid from the query.
-
execute_lastrowid(query, *parameters)[source]
Executes the given query, returning the lastrowid from the query.
-
execute_rowcount(query, *parameters)[source]
Executes the given query, returning the rowcount from the query.
-
executemany(query, parameters)[source]
Executes the given query against all the given param sequences.
We return the lastrowid from the query.
-
executemany_lastrowid(query, parameters)[source]
Executes the given query against all the given param sequences.
We return the lastrowid from the query.
-
executemany_rowcount(query, parameters)[source]
Executes the given query against all the given param sequences.
We return the rowcount from the query.
-
class tornado.database.Row[source]
A dict that allows for object-like property access syntax.