Module marksman.db

A module that implements low level access to the database, for commonly used SQL operations.

Functions

def create_tables(cursor: sqlite3.Cursor)

Create all tables required by marksman

Args

cursor : Cursor
a sqlite3 Cursor object
def foreign_key_constraint(cursor: sqlite3.Cursor)

Turn on foreign key constraints

Args

cursor : Cursor
sqlite3 Cursor object
def gen_kv_str(kv_dict: dict, delim: str = 'AND') ‑> str

Generate key value strings

Args

kv_dict : dict
dictionary containing keys and values
delim : str, optional
the stuff to put in between. Defaults to 'AND'.

Returns

str
the rendered key value string

Classes

class DbModelz (table: str, cursor: sqlite3.Cursor)

Class to implement low level access to the database for common tasks

Constructor to initialize DbModelz object

Args

table : str
name of the table to work with
cursor : Cursor
sqlite3 Cursor object

Methods

def delete(self, **conds) ‑> NoneType

Deletes the entries satisfying given condtions

def exists(self, **conds) ‑> tuple

Checks whether an entry exists, based on given condition

Returns

tuple or None
returns the tuple containing the entity if exists else None
def fetch(self, **conds) ‑> list

Fetches a list of results based on condition parameters

Returns

list
[description]
def insert(self, values: tuple) ‑> NoneType

Inserts the values provided in the table

Args

values : tuple
values to insert
def query(self, query_string: str)

Execute a query using the Cursor and return all results

Args

query_string : str
the query to execute

Returns

list
results
def update(self, set_dict: dict, **conds) ‑> NoneType

Updates the table using set_string, based on given conditions

Args

set_string : str
the string to put beside SET keyword in SQL