API#
- class sqlalchemy_declarative_extensions.schema.Schemas#
A collection of schemas and the settings for diff/collection.
- Parameters
schemas – The list of grants
ignore_unspecified – Optionally ignore detected grants which do not match the set of defined grants.
Examples
No schemas
>>> schemas = Schemas()
Some options set
>>> schemas = Schemas(ignore_unspecified=True)
With some actual schemas
>>> from sqlalchemy_declarative_extensions import Schema, Schemas >>> schema = Schemas().are("foo", Schema("bar"), ...)
- classmethod coerce_from_unknown(unknown)#
- ignore_unspecified = False#
- schemas = []#
Decorate a class or declarative base model in order to register a View.
Given some object with the attributes: __tablename__, (optionally for schema) __table_args__, and __view__, registers a View object.
The __view__ attribute can be either a raw string query, or a SQLAlchemy object
capable of being compiled (namely text()
or select()
).
This intentionally allows one to register a Model definition as a view, and have it register in the same way you might otherwise manually define it. This can be useful, to enable querying that view in native SQLAlchemy ORM-style, as though it were a table.
- param base
A declarative base object.
- param materialized
Whether the view should be a materialized view
- param register_as_model
Whether the view should be registered as a SQLAlchemy mapped object. Note this only works if the view defines mappable models columns (minimally a primary key), like a proper modeled table.
>>> try:
... from sqlalchemy.orm import declarative_base
... except ImportError:
... from sqlalchemy_declarative_extensions.sqlalchemy import declarative_base
>>> from sqlalchemy import Column, types
>>> from sqlalchemy_declarative_extensions import view
>>>
>>> Base = declarative_base()
>>>
>>> @view(Base)
... class Foo:
... __tablename__ = "foo"
... __view__ = "SELECT * from bar"
...
... id = Column(types.Integer, primary_key=True)
- class sqlalchemy_declarative_extensions.role.base.Roles#
- are(*roles)#
- Parameters
roles (postgresql.Role | generic.Role | str) –
- classmethod coerce_from_unknown(unknown)#
- Parameters
unknown (None | Iterable[postgresql.Role | generic.Role | str] | Roles) –
- Return type
Roles | None
- ignore_roles#
- ignore_unspecified = False#
- roles#
- class sqlalchemy_declarative_extensions.role.generic.Role#
-
- property has_option#
- in_roles#
- name#
- property options#
- class sqlalchemy_declarative_extensions.grant.Grants#
A collection of grants and the settings for diff/collection.
- Parameters
grants – The list of grants
ignore_unspecified – Defaults to False. When True, ignore detected grants which do not match the set of defined grants.
ignore_self_grants – Defaults to True. When True, ignores grants to the current user. It’s typical in migrations that the a single user performs migrations and will have implicitly granted grants on all objects. In this scenario, it can be tedious to define those permissions on every object, so they are ignored by default.
only_defined_roles – Defaults to True. When True, only applies to roles specified in the roles section.
default_grants_imply_grants – Defaults to True. When True, default grants also imply the set of expected actual grants. This allows one to specify only default grants, and per-object grants will be made to match the default set.
Examples
No grants
>>> grants = Grants()
Some options set
>>> grants = Grants(ignore_unspecified=True)
With some actual grants
>>> from sqlalchemy_declarative_extensions.dialects.postgresql import DefaultGrant >>> grants = Grants().are(DefaultGrant(..., ...), ...)
- are(*grants)#
- Parameters
grants (G) –
- classmethod coerce_from_unknown(unknown)#
- default_grants_imply_grants = True#
- grants#
- ignore_self_grants = True#
- ignore_unspecified = False#
- only_defined_roles = True#
- class sqlalchemy_declarative_extensions.function.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#
- property qualified_name#
- returns = void#
- schema#
- to_sql_create(replace=False)#
- to_sql_drop()#
- to_sql_update()#
- class sqlalchemy_declarative_extensions.function.Functions#
-
- classmethod coerce_from_unknown(unknown)#
- functions#
- ignore_unspecified = False#
- sqlalchemy_declarative_extensions.function.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) –
- class sqlalchemy_declarative_extensions.trigger.Trigger#
Describes a generic trigger.
- execute#
- name#
- on#
- abstract to_sql_create(replace=False)#
- to_sql_drop()#
- to_sql_update(connection)#
- Parameters
connection (sqlalchemy.engine.Connection) –
- class sqlalchemy_declarative_extensions.trigger.Triggers#
-
- classmethod coerce_from_unknown(unknown)#
- ignore_unspecified = False#
- triggers#
- sqlalchemy_declarative_extensions.trigger.register_trigger(base_or_metadata, trigger)#
Register a trigger onto the given declarative base or Metadata.
This can be used instead of the static registration through Triggers on a declarative base or MetaData, to imperitively register triggers.
- Parameters
base_or_metadata (HasMetaData | MetaData) –
trigger (Trigger) –
- class sqlalchemy_declarative_extensions.row.Row(tablename, **column_values)#
- class sqlalchemy_declarative_extensions.row.Rows#
-
- classmethod coerce_from_unknown(unknown)#
- ignore_unspecified = False#
- included_tables#
- rows#
Alembic#
- sqlalchemy_declarative_extensions.alembic.register_alembic_events(schemas=True, views=True, roles=True, grants=True, functions=True, triggers=True, rows=True)#
Register handlers into alembic’s event system for the supported object types.
By default all object types are enabled, but each can be individually disabled.
Note this is the opposite of the defaults when registering against SQLAlchemy’s event system.