mafw.db.std_tables
Module provides standard tables that are included in all database created by MAFw processor.
Standard tables are automatically created and initialized by a Processor or a
ProcessorList when opening a database connection.
This means that if a processor receives a valid database object, then it will suppose that the connection was already opened somewhere else (either from a ProcessorList or a third party) and thus it is not creating the standard tables.
If a processor is constructed using a database configuration dictionary, then it will first try to open a connection
to the DB, then creating all standard tables and finally executing their StandardTable.init method. The same
apply for the Processor list.
In other words, object responsible to open the database connection is taking care also of creating the standard tables and of initializing them. If the user opens the connection and passes it to a Processor or ProcessorList, then the user is responsible to create the standard tables and to initialize them.
All standard tables must derive from the StandardTable to have the same interface for the
initialization.
Users can create their own standard tables and export them as a pluggable object using the same approach as for custom processors. An example is provided in the documentation.
Module Attributes
A dictionary containing the standard tables being exported to the rest of the framework. |
Classes
|
A Model for the files to be removed from disc |
|
A model for the output of the plotter processors. |
|
A base class for tables that are generated automatically by the MAFw processor. |
|
A helper tool to disable a specific type of triggers. |
|
A Model for the trigger status |
Exceptions
An exception raised when trying to access a not existing table. |
|
An exception raised when trying to access a not existing table. |
|
An exception raised when trying to access a not existing table. |
|
An exception raised when trying to access a not existing table. |
- exception mafw.db.std_tables.OrphanFileDoesNotExist[source]
Bases:
DoesNotExistAn exception raised when trying to access a not existing table.
- exception mafw.db.std_tables.PlotterOutputDoesNotExist[source]
Bases:
DoesNotExistAn exception raised when trying to access a not existing table.
- exception mafw.db.std_tables.StandardTableDoesNotExist[source]
Bases:
ExceptionAn exception raised when trying to access a not existing table.
- exception mafw.db.std_tables.TriggerStatusDoesNotExist[source]
Bases:
ExceptionAn exception raised when trying to access a not existing table.
- class mafw.db.std_tables.OrphanFile(*args, **kwargs)[source]
Bases:
StandardTableA Model for the files to be removed from disc
- DoesNotExist
alias of
OrphanFileDoesNotExist
- class mafw.db.std_tables.PlotterOutput(*args, **kwargs)[source]
Bases:
StandardTableA model for the output of the plotter processors.
The model has a trigger activated on delete queries to insert filenames and checksum in the OrphanFile model.
- DoesNotExist
alias of
PlotterOutputDoesNotExist
- class mafw.db.std_tables.StandardTable(*args, **kwargs)[source]
Bases:
MAFwBaseModelA base class for tables that are generated automatically by the MAFw processor.
- DoesNotExist
alias of
StandardTableDoesNotExist
- class mafw.db.std_tables.TriggerDisabler(trigger_type_id: int)[source]
Bases:
objectA helper tool to disable a specific type of triggers.
Not all SQL dialects allow to temporarily disable trigger execution.
In order overcome this limitation, MAFw has introduced a practical workaround. All types of triggers are active by default but they can be temporarily disabled, by changing their status in the
TriggerStatustable.In order to disable the trigger execution, the user has to set the status of the corresponding status to 0 and also add a when condition to the trigger definition.
Here is an example code:
class MyTable(MAFwBaseModel): id_ = AutoField(primary_key=True) integer = IntegerField() float_num = FloatField() @classmethod def triggers(cls): return [ Trigger( 'mytable_after_insert', (TriggerWhen.After, TriggerAction.Insert), cls, safe=True, ) .add_sql( 'INSERT INTO target_table (id__id, half_float_num) VALUES (NEW.id_, NEW.float_num / 2)' ) .add_when( '1 == (SELECT status FROM trigger_status WHERE trigger_type_id == 1)' ) ]
When you want to perform a database action with the trigger disabled, you can either use this class as context manager or call the
disable()andenable()methods.# as a context manager with TriggerDisabler(trigger_type_id = 1): # do something without triggering any trigger of type 1. # with the explicit methods disabler = TriggerDisabler(1) disabler.disable() # do something without triggering any trigger of type 1. disabler.enable()
When using the two explicit methods, the responsibility to assure that the triggers are re-enabled in on the user.
Constructor parameters:
- Parameters:
trigger_type_id (int) – the id of the trigger to be temporary disabled.
- class mafw.db.std_tables.TriggerStatus(*args, **kwargs)[source]
Bases:
StandardTableA Model for the trigger status
- DoesNotExist
alias of
TriggerStatusDoesNotExist
- mafw.db.std_tables.standard_tables: dict[str, type[StandardTable]] = {'OrphanFile': <Model: OrphanFile>, 'PlotterOutput': <Model: PlotterOutput>, 'TriggerStatus': <Model: TriggerStatus>}
A dictionary containing the standard tables being exported to the rest of the framework.
The key is the name of the model and the value is the model class itself.