cornflakes.decorator.datalite package

Submodules

cornflakes.decorator.datalite.commons module

cornflakes.decorator.datalite.commons.default_formatter(x)[Quellcode]
Parameter:

x (Any) –

Rückgabetyp:

Any

cornflakes.decorator.datalite.commons.generator_formatter(_)[Quellcode]
Parameter:

_ (Generator) –

Rückgabetyp:

None

cornflakes.decorator.datalite.commons.str_to_bool(s)[Quellcode]
Parameter:

s (str) –

Rückgabetyp:

bool

cornflakes.decorator.datalite.commons.uuid_formatter(x)[Quellcode]
Parameter:

x (UUID) –

Rückgabetyp:

bytes

cornflakes.decorator.datalite.constraints module

datalite.constraints module introduces constraint

types that can be used to hint field variables, that can be used to signal datalite decorator constraints in the database.

exception cornflakes.decorator.datalite.constraints.ConstraintFailedError[Quellcode]

Bases: Exception

This exception is raised when a Constraint fails.

cornflakes.decorator.datalite.constraints.Unique

Dataclass fields hinted with this type signals datalite that the bound column of this field in the table is NOT NULL and UNIQUE.

alias of Union[Tuple[T], T]

cornflakes.decorator.datalite.datalite_decorator module

Defines the Datalite decorator that can be used to convert a dataclass to a class bound to a sqlite3 database.

cornflakes.decorator.datalite.datalite_decorator.datalite(db_path, type_overload=None)[Quellcode]

Bind a dataclass to a sqlite3 database. This adds new methods to the class, such as create_entry(), remove_entry() and update_entry().

Parameter:
  • db_path (str) – Path of the database to be binded.

  • type_overload (Dict[type | None, str] | None) – Type overload dictionary.

Rückgabe:

The new dataclass.

Rückgabetyp:

Callable

cornflakes.decorator.datalite.datalite_decorator.remove_from(class_, obj_id)[Quellcode]
Parameter:
  • class_ (type) –

  • obj_id (int) –

cornflakes.decorator.datalite.fetch module

cornflakes.decorator.datalite.fetch.fetch_all(class_, page=0, element_count=10)[Quellcode]

Fetchall the records in the bound database.

Parameter:
  • class – Class of the records.

  • page (int) – Which page to retrieve, default all. (0 means closed).

  • element_count (int) – Element count in each page.

  • class_ (type) –

Rückgabe:

All the records of type class_ in the bound database as a tuple.

Rückgabetyp:

tuple

cornflakes.decorator.datalite.fetch.fetch_equals(class_, field, value)[Quellcode]

Fetch a class_ type variable from its bound db.

Parameter:
  • class – Class to fetch.

  • field (str) – Field to check for, by default, object id.

  • value (Any) – Value of the field to check for.

  • class_ (type) –

Rückgabe:

The object whose data is taken from the database.

Rückgabetyp:

Any

cornflakes.decorator.datalite.fetch.fetch_from(class_, obj_id)[Quellcode]

Fetch a class_ type variable from its bound dv.

Parameter:
  • class – Class to fetch from.

  • obj_id (int) – Unique object id of the object.

  • class_ (type) –

Rückgabe:

The fetched object.

Rückgabetyp:

Any

cornflakes.decorator.datalite.fetch.fetch_if(class_, condition, page=0, element_count=10)[Quellcode]

Fetch all class_ type variables from the bound db, provided they fit the given condition

Parameter:
  • class – Class type to fetch.

  • condition (str) – Condition to check for.

  • page (int) – Which page to retrieve, default all. (0 means closed).

  • element_count (int) – Element count in each page.

  • class_ (type) –

Rückgabe:

A tuple of records that fit the given condition of given type class_.

Rückgabetyp:

tuple

cornflakes.decorator.datalite.fetch.fetch_range(class_, range_)[Quellcode]

Fetch the records in a given range of object ids.

Parameter:
  • class – Class of the records.

  • range – Range of the object ids.

  • class_ (type) –

  • range_ (range) –

Rückgabe:

A tuple of class_ type objects whose values come from the class_‘ bound database.

Rückgabetyp:

tuple

cornflakes.decorator.datalite.fetch.fetch_where(class_, field, value, page=0, element_count=10)[Quellcode]

Fetch all class_ type variables from the bound db, provided that the field of the records fit the given value.

Parameter:
  • class – Class of the records.

  • field (str) – Field to check.

  • value (Any) – Value to check for.

  • page (int) – Which page to retrieve, default all. (0 means closed).

  • element_count (int) – Element count in each page.

  • class_ (type) –

Rückgabe:

A tuple of the records.

Rückgabetyp:

tuple

cornflakes.decorator.datalite.fetch.is_fetchable(class_, obj_id)[Quellcode]

Check if a record is fetchable given its obj_id and class_ type.

Parameter:
  • class – Class type of the object.

  • obj_id (int) – Unique obj_id of the object.

  • class_ (type) –

Rückgabe:

If the object is fetchable.

Rückgabetyp:

bool

cornflakes.decorator.datalite.mass_actions module

This module includes functions to insert multiple records to a bound database at one time, with one time open and closing of the database file.

exception cornflakes.decorator.datalite.mass_actions.HeterogeneousCollectionError[Quellcode]

Bases: Exception

:raiseif the passed collection is not homogeneous.

ie: If a List or Tuple has elements of multiple types.

cornflakes.decorator.datalite.mass_actions.copy_many(objects, db_name, protect_memory=True)[Quellcode]

Copy many records to another database, from their original database to new database, do not delete old records.

Parameter:
  • objects (List[T] | Tuple[T]) – Objects to copy.

  • db_name (str) – Name of the new database.

  • protect_memory (bool) – Wheter to protect memory during operation, Setting this to False will quicken the operation, but if the operation is cut short, database file will corrupt.

Rückgabe:

None

Rückgabetyp:

None

cornflakes.decorator.datalite.mass_actions.create_many(objects, protect_memory=True)[Quellcode]

Insert many records corresponding to objects in a tuple or a list.

Parameter:
  • protect_memory (bool) – If False, memory protections are turned off, makes it faster.

  • objects (List[T] | Tuple[T]) – A tuple or a list of objects decorated with datalite.

Rückgabe:

None.

Rückgabetyp:

None

cornflakes.decorator.datalite.migrations module

Migrations module deals with migrating data when the object definitions change. This functions deal with Schema Migrations.

cornflakes.decorator.datalite.migrations.basic_migrate(cls, column_transfer)[Quellcode]

Given a class, compare its previous table, delete the fields that no longer exist, create new columns for new fields. If the column_flow parameter is given, migrate elements from previous column to the new ones. It should be noted that, the obj_ids do not persist.

Parameter:
  • cls (type) – Datalite class to migrate.

  • column_transfer (Dict[str, str]) – A dictionary showing which columns will be copied to new ones.

Rückgabe:

None.

Rückgabetyp:

None

cornflakes.decorator.datalite.type_mapping module

class cornflakes.decorator.datalite.type_mapping.SQLTypes(value)[Quellcode]

Bases: Enum

SQL types for SQLite3.

autoincrement = 'AUTOINCREMENT'
blob = 'BLOB'
date = 'DATE'
foreign_key = 'FOREIGN KEY'
integer = 'INTEGER'
json = 'JSON'
null = 'NULL'
numeric = 'NUMERIC'
primary_key = 'PRIMARY KEY'
real = 'REAL'
text = 'TEXT'
time = 'TIME'
timestamp = 'TIMESTAMP'
unique = 'UNIQUE'
unique_not_null = 'NOT NULL UNIQUE'

Module contents

cornflakes.decorator.datalite.datalite(db_path, type_overload=None)[Quellcode]

Bind a dataclass to a sqlite3 database. This adds new methods to the class, such as create_entry(), remove_entry() and update_entry().

Parameter:
  • db_path (str) – Path of the database to be binded.

  • type_overload (Dict[type | None, str] | None) – Type overload dictionary.

Rückgabe:

The new dataclass.

Rückgabetyp:

Callable