libgs.database.Database

class libgs.database.Database(db='sqlite:///libgs.db', binary_fmt='hex', get_from_disk=False, disk_threshold=None, disk_path=None)[source]

Class for low-level database access.

It can be connected to different engines; MySQL, SQLITE, etc…

Parameters:
  • db (str) – sqlalchemy engine connection string
  • binary_fmt (str[hex/b64]) – Format to store binary data as
  • get_from_disk (bool) – If True get linked content and insert in table before returning.
  • disk_threshold – Threshold (in bytes) before storing binary data to disk (None = do not store to disk)
  • disk_path – Absolute os path to store binary datafiles to

Note

If disk_threshold is specified, then data larger than <disk_theshold> bytes will be stored in the filesyste with only a reference inserted in the database.

The path in which it is stored is <disk_path>/comms. This path needs to be available and writeable. If it is not, an log message will be will be raised and the data stored in the database instead.

Methods

count_rows(table) Return the number of rows in a table
create_table(name, *columns, **kwargs) Set up the columns and add a unique key.
get_df(table[, where, limit, orderby, …]) Get data from communications database as a pandas.DataFrame object
get_file(fname) Grab a file resource and return the bytes or string (.bin or .txt)
put_df(table, df[, index, if_exists]) Add dataframe to database, appending metadata for when it was added

Inherited from base class