trilium_alchemy.core.entity

Class index

Canonical

BaseEntity

Base class for Trilium entities.

State

Entity state. Maintained automatically based on the user’s updates and object’s current state in Trilium.

EntityIdDescriptor

Accessor for read-only entity id.

FieldDescriptor

Accessor for a model field, e.g. a Note’s title field.

ReadOnlyFieldDescriptor

Accessor for a read-only model field, e.g. a Note’s date_created field.

ReadOnlyDescriptor

Accessor for read-only class attribute.

WriteThroughDescriptor

Accessor for class attribute which immediately populates the underlying model field when updated.

WriteOnceDescriptor

Accessor for field which is only allowed a single value. Subsequent assignments are a no-op if they set the same value.

ExtensionDescriptor

Accessor for model extension.

Symbols

class trilium_alchemy.core.entity.BaseEntity(*, entity_id: str | None = None, session: Session | None = None, model_backing: ModelT | None = None, create: bool | None = None)

Bases:

abc.ABC
trilium_alchemy.core.session.SessionContainer
trilium_alchemy.core.entity.model.ModelContainer

Aliases:

trilium_alchemy.BaseEntity
trilium_alchemy.core.BaseEntity

Base class for Trilium entities.

Should not be instantiated by user, but published for reference.

property state: State

Current state.

property session: Session

Session to which this entity belongs.

property str_short: str

Get a short description of this entity.

property str_summary: str

Get a summary of this entity, including its current state and model values.

flush()

Commit changes to Trilium for this entity and its dependencies.

invalidate()

Discard cached contents and user-provided data for this object. Upon next access, data will be fetched from Trilium.

delete()

Mark this entity for pending delete.

refresh()

Update value from Trilium, discarding any local changes.

class trilium_alchemy.core.entity.State(*args, **kwds)

Bases:

enum.Enum

Aliases:

trilium_alchemy.State
trilium_alchemy.core.State

Entity state. Maintained automatically based on the user’s updates and object’s current state in Trilium.

For example, state will change from State.UPDATE back to State.CLEAN if the user reverts changes.

CLEAN

No pending changes

CREATE

Pending create

UPDATE

Pending update

DELETE

Pending delete

name()

Inherited from: enum.Enum

The name of the Enum member.

value()

Inherited from: enum.Enum

The value of the Enum member.

class trilium_alchemy.core.entity.EntityIdDescriptor

Accessor for read-only entity id.

Raises:

ReadOnlyError – Upon write attempt

class trilium_alchemy.core.entity.FieldDescriptor(field: str)

Accessor for a model field, e.g. a Note’s title field.

When written, updates the working state which will be committed to Trilium upon flush. When read, returns the working state if set by user, or the state from Trilium if not.

class trilium_alchemy.core.entity.ReadOnlyFieldDescriptor(field: str)

Bases:

trilium_alchemy.core.entity.FieldDescriptor

Accessor for a read-only model field, e.g. a Note’s date_created field.

Raises:

ReadOnlyError – Upon write attempt

class trilium_alchemy.core.entity.ReadOnlyDescriptor(attr: str, allow_none_cb: str | None = None, allow_none: bool = False)

Accessor for read-only class attribute.

Raises:

ReadOnlyError – Upon write attempt

class trilium_alchemy.core.entity.WriteThroughDescriptor(attr: str, attr_attr: str, field: str)

Accessor for class attribute which immediately populates the underlying model field when updated.

class trilium_alchemy.core.entity.WriteOnceDescriptor(attr: str, validator: Callable = None)

Accessor for field which is only allowed a single value. Subsequent assignments are a no-op if they set the same value.

Raises:

ReadOnlyError – Upon write attempt with different value than currently set

class trilium_alchemy.core.entity.ExtensionDescriptor(attr: str)

Accessor for model extension.

A model extension performs additional processing on the model and provides an interface to update other entities associated with this entity. For example, Note uses an extension to process the list of attributes from the note model and create BaseAttribute instances.