# datalite package

## datalite Module

`@``datalite.``datalite`(db_path: str, type_overload: Optional[Dict[Optional[type], str]] = None) → Callable

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

  Parameters

    - db_path – Path of the database to be binded.

    - type_overload – Type overload dictionary.

  Returns

    The new dataclass.

## datalite.fetch module

`datalite.fetch.``fetch_all`(class_: type, page: int = 0, element_count: int = 10) → tuple

  Fetchall the records in the bound database.

  Parameters

    - class – Class of the records.

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

    - element_count – Element count in each page.

  Returns

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

`datalite.fetch.``fetch_equals`(class_: type, field: str, value: Any) → Any

  Fetch a class_ type variable from its bound db.

  Parameters

    - class – Class to fetch.

    - field – Field to check for, by default, object id.

    - value – Value of the field to check for.

  Returns

    The object whose data is taken from the database.

`datalite.fetch.``fetch_from`(class_: type, obj_id: int) → Any

  Fetch a class_ type variable from its bound dv.

  Parameters

    - class – Class to fetch from.

    - obj_id – Unique object id of the object.

  Returns

    The fetched object.

`datalite.fetch.``fetch_if`(class_: type, condition: str, page: int = 0, element_count: int = 10) → tuple

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

  Parameters

    - class – Class type to fetch.

    - condition – Condition to check for.

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

    - element_count – Element count in each page.

  Returns

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

`datalite.fetch.``fetch_range`(class_: type, range_: range) → tuple

  Fetch the records in a given range of object ids.

  Parameters

    - class – Class of the records.

    - range – Range of the object ids.

  Returns

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

`datalite.fetch.``fetch_where`(class_: type, field: str, value: Any, page: int = 0, element_count: int = 10) → tuple

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

  Parameters

    - class – Class of the records.

    - field – Field to check.

    - value – Value to check for.

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

    - element_count – Element count in each page.

  Returns

    A tuple of the records.

`datalite.fetch.``is_fetchable`(class_: type, obj_id: int) → bool

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

  Parameters

    - class – Class type of the object.

    - obj_id – Unique obj_id of the object.

  Returns

    If the object is fetchable.

## datalite.migrations module

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

`datalite.migrations.``basic_migrate`(class_: type, column_transfer: dict = None) → None

  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.

  Parameters

    - class – Datalite class to migrate.

    - column_transfer – A dictionary showing which columns will be copied to new ones.

  Returns

    None.