MySQL¶
Functions/Procedures¶
from sqlalchemy_declarative_extensions import Functions, Procedures, Function, Procedure
functions = Functions().are(
Function("some_function", "INSERT INTO foo"),
...
)
procedures = Procedures().are(
Procedure("some_proc", "INSERT INTO foo"),
...
)
Note
Neither functions nor procedures currently support arguments!
While function/procedure detailed options do vary across dialects, it is possible to define functions/procedures with all default options such that a generic implementation can be useful.
As such, the above example does use the generic instances, but a dialect-specific variant
subclass exists at sqlalchemy_declarative_extensions.dialects.mysql.
Triggers¶
from sqlalchemy_declarative_extensions import Triggers
from sqlalchemy_declarative_extensions.dialects.mysql import Trigger
triggers = Triggers().are(
Trigger.before("insert", on="some_table", execute="SET NEW.value = NEW.value * 2")
.named("before_insert_some_table")
.follows("some_other_trigger")
)
Trigger options and semantics differ across the different dialects that support
them, which is the reason for the dialect-scoped dialects.mysql import above.
API¶
- class sqlalchemy_declarative_extensions.dialects.mysql.Function¶
Describes a MySQL function.
- data_access: FunctionDataAccess¶
- classmethod from_unknown_function(f)¶
- Parameters:
f (sqlalchemy_declarative_extensions.function.base.Function)
- Return type:
Self
- modifies_sql()¶
- no_sql()¶
- reads_sql()¶
- security: FunctionSecurity¶
- with_data_access(data_access)¶
- Parameters:
data_access (FunctionDataAccess)
- with_security(security)¶
- Parameters:
security (FunctionSecurity)
- with_security_definer()¶
- class sqlalchemy_declarative_extensions.dialects.mysql.FunctionSecurity¶
Generic enumeration.
Derive from this class to define new enumerations.
- definer = 'DEFINER'¶
- invoker = 'INVOKER'¶
- class sqlalchemy_declarative_extensions.dialects.mysql.Procedure¶
Describes a MySQL procedure.
- classmethod from_unknown_procedure(f)¶
- Parameters:
f (sqlalchemy_declarative_extensions.procedure.base.Procedure)
- Return type:
Self
- normalize()¶
Normalize the procedure definition by dedenting and normalize the SQL.
- Return type:
Self
- security: ProcedureSecurity¶
- with_security(security)¶
- Parameters:
security (ProcedureSecurity)
- with_security_definer()¶
- class sqlalchemy_declarative_extensions.dialects.mysql.ProcedureSecurity¶
Generic enumeration.
Derive from this class to define new enumerations.
- definer = 'DEFINER'¶
- invoker = 'INVOKER'¶
- class sqlalchemy_declarative_extensions.dialects.mysql.Trigger¶
Describes a MySQL trigger.
Some trigger options are not currently supported.
- classmethod after(event, on, execute, name='')¶
- Parameters:
event (TriggerEvents | str)
on (str)
execute (str)
name (str)
- classmethod before(event, on, execute, name='')¶
- Parameters:
event (TriggerEvents | str)
on (str)
execute (str)
name (str)
- event: TriggerEvents¶
- follows(other_trigger_name)¶
Set the trigger to be ordered after the provided trigger name.
- Parameters:
other_trigger_name (str)
- order: TriggerOrder | None = None¶
- precedes(other_trigger_name)¶
Set the trigger to be ordered before the provided trigger name.
- Parameters:
other_trigger_name (str)
- time: TriggerTimes¶
- to_sql_create()¶
Return a trigger CREATE statement.
CREATE TRIGGER trigger_name { BEFORE | AFTER } { INSERT | UPDATE | DELETE } ON table_name FOR EACH ROW [{ FOLLOWS | PRECEDES } other_trigger_name] trigger_body
- Return type:
- class sqlalchemy_declarative_extensions.dialects.mysql.TriggerEvents¶
Generic enumeration.
Derive from this class to define new enumerations.
- delete = 'DELETE'¶
- insert = 'INSERT'¶
- update = 'UPDATE'¶
- class sqlalchemy_declarative_extensions.dialects.mysql.TriggerOrder¶
Encodes the trigger order.
MySQL triggers can be (optionally) made to execute before/after a related trigger.
- order: TriggerOrders¶