Skip to main content

Module sql

Module sql 

Source
Expand description

The metadata store on disk: one SQLite file, plm.sqlite, in WAL mode.

§Shape

Each kind of record has its own table. The columns the store queries or constrains on are real columns (a part’s number, a revision’s label, a use’s child part, an MPN), and the rest of the record is a JSON body column. That keeps every field the model has without a column per field, and a field a later slice adds needs no schema change: it rides in body. A record’s children live in their own tables, not in its body:

tableone row perconstrained / indexed on
partspartord (creation order, also the FTS rowid), id, number_lc UNIQUE, category_lc
revisionsrevision(part_id, label_lc) UNIQUE
usesline of a revision’s uses listchild_part, child_revision
manufacturer_partsMPN on a partmanufacturer, mpn_lc
supplier_offersoffer under an MPNsupplier, spn_lc
part_tagstag on a parttag_lc
users, sessions, api_tokens, part_types, categories, manufacturers, suppliersrecordtheir ids
workspaceworkspace folder, link or file(owner, parent), ord
changesdocument key in the change logseq
preferencesone reserved key of one user (crate::api::preferences), not in the in-memory state(user_id, key), (user_id, version)
auditaudit eventat, the actor, kind, entity_id, part_id, action
metathe sequence, the settings, and any state field with no tablekey
parts_ftspart (FTS5, trigram, contentless)number, name, description, category, tags, attribute values, MPNs, SPNs

Documents are NOT here: they stay one file each under models/, as the CAD app writes them.

§Reads

The server still answers reads from the whole state held in memory (crate::db::Db::read), which this file loads at start-up. What SQL adds on the read side is the search index and the audit log’s indexed queries, through a second connection so a search never waits on a write.

§Versions

PRAGMA user_version identifies the current schema. Existing files must match it exactly; new files are initialized directly without upgrade paths.

Structs§

Candidates
The indexed narrowing of a parts search (Sql::candidates).
Change
What one committed change moved, for Sql::write.
PreferenceRow
One row of a user’s preferences, without its value.
Sql
The SQLite store: a writer connection used under the store’s write lock, a reader for searches and audit queries, and a checkpointer thread.

Enums§

Durability
How long a commit waits for the disk.

Functions§

is_constraint
Whether error is a UNIQUE (or other) constraint the schema enforces — a rule the store’s own checks should have refused first.
schema_version
The only schema version this build reads and writes.
small_value
The state as JSON without its parts, workspaces, sessions or jobs: every other field, whatever it is. Those lists are swapped out for the length of the serialization, so they are never serialized (they are what grows); each has its own journal and table.