SQLStore#

class linkml.utils.sqlutils.SQLStore(schema: Optional[Union[str, SchemaDefinition]] = None, schemaview: Optional[SchemaView] = None, engine: Optional[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 SQLite 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

compile_native() module[source]#

Compile native python object 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: YAMLRoot, append=True) None[source]#

Store an element in the database

Parameters:
  • element

  • append

Returns:

from_sqla(obj: Any) Optional[Union[YAMLRoot, List[YAMLRoot]]][source]#

Translate from SQLAlchemy declarative module to native LinkML

Parameters:

obj – sqla object

Returns:

native dataclass object

load(target_class: Optional[Union[str, Type[YAMLRoot]]] = None) YAMLRoot[source]#

Loads a LinkML object from the wrapped SQLite database

Parameters:

target_class

Returns:

to_sqla(obj: Union[YAMLRoot, list]) Any[source]#

Translate native LinkML object to SQLAlchemy declarative module

Parameters:

obj

Returns:

Command Line#

linkml-sqldb#

Run the LinkML SQL CLI.

linkml-sqldb [OPTIONS] COMMAND [ARGS]...

Options

-v, --verbose#
-q, --quiet <quiet>#
--csv-field-size-limit <csv_field_size_limit>#

Increase the default limit for maximum field size. See https://docs.python.org/3/library/csv.html#csv.field_size_limit

-V, --version#

Show the version and exit.

Commands

dump

Dumps data to a SQL store

load

Loads data from a SQL store