t.d.b.InteractionBase : class documentation

Part of twistar.dbconfig.base View In Hierarchy

Known subclasses: twistar.dbconfig.mysql.MySQLDBConfig, twistar.dbconfig.postgres.PostgreSQLDBConfig, twistar.dbconfig.pyodbc.PyODBCDBConfig, twistar.dbconfig.sqlite.SQLiteDBConfig

Class that specific database implementations extend.
Line # Kind Name Docs
0 Class Variable LOG If True, then all queries are logged using twisted.python.log.msg.
0 Class Variable includeBlankInInsert If True, then insert/update queries will include setting object properties that have not be set to null in their respective columns.
24 Method logEncode Encode the given string if necessary for printing to logs.
33 Method log Log the query and any args or kwargs using twisted.python.log.msg if InteractionBase.LOG is True.
47 Method executeOperation Simply makes same twisted.enterprise.dbapi.ConnectionPool.runOperation call, but with call to log function.
56 Method execute Simply makes same twisted.enterprise.dbapi.ConnectionPool.runQuery call, but with call to log function.
65 Method executeTxn Execute given query within the given transaction. Also, makes call to log function.
74 Method select Select rows from a table.
146 Method insertArgsToString Convert {'name': value} to an insert "values" string like "(%s,%s,%s)".
153 Method insert Insert a row into the given table.
179 Method escapeColNames Escape column names for insertion into SQL statement.
190 Method insertMany Insert many values into a table.
210 Method getLastInsertID Using the given txn, get the id of the last inserted row.
222 Method delete Delete from the given tablename.
239 Method update Update a row into the given table.
268 Method valuesToHash Given a row from a database query (values), create a hash using keys from the table schema and values from the given values;
290 Method getSchema Get the schema (in the form of a list of column names) for a given tablename. Use the given transaction if specified.
304 Method insertObj Insert the given object into its table.
323 Method updateObj Update the given object's row in the object's table.
340 Method refreshObj Update the given object based on the information in the object's table.
354 Method whereToString Convert a conditional to the form needed for a query using the DBAPI. For instance, for most DB's question marks in the query string have to be converted to %s. This will vary by database.
370 Method updateArgsToString Convert dictionary of arguments to form needed for DB update query. This method will vary by database driver.
385 Method count Get the number of rows in the given table (optionally, that meet the given where criteria).
126 Method _doselect Private callback for actual select query call.
LOG =
If True, then all queries are logged using twisted.python.log.msg.
includeBlankInInsert =
If True, then insert/update queries will include setting object properties that have not be set to null in their respective columns.
def logEncode(self, s, encoding='utf-8'):
Encode the given string if necessary for printing to logs.
def log(self, query, args, kwargs):
Log the query and any args or kwargs using twisted.python.log.msg if InteractionBase.LOG is True.
def executeOperation(self, query, *args, **kwargs):
Simply makes same twisted.enterprise.dbapi.ConnectionPool.runOperation call, but with call to log function.
def execute(self, query, *args, **kwargs):
Simply makes same twisted.enterprise.dbapi.ConnectionPool.runQuery call, but with call to log function.
def executeTxn(self, txn, query, *args, **kwargs):
Execute given query within the given transaction. Also, makes call to log function.
def select(self, tablename, id=None, where=None, group=None, limit=None, orderby=None, select=None):
Select rows from a table.
ParameterstablenameThe tablename to select rows from.
idIf given, only the row with the given id will be returned (or None if not found).
whereConditional of the same form as the where parameter in DBObject.find.
groupString describing how to group results.
limitInteger limit on the number of results. If this value is 1, then the result will be a single dictionary. Otherwise, if id is not specified, an array will be returned. This can also be a tuple, where the first value is the integer limit and the second value is an integer offset. In the case that an offset is specified, an array will always be returned.
orderbyString describing how to order the results.
selectColumns to select. Default is *.
ReturnsIf limit is 1 or id is set, then the result is one dictionary or None if not found. Otherwise, an array of dictionaries are returned.
def _doselect(self, txn, q, args, tablename, one=False):
Private callback for actual select query call.
def insertArgsToString(self, vals):
Convert {'name': value} to an insert "values" string like "(%s,%s,%s)".
def insert(self, tablename, vals, txn=None):
Insert a row into the given table.
ParameterstablenameTable to insert a row into.
valsValues to insert. Should be a dictionary in the form of {'name': value, 'othername': value}.
txnIf txn is given it will be used for the query, otherwise a typical runQuery will be used
ReturnsA Deferred that calls a callback with the id of new row.
def escapeColNames(self, colnames):
Escape column names for insertion into SQL statement.
ParameterscolnamesA List of string column names.
ReturnsA List of string escaped column names.
def insertMany(self, tablename, vals):
Insert many values into a table.
ParameterstablenameTable to insert a row into.
valsValues to insert. Should be a list of dictionaries in the form of {'name': value, 'othername': value}.
ReturnsA Deferred.
def getLastInsertID(self, txn):
Using the given txn, get the id of the last inserted row.
ReturnsThe integer id of the last inserted row.
def delete(self, tablename, where=None):
Delete from the given tablename.
ParameterswhereConditional of the same form as the where parameter in DBObject.find. If given, the rows deleted will be restricted to ones matching this conditional.
ReturnsA Deferred.
def update(self, tablename, args, where=None, txn=None):
Update a row into the given table.
ParameterstablenameTable to insert a row into.
argsValues to insert. Should be a dictionary in the form of {'name': value, 'othername': value}.
whereConditional of the same form as the where parameter in DBObject.find. If given, the rows updated will be restricted to ones matching this conditional.
txnIf txn is given it will be used for the query, otherwise a typical runQuery will be used
ReturnsA Deferred
def valuesToHash(self, txn, values, tablename):
Given a row from a database query (values), create a hash using keys from the table schema and values from the given values;
ParameterstxnThe transaction to use for the schema update query.
valuesA row from a db (as a list).
tablenameName of the table to fetch the schema for.
def getSchema(self, tablename, txn=None):
Get the schema (in the form of a list of column names) for a given tablename. Use the given transaction if specified.
def insertObj(self, obj):
Insert the given object into its table.
ReturnsA Deferred that sends a callback the inserted object.
def updateObj(self, obj):
Update the given object's row in the object's table.
ReturnsA Deferred that sends a callback the updated object.
def refreshObj(self, obj):
Update the given object based on the information in the object's table.
ReturnsA Deferred that sends a callback the updated object.
def whereToString(self, where):
Convert a conditional to the form needed for a query using the DBAPI. For instance, for most DB's question marks in the query string have to be converted to %s. This will vary by database.
ParameterswhereConditional of the same form as the where parameter in DBObject.find.
ReturnsA conditional in the same form as the where parameter in DBObject.find.
def updateArgsToString(self, args):
Convert dictionary of arguments to form needed for DB update query. This method will vary by database driver.
ParametersargsValues to insert. Should be a dictionary in the form of {'name': value, 'othername': value}.
ReturnsA tuple of the form ('name = %s, othername = %s, ...', argvalues).
def count(self, tablename, where=None):
Get the number of rows in the given table (optionally, that meet the given where criteria).
ParameterstablenameThe tablename to count rows from.
whereConditional of the same form as the where parameter in DBObject.find.
ReturnsA Deferred that returns the number of rows.
API Documentation for twistar, generated by pydoctor at 2012-06-12 10:00:49.