Cloudflare - v1.3.0
    Preparing search index...

    Class D1Service<E>

    D1 capability.

    The relational-storage half of the core: queries, writes, and batches expressed in SQL, with the binding and its configuration kept out of sight.

    Callers pass values separately from the statement, so user input is always parameterised. Nothing here knows what the rows mean — the schema belongs to whichever business service owns it.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Implements

    • DataStore<E>
    Index
    • Runs a query and returns every row.

      Type Parameters

      • T = Record<string, unknown>

      Parameters

      • env: E

        The Worker environment.

      • sql: string

        SQL statement, using ? placeholders for bind values.

      • ...values: unknown[]

        Values bound to the placeholders, in order.

      Returns Promise<T[]>

      The matched rows, empty when the query matched nothing.

    • Runs several statements as one batch.

      The batch shares an implicit transaction, so a failure part-way through rolls the whole set back.

      Parameters

      • env: E

        The Worker environment.

      • statements: SqlStatement[]

        Statements and their bind values, in execution order.

      Returns Promise<SqlWriteResult[]>

      One result per statement, in the order supplied.

    • Runs a query and returns its first row.

      Type Parameters

      • T = Record<string, unknown>

      Parameters

      • env: E

        The Worker environment.

      • sql: string

        SQL statement, using ? placeholders for bind values.

      • ...values: unknown[]

        Values bound to the placeholders, in order.

      Returns Promise<T>

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

    • Reports whether the database is bound to this Worker.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Runs a write and reports what it changed.

      Parameters

      • env: E

        The Worker environment.

      • sql: string

        SQL statement, using ? placeholders for bind values.

      • ...values: unknown[]

        Values bound to the placeholders, in order.

      Returns Promise<SqlWriteResult>

      The row count and the id assigned by an insert.