OCDocker.DB.Models.Base module

Base class for all the tables in the database.

Usage:

from OCDocker.DB.Models.Base import base

class OCDocker.DB.Models.Base.Base(**kwargs)[source]

Bases: DeclarativeBase

Base class for all the tables.

Parameters:

kwargs (Any) –

classmethod __repr__()[source]

Return the representation of the object.

Returns:

The representation of the object.

Return type:

str

id = Column(None, Integer(), table=None, primary_key=True, nullable=False)
created_at = Column(None, DateTime(), table=None, server_default=DefaultClause(<sqlalchemy.sql.functions.now at 0x7fec6823bd90; now>, for_update=False))
modified_at = Column(None, DateTime(), table=None, onupdate=ColumnElementColumnDefault(<sqlalchemy.sql.functions.now at 0x7fec76bc4f90; now>))
name = Column(None, String(length=760), table=None, nullable=False)
classmethod add_dynamic_columns(collection)[source]

Dynamically add columns based on descriptor names.

Parameters:

collection (List[str]) – The collection of descriptors.

Return type:

None

classmethod delete(idorname)[source]

Delete data from the database.

Parameters:

idorname (Union[int, str]) – The ID or name of the data to be deleted.

Returns:

True if the data was deleted, False otherwise.

Return type:

bool

classmethod determine_column_type(descriptor)[source]

Determine the type of column based on the descriptor.

Parameters:

descriptor (str) – The descriptor name.

Returns:

The type of the column.

Return type:

Integer | Float

classmethod find_iter(idorname, batch_size=1000)[source]

Search data in the database and stream the rows.

Parameters:
  • idorname (Union[int, str]) – The ID or name of the data to be searched.

  • batch_size (int, optional) – Number of rows per fetch batch.

Returns:

Iterator with matching rows.

Return type:

Iterator[DeclarativeMeta]

classmethod find(idorname)[source]

Search data in the database.

Parameters:

idorname (Union[int, str]) – The ID or name of the data to be searched.

Returns:

The data found.

Return type:

List[DeclarativeMeta]

classmethod find_all_iter(batch_size=1000)[source]

Search all data in the database and stream the rows.

Parameters:

batch_size (int, optional) – Number of rows per fetch batch.

Returns:

Iterator with all rows.

Return type:

Iterator[DeclarativeMeta]

classmethod find_all()[source]

Search all data in the database.

Returns:

The data found.

Return type:

List[DeclarativeMeta]

classmethod find_all_names_iter(batch_size=1000)[source]

Search all names in the database and stream the rows.

Parameters:

batch_size (int, optional) – Number of rows per fetch batch.

Returns:

Iterator with all names.

Return type:

Iterator[str]

classmethod find_all_names()[source]

Search all names in the database.

Returns:

The names found.

Return type:

List[str]

classmethod find_attribute_iter(column, value, operator='==', batch_size=1000)[source]

Search data in the database based on an attribute and stream rows.

Parameters:
  • column (str) – The column name.

  • value (Any) – The value to be searched.

  • operator (str) – The operator to be used.

  • batch_size (int, optional) – Number of rows per fetch batch.

Returns:

Iterator with matching rows.

Return type:

Iterator[DeclarativeMeta]

classmethod find_attribute(column, value, operator='==')[source]

Search data in the database based on an attribute.

Parameters:
  • column (str) – The column name.

  • value (Any) – The value to be searched.

  • operator (str) – The operator to be used.

Returns:

The data found.

Return type:

List[DeclarativeMeta]

classmethod find_first(idorname)[source]

Search data in the database.

Parameters:

idorname (Union[int, str]) – The ID or name of the data to be searched.

Returns:

The first matching row, if any.

Return type:

DeclarativeMeta | None

classmethod insert(payload, ignorePresence=False)[source]

Insert data into the database.

Parameters:
  • payload (dict) – The data to be inserted.

  • ignorePresence (bool) – Whether to ignore the presence of the data in the database.

Returns:

True if the data was inserted, False otherwise.

Return type:

bool

classmethod insert_or_update(payload)[source]

Insert or update data in the database.

Parameters:

payload (dict) – The data to be inserted or updated.

Returns:

True if the data was inserted or updated, False otherwise.

Return type:

bool

classmethod to_dict()[source]

Return the object as a dictionary.

Returns:

The object as a dictionary.

Return type:

Dict[str, Any]

classmethod update(idorname, payload)[source]

Update data in the database.

Parameters:
  • idorname (Union[int, str]) – The ID or name of the data to be updated.

  • payload (dict) – The data to be updated.

Returns:

True if the data was updated, False otherwise.

Return type:

bool

metadata: ClassVar[MetaData] = MetaData()

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

See also

orm_declarative_metadata

registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

OCDocker.DB.Models.Base.base

alias of Base