principia_materia.utils.db_utils module
- class principia_materia.utils.db_utils.SQLiteDB(database)
- Bases: - object- Interface to SQLite database. - Parameters:
- database (str) – The path to the database file. 
 - commit()
- Commit the current transaction. 
 - create_table(table, columns, exists=True)
- Create a table. - Parameters:
- table (str) – The name of the table. 
- columns (list of str) – The columns to create in the table. 
- exists (bool, optional, default to True) – If True, do not throw and error when table exists. Otherwise. an error will be thrown if table exits. 
 
 
 - property cursor
- Get the Cursor object of the database. - Returns:
- cursor – The Cursor object. 
- Return type:
- Cursor 
 
 - execute(sql, parameters=None)
- Execute SQLl command with parameters. - Parameters:
- sql (str) – The SQL command. 
- parameters (tuple, optional, default to None) – The parameters in the SQL command. 
 
 
 - get_column_names(table)
- Get the column names of a table. - Parameters:
- table (str) – The name of the table. 
 
 - insert_to_table(table, data)
- Inseart a new row into a table. - Parameters:
- table (str) – The name of the table. 
- data (dict) – The values to insert into the new row of the table. 
 
 
 - row_in_table(table, key, value)
- Check if a row is in a table. - Parameters:
- table (str) – The name of the table. 
- key (str) – A column name in the table. 
- value (str) – The value of the column to match in the table. 
 
- Returns:
- flat – Whether the row is in the table. 
- Return type:
- bool 
 
 - search_table(table, keys, match_column={}, search_conditions=None)
- Search in a table. - The found rows can be retrieved from the Cursor object. - Parameters:
- table (str) – The name of the table. 
- match_column (dict) – The column match conditions. 
- search_conditions (list of str, optional, default to None) – Search conditions other than column matches. 
- keys (list of str) – The columns of the table to return. 
 
 
 - table_exists(table)
- Check if table exists. - Parameters:
- table (str) – The name of the table. 
- Returns:
- flat – Whether the table exits. 
- Return type:
- bool 
 
 - update_table(table, match_column, data)
- Update new row into a table. - Parameters:
- table (str) – The name of the table. 
- match_column (dict) – The column match conditions. 
- data (dict) – The values to insert into the new row of the table. 
 
 
 
- principia_materia.utils.db_utils.adapt_array(arr)
- Converts np.array to TEXT when inserting - http://stackoverflow.com/a/31312102/190597 (SoulNibbler) 
- principia_materia.utils.db_utils.convert_array(text)
- Converts TEXT to np.array when selecting