simplelogincmd.database.models.Alias

class Alias(**kwargs)

Bases: LenientInit, Object

A SimpleLogin alias

Methods

get

Retrieve the value of the given field

get_string

Retrieve a string representation of the field

identifier_query

Restrict a query based on a generic identifier

resolve_identifier

Retrieve a list of model objects based on a generic identifier

Attributes

creation_timestamp

disable_pgp

email

enabled

id

metadata

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

name

nb_block

nb_forward

nb_reply

note

pinned

registry

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

support_pgp

get(field: str) str | None

Retrieve the value of the given field

Parameters:

field (str) – The name of the field to get

Returns:

The field’s value, or None if the field is undefined

Return type:

str | None

get_string(field: str) str

Retrieve a string representation of the field

Parameters:

field (str) – The name of the field to get

Returns:

String representation of the field’s value

  • if value is string, then return value

  • if value is None, then “”

  • if value is bool, then “Y” or “N”

  • if value is iterable, then each element as a string, separated by commas

  • otherwise return str(value)

Return type:

str

classmethod identifier_query(query: Select, id: Any) Select

Restrict a query based on a generic identifier

In the event that id is not a numeric primary key id, model classes can decide for themselves, by overriding this method, how to find the objects to which id refers. Overriding implementations should restrict query, as via a call to sqlalchemy.Select.where() or similar, to a condition that identifies one (ideally) or more objects. For example, a Mailbox model might allow to search through email addresses, while an Alias model might search emails and alias notes for a match.

Parameters:
  • query (sqlalchemy.Select) – The query to be conditioned

  • id (Any) – The identifier which is supposed to identify ideally one, but potentialy many or no model objects

Returns:

The modified query

Return type:

sqlalchemy.Select

metadata: ClassVar[MetaData] = MetaData()

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

classmethod resolve_identifier(session: Session, id: Any) list[Object]

Retrieve a list of model objects based on a generic identifier

Attempt to produce a single model object by passing id directly on to sqlalchemy.orm.Session.get_one(). If that fails, then fall back to identifier_query(), which subclasses can override in order to determine how that particular model should interpret the identifier.

Parameters:
  • session (sqlalchemy.orm.Session) – The database session which is to search for object(s)

  • id (Any) – The identifier for which to search. This might be as simple as a primary key numeric id, or it could be a string which (ideally uniquely) identifies a particular model object.

Returns:

A list of zero or more matching model objects

Return type:

list[Object]