Base
Initial common functions for LOD Model Classes
- class loglan_core.base.BaseModel(**kwargs)[source]
Bases:
AsyncAttrs,DeclarativeBaseBaseModel is a subclass of DeclarativeBase. It serves as the parent class for other database models, providing common attributes and methods to its child classes. It doesn’t contain any class-specific attributes/methods.
- __repr__()[source]
Special method that returns a string representation of the object. It forms the string by joining key-value pairs of the object’s attributes, excluding keys that start with “_” and keys that are “created” or “updated”. The key-value pairs are sorted before joining.
- Returns:
- A string representation of the object in the format:
”ClassName(key1=value1, key2=value2, …)”.
- Return type:
str
- classmethod _filter_add_to_repr(k, v)[source]
Static method that filters out keys that start with “_” and keys that are “created” or “updated” and keys without values from the object’s attributes. The method is used to generate a string representation of the object. It is used internally by the __repr__.
- classmethod attributes_all()[source]
Class method that computes the all attribute keys from the class mapper and returns their names as a set.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of all attribute keys.
- Return type:
set[str]
- classmethod attributes_basic()[source]
Class method that computes the set of basic attributes for the class. It subtracts any relationships from all attributes.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of basic attributes.
- Return type:
set[str]
- classmethod attributes_extended()[source]
Class method that computes the extended attributes of the class. It does this by subtracting foreign keys from all attributes.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of the extended attributes.
- Return type:
set[str]
-
created:
Mapped[datetime] = <sqlalchemy.orm.properties.MappedColumn object> A class attribute mapped to a column in the database table. It represents the timestamp when a row is created. The default value is the current timestamp, and it can’t be null.
- Type:
datetime
- export()[source]
Class method that exports the object’s attributes into a dictionary. It filters out keys that start with “_” and keys that are “created” or “updated”, then sorts the remaining keys.
- Returns:
A dictionary with sorted keys and corresponding values of the object’s attributes.
- Return type:
dict
- classmethod foreign_keys()[source]
Class method that computes the names of foreign keys of the class. It does this by subtracting relationship keys and non-foreign keys from all attributes.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of the foreign keys.
- Return type:
set[str]
- classmethod get_all(session)[source]
Class method that retrieves all instances of the class from the database using the provided session.
- Parameters:
session (Session) – The session to use for the database query.
- Returns:
A list of all instances of the class.
- Return type:
list
- classmethod get_by_id(session, cid)[source]
Class method that retrieves an instance of the class from the database using the provided session and id.
- Parameters:
session (Session) – The session to use for the database query.
cid (int) – The id of the instance to retrieve.
- Returns:
The instance of the class with the given id, or None if no such instance exists.
- Return type:
Object of class type or None
- classmethod hybrid_properties()[source]
Class method that computes the hybrid properties of the class.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of the hybrid properties.
- Return type:
set[str]
-
id:
Mapped[int] = <sqlalchemy.orm.properties.MappedColumn object> A class attribute mapped to a column in the database table. It serves as the primary key for the table.
- Type:
int
- metadata: ClassVar[MetaData] = MetaData()
Refers to the
_schema.MetaDatacollection that will be used for new_schema.Tableobjects.See also
orm_declarative_metadata
- classmethod non_foreign_keys()[source]
Class method that computes the non-foreign keys of the class. It does this by inspecting the class columns and selecting those without foreign keys.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of the non-foreign keys.
- Return type:
set[str]
- classmethod properties()[source]
Class method that computes the properties of the class.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of the properties.
- Return type:
set[str]
- registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>
This code creates a registry that maps custom type annotations to SQLAlchemy String types with specified lengths. The keys are custom type annotation names and the values are SQLAlchemy String types with the specified lengths.
- classmethod relationships()[source]
Class method that computes the relationship names from the class mapper and returns them as a set.
It doesn’t require any parameters as it operates on the class itself.
- Returns:
A set of strings with names of the relationships.
- Return type:
set[str]
-
updated:
Mapped[datetime|None] = <sqlalchemy.orm.properties.MappedColumn object> A class attribute mapped to a column in the database table. It represents the timestamp when a row is last updated. Whenever the row is updated, this timestamp is automatically set to the current time. It can be
nullif the row has never been updated.- Type:
datetime