skip to the page

@jam-overture/loom/postgres

The Postgres store. Same contract, a database behind it.

Everything below is exported from that import. The names, the signatures and the sentences are read from the package itself rather than written here, so this page says what the copy of Loom in your node_modules says — and it changes in the same pull request the code does.

10 exports, in 5 modules. Generated from ./dist/store/postgres.d.ts, which is the declaration file this package publishes for @jam-overture/loom/postgres.

Install this first. @jam-overture/loom/postgres loads it the moment the import runs. Without it, the import itself fails — before any of your own code has run.

  • drizzle-orm^0.45.2optional peer dependency
pnpm add drizzle-orm

No import here has everything behind it. @jam-overture/loom/postgres publishes 10 of the 1,298 names this package publishes. The other 1,288 are behind one of the 16 other imports, and not one of those imports publishes a single name this one does. The imports do not nest: a name that is not on this page is not a name that does not exist, and the search at the top of the page says which import it comes from.

Database

store/database

The database handle the postgres store and its migration share.

LoomDatabasetype

The narrowest Drizzle type that both the postgres.js and PGlite drivers satisfy. It lives alone so that migrate.ts and postgres.ts can share it without importing each other.

type LoomDatabase = PgDatabase<PgQueryResultHKT>;

Migrate

store/migrate

Creating the tables the postgres store expects.

TREE_STORE_DDLvalue

The schema, as statements a host can run.

const TREE_STORE_DDL: readonly string[]

HOLD_STORE_DDLvalue

The hold store's schema, as statements a host can run.

const HOLD_STORE_DDL: readonly string[]

ensureTreeStoreSchemafunction

Creates the tables if they are absent. Every statement is IF NOT EXISTS, so running it against a populated database is a no-op rather than a hazard.

Shown in use on Going to production — Creating them is one call, and running it twice is a no-op

const ensureTreeStoreSchema: (db: LoomDatabase) => Promise<void>

ensureHoldStoreSchemafunction

Creates the hold table if it is absent. Idempotent on the same terms.

Shown in use on Going to production — Creating them is one call, and running it twice is a no-op

const ensureHoldStoreSchema: (db: LoomDatabase) => Promise<void>

Postgres

store/postgres

The store, backed by Postgres.

postgresTreeStorefunction

Shown in use on The history of a page — Where this actually runs, What your app has to do — The three things a change needs and Going to production — Three places state lives, and only one of them is your pages

const postgresTreeStore: (db: LoomDatabase) => TreeStore

Postgres holds

store/postgres-holds

Custody of held proposals, backed by Postgres.

postgresHoldStorefunction

Shown in use on Answering a held change — Where a waiting change waits, What your app has to do — The three things a change needs and Going to production — Three places state lives, and only one of them is your pages

const postgresHoldStore: (db: LoomDatabase) => HoldStore

Schema

store/schema

Two tables: the log, and the snapshot it produces.

loomTreesvalue

The snapshot. document is the whole LoomTree, stored as JSON rather than decomposed into node rows — the tree is read and written whole, and a schema that shredded it would have to be migrated every time §1 changes the AST.

const loomTrees: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "loom_trees";
    schema: undefined;
    columns: {
        treeId: import("drizzle-orm/pg-core").PgColumn<{
            name: "tree_id";
            tableName: "loom_trees";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        revision: import("drizzle-orm/pg-core").PgColumn<{
            name: "revision";
            tableName: "loom_trees";
            dataType: "number";
            columnType: "PgInteger";
            data: number;
            driverParam: string | number;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        document: import("drizzle-orm/pg-core").PgColumn<{
            name: "document";
            tableName: "loom_trees";
            dataType: "json";
            columnType: "PgJsonb";
            data: unknown;
            driverParam: unknown;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        updatedAt: import("drizzle-orm/pg-core").PgColumn<{
            name: "updated_at";
            tableName: "loom_trees";
            dataType: "date";
            columnType: "PgTimestamp";
            data: Date;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    };
    dialect: "pg";
}>

loomRevisionsvalue

The log. The composite primary key is load-bearing rather than incidental: it makes the *database* enforce the revision sequence, so two writers racing at the same base revision cannot both commit even if both passed the base-revision check before either finished. The in-memory store gets that property from being single-threaded; here it has to come from a constraint.

const loomRevisions: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "loom_revisions";
    schema: undefined;
    columns: {
        treeId: import("drizzle-orm/pg-core").PgColumn<{
            name: "tree_id";
            tableName: "loom_revisions";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        revision: import("drizzle-orm/pg-core").PgColumn<{
            name: "revision";
            tableName: "loom_revisions";
            dataType: "number";
            columnType: "PgInteger";
            data: number;
            driverParam: string | number;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        proposalId: import("drizzle-orm/pg-core").PgColumn<{
            name: "proposal_id";
            tableName: "loom_revisions";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        delta: import("drizzle-orm/pg-core").PgColumn<{
            name: "delta";
            tableName: "loom_revisions";
            dataType: "json";
            columnType: "PgJsonb";
            data: unknown;
            driverParam: unknown;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        provenance: import("drizzle-orm/pg-core").PgColumn<{
            name: "provenance";
            tableName: "loom_revisions";
            dataType: "json";
            columnType: "PgJsonb";
            data: unknown;
            driverParam: unknown;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        appliedAt: import("drizzle-orm/pg-core").PgColumn<{
            name: "applied_at";
            tableName: "loom_revisions";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        answeredBy: import("drizzle-orm/pg-core").PgColumn<{
            name: "answered_by";
            tableName: "loom_revisions";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    };
    dialect: "pg";
}>

loomHoldsvalue

The custody of what the Gate held back.

const loomHolds: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "loom_holds";
    schema: undefined;
    columns: {
        proposalId: import("drizzle-orm/pg-core").PgColumn<{
            name: "proposal_id";
            tableName: "loom_holds";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        treeId: import("drizzle-orm/pg-core").PgColumn<{
            name: "tree_id";
            tableName: "loom_holds";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        baseRevision: import("drizzle-orm/pg-core").PgColumn<{
            name: "base_revision";
            tableName: "loom_holds";
            dataType: "number";
            columnType: "PgInteger";
            data: number;
            driverParam: string | number;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        intent: import("drizzle-orm/pg-core").PgColumn<{
            name: "intent";
            tableName: "loom_holds";
            dataType: "json";
            columnType: "PgJsonb";
            data: unknown;
            driverParam: unknown;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        proposal: import("drizzle-orm/pg-core").PgColumn<{
            name: "proposal";
            tableName: "loom_holds";
            dataType: "json";
            columnType: "PgJsonb";
            data: unknown;
            driverParam: unknown;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        disposition: import("drizzle-orm/pg-core").PgColumn<{
            name: "disposition";
            tableName: "loom_holds";
            dataType: "json";
            columnType: "PgJsonb";
            data: unknown;
            driverParam: unknown;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        heldAt: import("drizzle-orm/pg-core").PgColumn<{
            name: "held_at";
            tableName: "loom_holds";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    };
    dialect: "pg";
}>