@getriebe/persistence
Connect the storage adapters and their transaction interfaces.
Source revision 49560371f6cd34d30383df5619df46969c594ae4.
checkRecordKey
Section titled “checkRecordKey”export declare function checkRecordKey(value: string): void;decodeRecordValue
Section titled “decodeRecordValue”export declare function decodeRecordValue(value: unknown): JsonValue;decodeStoredRecords
Section titled “decodeStoredRecords”export declare function decodeStoredRecords(rows: readonly Readonly<Record<string, unknown>>[]): readonly StoredRecord[];encodeRecordValue
Section titled “encodeRecordValue”export declare function encodeRecordValue(value: JsonValue): string;JsonValue
Section titled “JsonValue”export type JsonValue = null | boolean | number | string | readonly JsonValue[] | { readonly [key: string]: JsonValue;};openPostgres
Section titled “openPostgres”export declare function openPostgres(options: PostgresOptions): Promise<Persistence>;openSqlite
Section titled “openSqlite”export declare function openSqlite(options?: SqliteOptions): Promise<Persistence>;Persistence
Section titled “Persistence”export interface Persistence { readonly capabilities: StorageCapabilities; transaction<T>(work: (transaction: StorageTransaction) => Promise<T> | T): Promise<T>; close(): Promise<void>;}PersistenceError
Section titled “PersistenceError”export declare class PersistenceError extends Error { readonly code: PersistenceErrorCode; constructor(code: PersistenceErrorCode, message: string, options?: ErrorOptions);}PersistenceErrorCode
Section titled “PersistenceErrorCode”export type PersistenceErrorCode = "conflict" | "unavailable" | "storage" | "commit-unknown" | "schema-incompatible" | "invalid-use";PostgresOptions
Section titled “PostgresOptions”export interface PostgresOptions { readonly connectionString: string;}recordKey
Section titled “recordKey”export declare function recordKey(namespace: string, id: string): readonly [string, string];recordSchemaUpdates
Section titled “recordSchemaUpdates”export declare function recordSchemaUpdates(rows: readonly Readonly<Record<string, unknown>>[]): readonly string[];recordStoreSql
Section titled “recordStoreSql”export declare const recordStoreSql: Readonly<{ createVersionTable: "CREATE TABLE IF NOT EXISTS getriebe_schema (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n version INTEGER NOT NULL\n )"; readVersion: "SELECT version FROM getriebe_schema"; verifyRecordTable: "SELECT namespace, id, value FROM getriebe_record WHERE 1 = 0"; get: "SELECT value FROM getriebe_record WHERE namespace = $1 AND id = $2"; list: "SELECT id, value FROM getriebe_record WHERE namespace = $1"; put: "INSERT INTO getriebe_record (namespace, id, value) VALUES ($1, $2, $3)\n ON CONFLICT (namespace, id) DO UPDATE SET value = excluded.value"; delete: "DELETE FROM getriebe_record WHERE namespace = $1 AND id = $2";}>;SqliteOptions
Section titled “SqliteOptions”export interface SqliteOptions { readonly path?: string;}StorageCapabilities
Section titled “StorageCapabilities”export interface StorageCapabilities { readonly adapter: "sqlite" | "postgres"; readonly isolation: "serialized-sqlite-writers" | "serializable"; readonly survivesOrderedRestart: boolean;}StorageTransaction
Section titled “StorageTransaction”export interface StorageTransaction { get(namespace: string, id: string): Promise<JsonValue | undefined>; list(namespace: string): Promise<readonly StoredRecord[]>; put(namespace: string, id: string, value: JsonValue): Promise<void>; delete(namespace: string, id: string): Promise<boolean>;}StoredRecord
Section titled “StoredRecord”export interface StoredRecord { readonly id: string; readonly value: JsonValue;}