Using SQL Databases
SQL Alchemy is a SQL framework for python. It has a core layer, and an ORM layer.
See:
SQL Alchemy for generating SQL Alchemy code
SQL DDL for generating SQL DDL
The SQLStore class provides a convenient wrapper around these generators for working with SQL Data
SQLStore
- class linkml.utils.sqlutils.SQLStore(schema: Optional[Union[str, linkml_runtime.linkml_model.meta.SchemaDefinition]] = None, schemaview: Optional[linkml_runtime.utils.schemaview.SchemaView] = None, engine: Optional[sqlalchemy.engine.base.Engine] = None, database_path: Optional[str] = None, module: Optional[module] = None, native_module: Optional[module] = None, include_schema_in_database: Optional[bool] = None)[source]
A wrapper for a SQLLite database.
This provides two core operations for storing and retrieving data
The wrapper transparently will take care of:
mapping your LinkML schema into SQL Tables
creating a SQL Alchemy ORM layer
mapping your data/objects in any LinkML compliant data format (json. yaml, rdf) into ORM objects
- compile() module [source]
Compile SQLAlchemy object model
Uses Declarative by default.
Note that the SQLA model is different from the native dataclass model
- Returns
compiled module
- db_exists(create=True, force=False) str [source]
check if database exists, optionally create if not present
- Parameters
create – create if does not exist
force – recreate database, destroying any content if previously present
- Returns
path
- dump(element: linkml_runtime.utils.yamlutils.YAMLRoot, append=True) None [source]
Store an element in the database
- Parameters
element –
append –
- Returns
- from_sqla(obj: Any) Optional[Union[linkml_runtime.utils.yamlutils.YAMLRoot, List[linkml_runtime.utils.yamlutils.YAMLRoot]]] [source]
Translate from SQLAlchemy declarative module to native LinkML
- Parameters
obj – sqla object
- Returns
native dataclass object