= init_db() db
create database
Core database functionality for the keybindings_fps app. This module is meant to run once to create the database and tables. Don’t run this module again if the database already exists, because it will drop the existing tables.
Initialize database
init_db
init_db (data_dir:pathlib.Path=None)
Initialize the database connection Args: data_dir: Optional path to data directory. If None, uses project’s data dir
0].keys() db.t.actions()[
dict_keys(['id', 'name', 'description', 'category_id'])
Create the tables
create_tables
create_tables (db:<function database>, overwrite_existing:bool=False)
Create all required database tables.
Type | Default | Details | |
---|---|---|---|
db | database | Database connection | |
overwrite_existing | bool | False | Remove all existing data in database |
Open existing database in project data directory
= init_db() db
Check that the database is opened in the correct location
db.conn.filename
'/home/jelle/code/keybindings_fps/data/game_bindings.db'
Modify structure of database tables
Add a new column to an existing table
add_clmn_to_table
add_clmn_to_table (db, table, column, col_type, **kwargs)
Add a new column to an existing table
'bindings'].c db.t[
action_id, description, game_id, id, key_id, modifier_id, sort_order
'bindings', 'test', str, not_null_default='test text') add_clmn_to_table(db,
<Table bindings (id, game_id, action_id, key_id, modifier_id, description, sort_order, test)>
'bindings'].columns[-1].name, 'test') test_eq(db.t[
Delete/drop a column from an existing table
drop_clmn_from_table
drop_clmn_from_table (db, table, column)
Drop a column from an existing table
'bindings', 'test') drop_clmn_from_table(db,
<Table bindings (id, game_id, action_id, key_id, modifier_id, description, sort_order)>
'test' not in db.t['bindings'].c, True) test_eq(
db.conn.close()