Storages#

The storages reading and writing the resources with a SQLAlchemy Session.

class scim2_sqlalchemy.SqlAlchemyStorage(mappings, session, provider=None)[source]#

Store SCIM resources in the records of SQLAlchemy models.

The storage never commits: committing the request is left to the application. Each write is flushed, so that the database fills the identifiers and checks its constraints.

A change the mappings cannot store raises an error rather than being lost: InvalidValueException for an attribute no mapping stores, and MutabilityException for an attribute the mapping only reads. A value equal to the stored one is accepted, so a resource read and sent back can always be written.

Parameters:
  • mappings (Mapping[str, ResourceMapping]) – The mapping of each resource type, by resource type name.

  • session (Callable[[], Session]) – Return the current Session, such as a scoped_session.

  • provider (ScimProvider | None) – The provider of the server. The storage then returns instances of its models, rather than of the models of the mappings, and gives each link a $ref relative to the SCIM root, from the endpoints of its resource types. Strings are compared with the comparison_key of its policy.

operation()[source]#

Run the operation in a savepoint.

The savepoint comes from begin_nested(). A failed operation of a bulk request is then rolled back alone (RFC 7644 §3.7).

Return type:

Generator[None]

class scim2_sqlalchemy.AsyncSqlAlchemyStorage(mappings, session, provider=None)[source]#

The asynchronous variant of SqlAlchemyStorage.

It needs the asyncio extra, which installs the asynchronous support of SQLAlchemy: pip install "scim2-sqlalchemy[asyncio]".

Parameters:
operation()[source]#

Run the operation in a savepoint. See SqlAlchemyStorage.operation().

Return type:

AsyncGenerator[None]