-
Notifications
You must be signed in to change notification settings - Fork 0
Python
Cory Cook edited this page Apr 10, 2014
·
2 revisions
Be sure to import Db
from db import DbUse a connection string to connect to your database
db = Db('DSN=DSNNAME')Select a table to perform actions on
db.table('tablename')To search for a particular string in a column
db.search('column', 'value')To search for a numeric value in a column
db.search('column', 1)To search for a match in a set of values
db.search('column', [1, 2, 3])To copy connection and table information
db2 = Db(db)To search for a match in a subquery
db = Db('DSN=DSNNAME')
db2 = Db(db)
db2.search('column2', 'value2')
db.search('column', db2)Warning: the above query is the same as the following
db = Db('DSN=DSNNAME')
db2 = Db(db)
db.search('column', db2)
db2.search('column2', 'value2')This is due to the fact that the sub-query is not evaluated until the primary query serialized
To sort a set of data
db.sort('column')To group by a column
db.group('column')To select columns to return
db.select('column')Sort, group, and select can be called for multiple values. For example:
db.select('column1')
db.select('column2')or
db.select(['column1', 'column2'])Search can be called for multiple columns as well
db.search('column1', 'value1')
db.search('column2', 2)