Class EntityDatabaseAdapter<TFields>Abstract

A database adapter is an interface by which entity objects can be fetched, inserted, updated, and deleted from a database. This base class handles all entity field transformation. Subclasses are responsible for implementing database-specific logic for a type of database.

Type Parameters

  • TFields extends Record<string, any>

Hierarchy (view full)

Constructors

Methods

  • Delete an object by ID.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • queryContext: EntityQueryContext

      query context with which to perform the deletion

    • idField: K

      the field in the object that is the ID

    • id: any

      the value of the ID field in the object

    Returns Promise<void>

  • Fetch many objects matching the conjunction of where clauses constructed from specified field equality operands.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    Returns Promise<readonly Readonly<TFields>[]>

    array of objects matching the query

  • Fetch many objects matching the raw WHERE clause.

    Parameters

    • queryContext: EntityQueryContext

      query context with which to perform the fetch

    • rawWhereClause: string

      parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders

    • bindings: object | any[]

      array of positional bindings or object of named bindings

    • querySelectionModifiers: QuerySelectionModifiersWithOrderByRaw<TFields>

      limit, offset, and orderBy for the query

    Returns Promise<readonly Readonly<TFields>[]>

    array of objects matching the query

  • Fetch many objects where fieldName is one of fieldValues.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • queryContext: EntityQueryContext

      query context with which to perform the fetch

    • fieldName: K

      object field being queried

    • fieldValues: readonly NonNullable<TFields[K]>[]

      fieldName field values being queried

    Returns Promise<ReadonlyMap<NonNullable<TFields[K]>, readonly Readonly<TFields>[]>>

    map from fieldValue to objects that match the query for that fieldValue

  • Parameters

    • queryInterface: any
    • tableName: string
    • tableField: string
    • tableValues: readonly any[]

    Returns Promise<object[]>

  • Update an object.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • queryContext: EntityQueryContext

      query context with which to perform the update

    • idField: K

      the field in the object that is the ID

    • id: any

      the value of the ID field in the object

    • object: Readonly<Partial<TFields>>

      the object to update

    Returns Promise<Readonly<TFields>>

    the updated object

  • Parameters

    • queryInterface: any
    • tableName: string
    • tableIdField: string
    • id: any
    • object: object

    Returns Promise<object[]>