Core - v1.0.0
    Preparing search index...

    Interface DataStore<TRuntime>

    Relational storage addressed with SQL.

    Deliberately expressed in SQL and rows rather than entities. Nothing at this level knows what an article or a user is; mapping rows onto a domain is the business service's job, which is what keeps one storage capability usable by every service in the application.

    Unlike a cache, storage is not optional infrastructure — an implementation whose Capability.isAvailable is false throws rather than quietly returning nothing, because a silent empty result set is indistinguishable from real data and would corrupt whatever read it.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    interface DataStore<TRuntime = unknown> {
        all<T = Record<string, unknown>>(
            runtime: TRuntime,
            sql: string,
            ...values: unknown[],
        ): Promise<T[]>;
        batch(
            runtime: TRuntime,
            statements: SqlStatement[],
        ): Promise<SqlWriteResult[]>;
        first<T = Record<string, unknown>>(
            runtime: TRuntime,
            sql: string,
            ...values: unknown[],
        ): Promise<T>;
        isAvailable(runtime: TRuntime): boolean;
        write(
            runtime: TRuntime,
            sql: string,
            ...values: unknown[],
        ): Promise<SqlWriteResult>;
    }

    Type Parameters

    • TRuntime = unknown

      The runtime handle the store is resolved from.

    Hierarchy (View Summary)

    Index
    • Runs a query and returns every row.

      Type Parameters

      • T = Record<string, unknown>

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • sql: string

        The query, using ? placeholders.

      • ...values: unknown[]

        Values bound to the placeholders, in order.

      Returns Promise<T[]>

      The rows.

    • Runs a query and returns its first row.

      Type Parameters

      • T = Record<string, unknown>

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • sql: string

        The query, using ? placeholders.

      • ...values: unknown[]

        Values bound to the placeholders, in order.

      Returns Promise<T>

      The first row, or null when the query matched nothing.

    • Reports whether the capability is actually usable on this runtime.

      Parameters

      Returns boolean

      true when calls will reach a real backing resource.

      A capability backed by an optional resource answers false when that resource was never provisioned. Implementations must document what each method does in that state — degrade or throw — and must not vary it, since a caller choosing between two implementations is relying on the answer meaning the same thing in both.