Functions#

from sqlalchemy.orm import declarative_base
from sqlalchemy_declarative_extensions import declarative_database, Function, Functions

_Base = declarative_base()

@declarative_database
class Base(_Base):
    __abstract__ = True

    functions = Functions().are(
        Function("gimme", "SELECT 1;", returns="INTEGER"),
        Function(
            "fancy_trigger",
            """
            BEGIN
            INSERT INTO foo (id) select NEW.id + 1;
            RETURN NULL;
            END
            """,
            language="plpgsql",
            returns="trigger",
        )
    )

Note

Functions options are wildly different across dialects. As such, you should likely always use the diaelect-specific Function object.

Note

Function behavior (for eaxmple…arguments) is not fully implemented at current time, although it should be functional for the options it does support. Any ability to instantiate an object which produces a syntax error should be considered a bug. Additionally, feature requests for supporting more function options are welcome!

In particular, the current function support is heavily oriented around support for defining triggers.

class sqlalchemy_declarative_extensions.function.base.Function#

Describes a user defined function.

Many function attributes are not currently supported. Support is currently minimal due to being a means to an end for defining triggers.

definition#
language = sql#
name#
abstract normalize()#
Return type

Function

property qualified_name#
returns = void#
schema#
to_sql_create(replace=False)#
to_sql_drop()#
to_sql_update()#
class sqlalchemy_declarative_extensions.function.base.Functions#
append(function)#
Parameters

function (Function) –

are(*functions)#
Parameters

functions (Function) –

classmethod coerce_from_unknown(unknown)#
Parameters

unknown (None | Iterable[Function] | Functions) –

Return type

Functions | None

functions#
ignore_unspecified = False#
sqlalchemy_declarative_extensions.function.base.register_function(base_or_metadata, function)#

Register a function onto the given declarative base or Metadata.

This can be used instead of the static registration through Functions on a declarative base or MetaData, to imperitively register functions.

Parameters
  • base_or_metadata (HasMetaData | MetaData) –

  • function (Function) –