Home | Trees | Indices | Help |
|
---|
|
object --+ | dict --+ | DAL
an instance of this class represents a database connection
Example:db = DAL('sqlite://test.db') db.define_table('tablename', Field('fieldname1'), Field('fieldname2'))
|
|||
Field an instance of this class represents a database field |
|||
Table an instance of this class represents a database table |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from |
|
|||
|
|||
|
|||
|
|
|||
Inherited from |
|
Creates a new Database Abstraction Layer instance. Keyword arguments: :uri: string that contains information for connecting to a database. (default: 'sqlite://dummy.db') :pool_size: How many open connections to make to the database object. :folder: <please update me> :db_codec: string encoding of the database (default: 'UTF-8') :check_reserved: list of adapters to check tablenames and column names against sql reserved keywords. (Default None) * 'common' List of sql keywords that are common to all database types such as "SELECT, INSERT". (recommended) * 'all' Checks against all known SQL keywords. (not recommended) <adaptername> Checks against the specific adapters list of keywords (recommended) * '<adaptername>_nonreserved' Checks against the specific adapters list of nonreserved keywords. (if available) :migrate (defaults to True) sets default migrate behavior for all tables :fake_migrate (defaults to False) sets default fake_migrate behavior for all tables :migrate_enabled (defaults to True). If set to False disables ALL migrations :fake_migrate_all (defaults to False). If sets to True fake migrates ALL tables :attempts (defaults to 5). Number of times to attempt connecting
|
|
|
EXAMPLE: db.define_table('person',Field('name'),Field('info')) db.define_table('pet',Field('person',db.person),Field('name'),Field('info')) @request.restful() def index(): def GET(*kargs,**kvars): patterns = [ "/persons[person]", "/{person.name.startswith}", "/{person.name}/:field", "/{person.name}/pets[pet.person]", "/{person.name}/pet[pet.person]/{pet.name}", "/{person.name}/pet[pet.person]/{pet.name}/:field" ] parser = db.parse_as_rest(patterns,kargs,kvars) if parser.status == 200: return dict(content=parser.response) else: raise HTTP(parser.status,parser.error) def POST(table_name,**kvars): if table_name == 'person': return db.person.validate_and_insert(**kvars) elif table_name == 'pet': return db.pet.validate_and_insert(**kvars) else: raise HTTP(400) return locals() |
|
|
|
|
|
placeholders is optional and will always be None when using DAL if using raw SQL with placeholders, placeholders may be a sequence of values to be substituted in or, *if supported by the DB driver*, a dictionary with keys matching named placeholders in your SQL. Added 2009-12-05 "as_dict" optional argument. Will always be None when using DAL. If using raw SQL can be set to True and the results cursor returned by the DB driver will be converted to a sequence of dictionaries keyed with the db field names. Tested with SQLite but should work with any database since the cursor.description used to get field names is part of the Python dbi 2.0 specs. Results returned with as_dict = True are the same as those returned when applying .to_list() to a DAL query. [{field1: value1, field2: value2}, {field1: value1b, field2: value2b}] --bmeredyk |
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Aug 4 00:47:00 2011 | http://epydoc.sourceforge.net |