DB

class dbbase.DB(config, model_class=None, checkfirst=True, echo=False, *args, **kwargs)[source]

Bases: object

This class defines a central location for accepting database configuration information, creating connections and sessions.

Default:

DB(config, model_class=None, checkfirst=True, echo=False)

Parameters
  • config – (str) : Configuration string for the database, the equivalent of SQLALCHEMY_DATABASE_URI.

  • model_class – (obj) : An alternate Model class can be inserted. Otherwise it defaults to Model in this package.

  • checkfirst – (bool) : create tables only if the table does not exist

  • echo – (bool) : log actions in database engine

Methods

apply_db(cls)

This function receives a Model class and applies db and session to the class.

create_all([bind, checkfirst])

This function creates all available tables.

create_engine([echo])

Basically a pass through to sqlalchemy.

create_session([checkfirst, echo])

This function instantiates an engine, and connects to the database.

doc_column(cls, column_name)

This function extracts the documentation dictionary for a column.

doc_table(cls[, to_camel_case, …])

This function creates a dictionary of a table configuraton to aid in documenting.

doc_tables([class_list, to_camel_case])

This function creates a dictionary of all the table configuratons.

drop_all([tables, checkfirst, echo])

Drop all tables and sequences.

get_table_list()

This function returns a list of tables as found in the database.

load_model_class([model_class])

This function creates a fresh copy of the declarative base.