gws.base.database.model¶
Base database model.
Source code: gws.base.database.model
Module Contents¶
- class gws.base.database.model.Config¶
Bases:
gws.base.model.ConfigConfiguration for the database model.
- class gws.base.database.model.Object¶
Bases:
gws.base.model.Object,gws.DatabaseModelBase model for a database table.
Reads features from one table with SELECT queries built from the model fields, and creates, updates and deletes table rows. Provides subclasses with the database provider, access to the table and its columns, and the SELECT builder.
- build_select(mc)¶
Build a SELECT statement for a search.
Combines the search query in
mc.search, the columns and conditions collected by the fields inmc.dbSelectandsqlFilter.- Parameters:
mc – Model context with
searchanddbSelectset.- Returns:
The SELECT statement, or
Noneif the search cannot match anything.
- column(column_name)¶
Return the SQLAlchemy
Columnobject of a column in the model table.- Parameters:
column_name – Column name.
- Returns:
The column object.
- Raises:
sqlalchemy.exc.SQLAlchemyError – If the table or the column does not exist.
- configure()¶
Configuration hook.
Called when the node is initialized. Raising an exception here aborts the creation of the node.
- configure_provider()¶
- create_feature(feature, mc)¶
Insert a new feature into the source.
- Parameters:
feature – The feature.
mc – The model context.
- Returns:
The primary key of the inserted feature.
- Raises:
gws.ForbiddenError – If the user cannot create features of this model.
- delete_feature(feature, mc)¶
Delete a feature from the source.
- Parameters:
feature – The feature.
mc – The model context.
- Returns:
The uid of the feature.
- Raises:
gws.ForbiddenError – If the user cannot delete features of this model.
- describe()¶
Return the description of the model source.
- Returns:
The dataset description, or None if the source cannot be described.
- fetch_features(select)¶
Run a SELECT statement and create a feature for each row.
The row values become the attributes of the feature record.
- Parameters:
select – SELECT statement.
- Returns:
A list of features.
- find_features(search, mc)¶
Find features matching a search query.
- Parameters:
search – The search query.
mc – The model context.
- Returns:
The features found.
- init_feature(feature, mc)¶
Initialize a new feature with initial field values.
- Parameters:
feature – The new feature.
mc – The model context.
- Raises:
gws.ForbiddenError – If the user cannot create features of this model.
- table()¶
Return the SQLAlchemy
Tableobject of the model table.- Returns:
The table object.
- Raises:
sqlalchemy.exc.SQLAlchemyError – If the table does not exist.
- uid_column()¶
Return the SQLAlchemy
Columnobject of the primary key column.- Returns:
The column object for
uidName.- Raises:
gws.Error – If the model has no primary key or the key column does not exist.
- uid_equals(uid)¶
Return a condition that matches features by uid.
The values are bound with the type of the primary key column, so that string uids can be compared with columns of other types.
- Parameters:
uid – A feature uid, or an iterable of uids.
- Returns:
An
=condition for a single uid, anINcondition for an iterable.- Raises:
gws.Error – If the model has no primary key or the key column does not exist.
- update_feature(feature, mc)¶
Update an existing feature in the source.
- Parameters:
feature – The feature.
mc – The model context.
- Returns:
The uid of the feature.
- Raises:
gws.ForbiddenError – If the user cannot write to this model.
- class gws.base.database.model.Props¶
Bases:
gws.base.model.Props