![]() |
Français |
Documentation
Contacts
Code
|
SQLite adapterThe main difference with the pure-Python module is the syntax to identify a database and a table, and the need to specify field types on base creation For compliance with SQLite vocabulary, the module defines two classes, Database
Instances of
To create a new table : table = db.create(table_name,*fields[,mode])
The fields must be 2-element tuples (field_name,field_type) where field_type is an SQLite field type : db.create('test',('name','TEXT'),('age','INTEGER'),('size','REAL'))
If other information needs to be provided, put it in the second argument, using the SQL syntax for SQLite : db.create('test',('date','BLOB DEFAULT CURRENT_DATE'))
The optional keyword argument mode specifies what you want to do if a table of the same name already exists in the file system
TableFor record insertion, updating, deletion and selection the syntax is the same as for the pure-Python module. The SQLite primary key To insert many records at a time, table.insert(list_of_values)
will be much faster than for values in list_of_values:
table.insert(values) Note that you can't use the Conversions between Python types and SQLite field types use the behaviour of the Python SQLite module : Selection methods return dictionaries, with SQLite types converted to Python types like this :
If you want fields to be returned as instances of db = Database('test.sqlite')
table = db['dummy'] table.is_date('birthday')
Intances of |