proteindf_bridge.dbmanager module

class proteindf_bridge.dbmanager.DbManager(db=':memory:', sql_debugout=False)[source]

Bases: object

>>> db = DbManager()
>>> db.create_table('table1', ['id', 'coulumn1', 'coulumn2'], 'id')
>>> db.get_table_names()
[u'table1']
>>> db.has_table('table1')
True
>>> db.get_field_names('table1')
['id', 'coulumn1', 'coulumn2']
>>> db.insert('table1', {'id':1, 'coulumn1':'Aichi', 'coulumn2':'Nagoya'})
>>> db.insert('table1', {'id':2, 'coulumn1':'Miyagi', 'coulumn2':'Sendai'})
>>> db.insert('table1', {'id':3, 'coulumn1':'Tokyo', 'coulumn2':'Tokyo'})
>>> db.select('table1', where='coulumn1 = "Tokyo"')
[{'coulumn1': u'Tokyo', 'coulumn2': u'Tokyo', 'id': 3}]
>>> db.update('table1', contents={'coulumn2':'Shinjuku'},         where='coulumn1 = "Tokyo"')
>>> db.select('table1', where='coulumn1 = "Tokyo"')
[{'coulumn1': u'Tokyo', 'coulumn2': u'Shinjuku', 'id': 3}]
>>> db.select('table1')
[{'coulumn1': u'Aichi', 'coulumn2': u'Nagoya', 'id': 1}, {'coulumn1': u'Miyagi', 'coulumn2': u'Sendai', 'id': 2}, {'coulumn1': u'Tokyo', 'coulumn2': u'Shinjuku', 'id': 3}]
>>> db.delete('table1', where='id = 1')
>>> db.select('table1')
[{'coulumn1': u'Miyagi', 'coulumn2': u'Sendai', 'id': 2}, {'coulumn1': u'Tokyo', 'coulumn2': u'Shinjuku', 'id': 3}]
create_table(table_name, field_names, primary_key=None)[source]

Create a TABLE.

table_name: the table name field_names: the field (column) names. If no type is specified, field_names should be a list. If a type is specified, field_names should be a dict of {name: type}.

delete(table, where)[source]

Delete a data record.

execute(sql, parameters=None)[source]

Execute the SQL.

get_field_names(table_name, fields='*')[source]

Return the fields within the specified TABLE as a list.

get_primary_keys(table_name)[source]

Return the list of field names under the primary key constraint.

get_results(sql)[source]

Execute the SQL and return the results as a list.

get_table_names()[source]

Return the TABLE names as a list.

get_user_version()[source]

Return the user version.

has_table(table_name)[source]

Return whether the specified TABLE exists.

insert(table, contents)[source]

Insert a data record.

contents is a dict keyed by field.

pp(data=None, check_row_lengths=True)[source]

pretty print for cursor data

pp_table(table_name)[source]

pretty print for table

select(table, fields=None, where=None)[source]

Retrieve data. Only AND is supported in the where clause.

set_user_version(version)[source]

Set the user version.

update(table, contents, where)[source]

Update a data record.

contents and where are dicts keyed by field.