1.2.1.2. models

This module provides the models for the data stored in the database as well as functionality for defining and managing the models themselves.

1.2.1.2.1. Data

database_tables[source]

A dictionary which contains all the database tables and their MetaTable instances.

SCHEMA_VERSION[source]

The schema version of the database, used for compatibility checks.

1.2.1.2.2. Functions

current_timestamp(*args, **kwargs)[source]

The function used for creating the timestamp used by database objects.

Returns:The current timestamp.
Return type:datetime.datetime
get_tables_with_column_id(column_id)[source]

Get all tables which contain a column named column_id.

Parameters:column_id (str) – The column name to get all the tables of.
Returns:The list of matching tables.
Return type:set
register_table(table)[source]

Register a database table. This will populate the information provided in DATABASE_TABLES dictionary. This also forwards signals to the appropriate listeners within the server.signal module.

Parameters:table (cls) – The table to register.
sql_null()[source]

Return a constant Null construct.

1.2.1.2.3. Classes

class BaseRowCls[source]

Bases: object

The base class from which other database table objects inherit from. Provides a standard __repr__ method and default permission checks which are to be overridden as desired by subclasses.

assert_session_has_permissions(*args, **kwargs)[source]

A convenience function which wraps session_has_permissions() and raises a KingPhisherPermissionError if the session does not have the specified permissions.

is_private = False[source]

Whether the table is only allowed to be accessed by the server or not.

classmethod metatable()[source]

Generate a MetaTable instance for this model class.

Returns:The appropriate metadata for the table represented by this model.
Return type:MetaTable
session_has_permissions(access, session)[source]

Check that the authenticated session has the permissions specified in access. The permissions in access are abbreviated with the first letter of create, read, update, and delete.

Parameters:
  • access (str) – The desired permissions.
  • session – The authenticated session to check access for.
Returns:

Whether the session has the desired permissions.

Return type:

bool

class MetaTable(column_names, model, name)[source]

Bases: tuple

Table metadata.

column_names[source]

A tuple of strings representing the table’s column names.

model[source]

The SQLAlchemy model class associated with this table.

name[source]

The name of this table.