Working with data in SQL Databases¶
NOTE: Currently SQL Database support is incomplete
See part 9 of the tutorial for an introduction.
Storing and retrieving data in SQLite3¶
See Using SQL DBs in the Developers Guide
Mapping from a LinkML model to SQL Schemas¶
The SQL Table Generator can be used to generate SQL DDL (CREATE TABLE statements) from a schema.
There are many possible ways of mapping a LinkML schema to SQL DDL. The existing generator makes a specific set of decisions, in future it may be possible to customize this more to your needs.
Classes are mapped to a Tables
Class slots are mapped to Columns
identifier slots are translated to Primary Keys
required slots are translated to mandatory fields
When handling inheritance:
Tables are generated for both superclasses and child classes
Slots are “rolled down” to child classes
A slot
sthat has a range of a classc:is transformed to a slot
s_{key}this is a foreign key to
{key}inc, where{key}is the primary key
The standard relational model does not allow for direct analogs of multivalued fields
A multivalued slot is modeled as a separate table with a backreference to the holder table
If the range of a multivalued slot
c.sis a Type (literal): - this generates a tablec_swith a backrefc_{key}- the table also include a single-valuedsIf the range of a multivalued slot
c.sis a Classr: - ifsis inlined, a backref tocis inserted into the table forr- ifsis not inlined, a new join tablec_sis created
Mapping is done via SQL Alchemy, which takes care of difference in SQL dialects.
Creation of an Object-Relation Mapping layer¶
The SQLAlchemy Generator will generate a Python ORM.
Currently there is no support for ORM generation in other languages.
Given that ORM layers need to tuned to specific use cases, you may wish to provide your own mapping. For Java you can do this by tuning the Jinja2 templates that are generated, see Java Generation