Skip to content

Common components ​

classDiagram
    class Model {
        Core core
        connect()
        and()
        or()
        relation()
        relations()
        limit()
        duplication()
        get()
        gets()
        getsCount()
        getCount()
        getSum()
        getAvg()
        getsPage()
        getQuery()
        create()
        creates()
        update()
        save()
        delete()
        restore()
        restoreOrCreate()
        expectRevision()
        toArray()
    }
    class Core {
        <<internal>>
        Columns columns
        Group conditions
        Optional_Db connection
        List_Model joins
        Optional_Limit limit
        Text lock
        List_Order order
        List_Model relations
        Optional_RowState row
        List_Assignment sets
        build()
    }
    class Request {
        <<internal>>
        RequestIR ir
        List_Value params
        shape()
    }
    class RequestIR {
        Text kind
        List_Assignment onDuplicate
        Optional_Optimistic optimistic
        Integer parameterCount
        QueryNode root
        List_List_Integer rows
        Text schemaHash
        List_Assignment set
        Integer version
    }
    class QueryNode {
        Columns columns
        Text entity
        List_Text groupBy
        List_Join joins
        Optional_Limit limit
        Text lock
        Group on
        RelationOptions options
        List_Order order
        List_Relation relations
        Group where
    }
    class Planner {
        <<internal>>
        Dialect dialect
        SchemaManifest manifest
        validate()
        plan()
    }
    class Plan {
        Text kind
        Text schemaHash
        List_Step steps
    }
    class Step {
        Optional_Assemble assemble
        List_BindSlot bindSlots
        Integer id
        Optional_ParentRef parent
        Text role
        Text sql
        List_Text tables
    }
    class Assemble {
        List_Child children
        List_OutputColumn columns
        Text entity
    }
    class Db {
        Config config
        Map_SchemaHash_Planner planners
        Cache_Shape_Plan plans
        ConnectionPool pool
        Cache_Sql_Statement statements
        List_StatementSubscriber subscribers
        connect()
        connectSchema()
        transaction()
        utils()
        close()
        stats()
        subscribe()
        execute()
        withRequestHook()
    }
    class TransactionFlow {
        <<internal>>
        List_TransactionFrame frames
        begin()
        savepoint()
        commit()
        rollback()
    }
    class Collection {
        Map_Key_Value fetched
        Map_Key_Model items
        List_Key keys
        get()
        first()
        keys()
        connect()
        delete()
        toArray()
    }
    class Page {
        Collection items
        Integer page
        Integer perPage
        Integer totalCount
        Integer totalPages
    }
    class Utils {
        Db db
        lock()
        setLocal()
        local()
        wasInserted()
        backendWaitingForLock()
        schema()
        privileges()
        aes()
        stats()
    }
    class SchemaUtils {
        Db db
        register()
        install()
        addTablesAndColumns()
        exists()
        installed()
        empty()
    }
    class AesUtils {
        Db db
        status()
        rotate()
    }
    class AESKeyring {
        Integer currentVersion
        Map_Integer_Secret versions
        versions()
    }
    class AESRotationStatus {
        Integer current
        Integer pending
        Integer total
        Map_Integer_Integer versions
    }
    class Generator {
        <<internal>>
        SchemaManifest manifest
        List_Path scan
        generate()
    }
    class Error {
        Optional_Error cause
        Text code
        Text message
    }
    class Dbspec {
        readFile()
        readBytes()
        readSet()
        parse()
        analyze()
        format()
        emit()
        manifest()
        render()
        introspect()
        externalDifferences()
        parsePlan()
        emitPlan()
        chain()
        diff()
        compareSchemas()
        installedDifferences()
        addTablesAndColumnsSteps()
        planSteps()
        apply()
        recover()
        rollback()
        finalize()
        exportMermaid()
        importMermaid()
    }
    class DbspecDocument {
    }
    Model *-- Core : stores chain state
    Core --> Db : uses connection
    Core --> TransactionFlow : uses flow transaction
    Core --> Request : builds
    Request *-- RequestIR : stores IR
    RequestIR *-- QueryNode : contains root
    QueryNode *-- QueryNode : contains child nodes
    Db *-- Planner : plans per schema
    Planner --> Plan : returns
    Plan *-- Step : contains ordered steps
    Step *-- Assemble : maps results
    Db --> TransactionFlow : opens
    Db --> Utils : returns
    Utils --> SchemaUtils : returns
    Utils --> AesUtils : returns
    SchemaUtils --> Planner : registers schema
    AesUtils --> AESKeyring : uses keys
    AesUtils --> AESRotationStatus : returns status
    Collection o-- Model : contains ordered models
    Page *-- Collection : contains items
    Model *-- Collection : contains relations
    Generator --> Model : emits
ComponentBehavior and state
ModelGenerated per entity. Holds the column values of a new or loaded row and the chain state in its Core.
CoreStores the chain state and builds a value-free request with a separate parameter list. Internal: Each client builds the request inside its own model runtime; the request IR it builds is the common shape, not the build call (docs/spec/interfaces.md §2).
RequestThe request shape is the plan cache key; values stay in the parameter list. Internal: The shape is the plan cache key that each client computes inside its connection; the request IR and its parameter list are common, not the shape call (docs/spec/interfaces.md §7).
RequestIRThe common request shape of every client.
QueryNodeThe root, a join child, a relation child, or a subquery.
PlannerRuns in the client process. Validates a request against the manifest and renders the dialect SQL. Internal: Each client validates and plans the request inside its connection, in the calling process; the plan and its SQL are common, checked by the conformance vectors, not the planner calls (docs/spec/interfaces.md §7).
PlanImmutable statements and assembly metadata cached per request shape.
StepOne SQL statement of a plan.
AssembleMaps result columns by position to models, joins, and relations.
DbOwns the pool, the planners of the schema sets registered on it, the plan and statement caches, and the statement event subscribers.
TransactionFlowPrivate. The transaction of the current execution flow; models without a connection use it. Internal: Begin, savepoint, commit and rollback are private; Db.transaction is their public entry (docs/spec/interfaces.md §6).
CollectionOrdered models keyed by primary key, keyName, or fetchKey.
PageThe rows and counts of getsPage.
UtilsConnection utilities; lock and local values need an active transaction.
SchemaUtilsRegisters the set of a generated schema on the connection without reading the database; installs the set with the client DDL renderer, verifies the database and registers the set; upgrades an installed set by the tables and the null or defaulted columns that the database lacks, without registering it.
AesUtilsReports and rotates AES key versions of a model table.
AESKeyringKeys by version; the current version encrypts new values.
AESRotationStatusRow counts per key version.
GeneratorOne per language. Reads the dbspec document set and emits models; Go and Rust emit only the chain methods the sources call. Internal: Each language generates its models with its own build tool and command; the generated models are common, not the generate call (docs/spec/interfaces.md §11, docs/operations/usage.md §3).
ErrorA stable code from docs/spec/errors.yaml.
DbspecReads a dbspec document file, or checks the bytes of one that the caller read, after checking its signature and encoding, reads a set file into the files of its document set, parses a dbspec document against its declared document set and gives the positions of its declarations, analyzes a text into that parse result and the tokens of its syntax, formats a text in canonical form or refuses a text that has a diagnostic, emits a parsed document in canonical form, gives the manifest text, schema text and hashes of a document set, renders a document set as dialect statements, introspects a database into a document, compares databases with external documents and with a set, reads, emits, chains, diffs and writes the steps of plans, compares schema texts, applies, recovers, rolls back and finalizes plans on a connection, and exports and imports Mermaid erDiagrams (docs/spec/dbspec.md, docs/spec/dialects.md, docs/spec/plans.md, docs/spec/mermaid.md).
DbspecDocumentOne parsed and validated dbspec document. It is immutable; emitting it gives its canonical text.

A component marked <<internal>> states its grounding in the manifest field internal (internal_ko): each client implements its methods privately with no common signature, so they have no interface rule. Every method of the other components has a rule, and every rule names a method of a public component; make interface-check checks both directions.

Host-native APIs ​

APIHostSemantic requirementNative declaration
Db.withContextgoCFG-9packages/go/orm/db.go::DB.WithContext
Cancellation.cancelphpCFG-9packages/php/src/Cancellation.php::Polyspec\Orm\Cancellation::cancel
Db.withCancellationphpCFG-9packages/php/src/Db.php::Polyspec\Orm\Db::withCancellation
Db.withSignaltypescriptCFG-9packages/ts/src/database.ts::Db.withSignal
Db.withFuturepythonCFG-9packages/python/src/polyspec/orm/database.py::Db.with_future

A host-native API uses its host language’s public primitive and has no common signature. The shared behavior is checked through every runtime entry and its exact parity cases in behavior_adapters. An unresolved entry is not implementation evidence.

Shared behavior adapters ​

  • INT-139 The generated component document records every component, method, field, and ownership edge in the manifest in both languages.
RequirementCompletion itemRuntimeStatusHost primitiveExecutable case
CFG-9KSTD-2-11-16goimplementedDb.WithContextpackages/go/orm/cancel_test.go::TestWithContextCancels
CFG-9KSTD-2-11-16phpimplementedCancellation::cancel and Db::withCancellationpackages/php/tests/QueryCancellationTest.php::testCancellationInterruptsSqliteVmRollsBackAndKeepsRootConnectionUsable
packages/php/tests/QueryCancellationTest.php::testPostgresNoticeCancelsActiveStatementRollsBackAndReusesRoot
packages/php/tests/QueryCancellationTest.php::testMysqlLockEventCancelsActiveStatementRollsBackAndReconnectsRoot
CFG-9KSTD-2-11-16php-extensionimplementedCancellation::cancel and Db::withCancellationpackages/php-ext/tests/QueryCancellationNativeTest.php::testNativeCancellationInterruptsSqliteRollsBackAndKeepsRootConnectionUsable
packages/php-ext/tests/QueryCancellationNativeTest.php::testPostgresNoticeCancelsActiveStatementRollsBackAndReusesRoot
packages/php-ext/tests/QueryCancellationNativeTest.php::testMysqlLockEventCancelsActiveStatementRollsBackAndReconnectsRoot
CFG-9KSTD-2-11-16pythonimplementedDb.with_futurepackages/python/tests/coverage_transactions.py::test_handle_abandoned_query
packages/python/tests/test_query_cancel.py::test_cancel_interrupts_active_statement_and_root_is_reusable
CFG-9KSTD-2-11-16rustimplementeddropping the statement futurepackages/rust/orm/tests/zone.rs::dropping_a_query_cancels_it
CFG-9KSTD-2-11-16typescriptimplementedDb.withSignalpackages/ts/tests/coverage_transactions.mjs::handle_abandoned_query [sqlite] (before-start)
packages/ts/tests/coverage_transactions.mjs::handle_abandoned_query [mysql]
packages/ts/tests/coverage_transactions.mjs::handle_abandoned_query [postgres]

A shared behavior is complete only when every runtime has an exact executable case. An unresolved entry blocks completion until its checklist item is resolved.

FromToRelation
ModelCorestores chain state
CoreDbuses connection
CoreTransactionFlowuses flow transaction
CoreRequestbuilds
RequestRequestIRstores IR
RequestIRQueryNodecontains root
QueryNodeQueryNodecontains child nodes
DbPlannerplans per schema
PlannerPlanreturns
PlanStepcontains ordered steps
StepAssemblemaps results
DbTransactionFlowopens
DbUtilsreturns
UtilsSchemaUtilsreturns
UtilsAesUtilsreturns
SchemaUtilsPlannerregisters schema
AesUtilsAESKeyringuses keys
AesUtilsAESRotationStatusreturns status
CollectionModelcontains ordered models
PageCollectioncontains items
ModelCollectioncontains relations
GeneratorModelemits

An underscore in a diagram type name separates nested types. The table defines the exact types.

FieldCommon type
Model.coreCore
Core.columnsColumns
Core.conditionsGroup
Core.connectionOptional<Db>
Core.joinsList<Model>
Core.limitOptional<Limit>
Core.lockText
Core.orderList<Order>
Core.relationsList<Model>
Core.rowOptional<RowState>
Core.setsList<Assignment>
Request.irRequestIR
Request.paramsList<Value>
RequestIR.kindText
RequestIR.onDuplicateList<Assignment>
RequestIR.optimisticOptional<Optimistic>
RequestIR.parameterCountInteger
RequestIR.rootQueryNode
RequestIR.rowsList<List<Integer>>
RequestIR.schemaHashText
RequestIR.setList<Assignment>
RequestIR.versionInteger
QueryNode.columnsColumns
QueryNode.entityText
QueryNode.groupByList<Text>
QueryNode.joinsList<Join>
QueryNode.limitOptional<Limit>
QueryNode.lockText
QueryNode.onGroup
QueryNode.optionsRelationOptions
QueryNode.orderList<Order>
QueryNode.relationsList<Relation>
QueryNode.whereGroup
Planner.dialectDialect
Planner.manifestSchemaManifest
Plan.kindText
Plan.schemaHashText
Plan.stepsList<Step>
Step.assembleOptional<Assemble>
Step.bindSlotsList<BindSlot>
Step.idInteger
Step.parentOptional<ParentRef>
Step.roleText
Step.sqlText
Step.tablesList<Text>
Assemble.childrenList<Child>
Assemble.columnsList<OutputColumn>
Assemble.entityText
Db.configConfig
Db.plannersMap<SchemaHash,Planner>
Db.plansCache<Shape,Plan>
Db.poolConnectionPool
Db.statementsCache<Sql,Statement>
Db.subscribersList<StatementSubscriber>
TransactionFlow.framesList<TransactionFrame>
Collection.fetchedMap<Key,Value>
Collection.itemsMap<Key,Model>
Collection.keysList<Key>
Page.itemsCollection
Page.pageInteger
Page.perPageInteger
Page.totalCountInteger
Page.totalPagesInteger
Utils.dbDb
SchemaUtils.dbDb
AesUtils.dbDb
AESKeyring.currentVersionInteger
AESKeyring.versionsMap<Integer,Secret>
AESRotationStatus.currentInteger
AESRotationStatus.pendingInteger
AESRotationStatus.totalInteger
AESRotationStatus.versionsMap<Integer,Integer>
Generator.manifestSchemaManifest
Generator.scanList<Path>
Error.causeOptional<Error>
Error.codeText
Error.messageText

MIT License · Go / PHP / Rust / TypeScript