Meta models

This section of the documentation contains the code reference for the meta models available on cornflow.

Empty base model

class cornflow.models.meta_models.EmptyBaseModel(**kwargs)

Bases: Model

This is an empty abstract model that just implements some basic logic to be shared across all models.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

commit_changes(action: str | None = None)

This method is in charge to commit the changes to the database and perform a rollback in case there is an error, raising then an class:InvalidData exception

Parameters:

action (str) – the action that is being performed

Returns:

None

Return type:

None

save()

Method used to save a new object to the database

Returns:

None

Return type:

None

delete()

Method used to delete an object from the database

Returns:

None

Return type:

None

update(data: Dict)

Method used to update an object from the database

Parameters:

data (dict) – the data of the object

Returns:

None

Return type:

None

pre_update(data: Dict)

Method used to update the values of an object but not write it to the database :param dict data: the data of the object :return: None :rtype: None

classmethod get_all_objects(offset=0, limit=None, **kwargs)

Method to get all the objects from the database applying the filters passed as keyword arguments

Parameters:
  • offset (int) – query offset for pagination

  • limit (int) – query size limit

  • kwargs – the keyword arguments to be used as filters

Returns:

the query without being performed until and object is going to be retrieved or

iterated through the results. :rtype: class:Query

classmethod get_one_object(idx=None, **kwargs)

Method to retrieve an specific object from the database. This object can be retrieved with the primary key id or with a set of filters that should give back just one object, because the method is going to pick the first one. An example would be to filter by a column that has a unique constraint.

Parameters:
  • idx (str | int) – the id value for the primary key

  • kwargs – the keyword arguments passed to filter

Returns:

the retrieved object

Return type:

class:Model or any class that inherits from it

get(key: str)

Method used to get the value of any attribute of the model

Parameters:

key (str) – the attribute that we want to get the value from.

Returns:

the value of the given attribute

Return type:

Any

Trace attributes

class cornflow.models.meta_models.TraceAttributesModel

Bases: EmptyBaseModel

This abstract model is used to create the trace columns on all dependent models.

The trace columns are:

  • created_at: datetime, the datetime when the user was created (in UTC). This datetime is generated automatically, the user does not need to provide it.

  • updated_at: datetime, the datetime when the user was last updated (in UTC). This datetime is generated automatically, the user does not need to provide it.

  • deleted_at: datetime, the datetime when the user was deleted (in UTC). This field is used only if we deactivate instead of deleting the record. This datetime is generated automatically, the user does not need to provide it.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

update(data)

Method used to update an object from the database

Parameters:

data (dict) – the data of the object

Returns:

None

Return type:

None

pre_update(data)

Method used to update the values of an object but not write it to the database :param dict data: the data of the object :return: None :rtype: None

disable()

Method used to deactivate an object on the database (set the deleted_at date to the actual time stamp)

Returns:

None

Return type:

None

activate()

Method used to activate an object on the database (set the deleted_at date to None)

Returns:

None

Return type:

None

classmethod get_all_objects(creation_date_gte=None, creation_date_lte=None, deletion_date_gte=None, deletion_date_lte=None, update_date_gte=None, update_date_lte=None, offset=0, limit=None, **kwargs)

Method to get all the objects from the database applying the filters passed as keyword arguments

Parameters:
  • creation_date_gte (string) – created_at needs to be larger or equal to this

  • creation_date_lte (string) – created_at needs to be smaller or equal to this

  • deletion_date_gte (string) – deleted_at needs to be larger or equal to this,

  • deletion_date_lte (string) – deleted_at needs to be smaller or equal to this,

  • update_date_gte (string) – update_date_gte needs to be larger or equal to this,

  • update_date_lte (string) – update_date_lte needs to be smaller or equal to this,

  • offset (int) – query offset for pagination

  • limit (int) – query size limit

Returns:

The objects

Return type:

list(TraceAttributesModel)

classmethod get_one_object(idx=None, **kwargs)

Method to retrieve an specific object from the database. This object can be retrieved with the primary key id or with a set of filters that should give back just one object, because the method is going to pick the first one. An example would be to filter by a column that has a unique constraint.

Parameters:
  • idx (str | int) – the id value for the primary key

  • kwargs – the keyword arguments passed to filter

Returns:

the retrieved object

Return type:

class:Model or any class that inherits from it

Base data model

class cornflow.models.base_data_model.BaseDataModel(data)

Bases: TraceAttributesModel

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

classmethod get_all_objects(user, schema=None, creation_date_gte=None, creation_date_lte=None, deletion_date_gte=None, deletion_date_lte=None, id=None, update_date_gte=None, update_date_lte=None, user_name=None, last_name=None, email=None, role_id=None, url_rule=None, description=None, offset=0, limit=10)

Query to get all objects from a user

Parameters:
  • user (UserModel) – User object.

  • schema (string) – data_schema to filter (dag)

  • creation_date_gte (string) – created_at needs to be larger or equal to this

  • creation_date_lte (string) – created_at needs to be smaller or equal to this

  • deletion_date_gte (string) – deletion_at needs to be larger or equal to this

  • deletion_date_lte (string) – deletion_at needs to be smaller or equal to this

  • id (string) – user id

  • user_name (string) – user first name

  • last_name (string) – user last name

  • email (string) – user email

  • role_id (int) – user role id

  • url_rule (string) – url_rule

  • description (string) – description

  • update_date_gte (string) – update_at needs to be larger or equal to this

  • update_date_lte (string) – update_at needs to be smaller or equal to this

  • offset (int) – query offset for pagination

  • limit (int) – query size limit

Returns:

The objects

Return type:

list(BaseDataModel)

classmethod get_one_object(user=None, idx=None, **kwargs)

Query to get one object from the user and the id.

Parameters:
  • user (UserModel) – user object performing the query

  • idx (str or int) – ID from the object to get

Returns:

The object or None if it does not exist

Return type:

BaseDataModel