editor.common.database
This module provide database manipulating toolkit.
Typical usage example:
1db = Database()
2db.connect('some/path/to/sample.db')
3db.affirmTable('foo')
4db.setBool('bool_test', True, 'foo')
5db.setObject('obj_test', {'hello':'world'}, 'foo')
6obj = db.getObject('obj_test', 'foo')
7print(obj)
8# db.clear('foo')
9db.close()
Module Contents
- class editor.common.database.Database[source]
Represent a database object powered by sqlite3.
Provide basic interface of database manipulating, including a set of setters, getters, and other useful utils.
- connect(path)[source]
Load database of specified path.
- Parameters:
path (str) – Source database path.
- doSql(cmd, commit=True)[source]
Execute specified sql command.
- Parameters:
cmd (str) – Specified command to execute.
commit (bool) – Commit database operation.
- createTable(table)[source]
Create a database with specified name.
- Parameters:
table (str) – Table name to create.
- hasTable(table)[source]
Check if has certain database table.
- Parameters:
table (str) – Table name to check.
- Returns:
Contains certain table or not.
- Return type:
bool
- affirmTable(table)[source]
Affirm a certain database table.
If table not exist, will create a new one.
- Parameters:
table (str) – Table name to affirm.
- dropTable(table)[source]
Drop a certain database table.
- Parameters:
table (str) – Table name to drop.
- clearTable(table)[source]
Clear a certain database table’s content.
- Parameters:
table (str) – Table name to clear.
- remove(name, table)[source]
Remove an entry in certain database table.
- Parameters:
name (str) – Entry primary key to remove.
table (str) – Table name to operate.
- set(name, data, table)[source]
Set an entry data in certain database table.
- Parameters:
name (str) – Entry primary key to set.
data (any) – Data to set, will be implicit converted str.
table (str) – Table name to operate.
- setBool(name, data, table)[source]
Set an boolean data in certain database table.
- Parameters:
name (str) – Entry primary key to set.
data (bool) – Boolean data to set.
table (str) – Table name to operate.
- setQVariant(name, data, table)[source]
Set an QVariant variable in certain database table.
- Parameters:
name (str) – Entry primary key to set.
Data (QVariant) – QVariant data to set.
table (str) – Table name to operate.
- setObject(name, obj, table)[source]
Set an object in certain database table.
- Parameters:
name (str) – Entry primary key to set.
obj (object) – Object data to set, will be serialized into json string.
table (str) – Table name to operate.
- get(name, table)[source]
Get an entry data in certain database table.
- Parameters:
name (str) – Entry primary key to get.
table (str) – Table name to get.
- Returns:
Found entry data.
- Return type:
str
- getBool(name, table)[source]
Get an boolean data in certain database table.
- Parameters:
name (str) – Fntry primary key to get.
table (str) – Fable name to get.
- Returns:
Found entry data.
- Return type:
bool