Entity
    Preparing search index...

    SQL Fragment class that safely handles parameterized queries.

    Type Parameters

    • TFields extends Record<string, any>

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    bindings: readonly SQLBinding<TFields>[]
    sql: string

    Methods

    • Get bindings in the format expected by Knex. Knex expects a flat array where both identifiers and values are mixed in order.

      Parameters

      • getColumnForField: (fieldName: keyof TFields) => string

        function that resolves an entity field name to its database column name

      Returns readonly RawBinding[]

    • Concatenate multiple SQL fragments with space separator. Useful for combining SQL clauses like WHERE, ORDER BY, etc.

      Type Parameters

      • TFields extends Record<string, any>

      Parameters

      Returns SQLFragment<TFields>

      const where = sql`WHERE age > ${18}`;
      const orderBy = sql`ORDER BY name`;
      const query = SQLFragment.concat(sql`SELECT * FROM users`, where, orderBy);
      // Generates: "SELECT * FROM users WHERE age > ? ORDER BY name"