Class AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>Abstract

Abstract base class for table mappers. It is abstract because it does not provide a way to specify query input and output transforms. Custom table mappers should extend this class with means for providing transforms.

Type Parameters

  • DB

    Interface whose fields are table names defining tables.

  • TB extends keyof DB & string

    Name of the table.

  • KeyColumns extends Readonly<SelectableColumnTuple<DB[TB]>> | Readonly<[]> = []

    Tuple of the names of the table's key columns. Defaults to [], indicating no key columns. Supports up to 4 columns.

  • SelectedColumns extends Readonly<SelectionColumn<DB, TB>[]> | ["*"] = ["*"]

    Columns to return from selection queries. Defaults to ['*'], returning all columns. May specify aliases.

  • SelectedObject = SelectedRow<DB, TB, SelectedColumns extends ["*"]
        ? never
        : SelectedColumns[number], SelectedColumns>

    Type of objects returned by select queries.

  • InsertedObject = Insertable<DB[TB]>

    Type of objects inserted into the table.

  • UpdatingObject = Updateable<DB[TB]>

    Type of objects used to update rows of the table.

  • ReturnCount = bigint

    Type of the count of the number of affected rows.

  • InsertReturnColumns extends Readonly<SelectionColumn<DB, TB>[]> | ["*"] = Readonly<KeyColumns>

    Columns to return from the table on insert queries that return columns. ['*'] returns all columns; [] returns none. May specify aliases. Defaults to KeyColumns.

  • UpdateReturnColumns extends Readonly<SelectionColumn<DB, TB>[]> | ["*"] = []

    Columns to return from the table on update queries that return columns. ['*'] returns all columns; [] returns none and is the default. May specify aliases.

  • InsertReturn = InsertReturnColumns extends ["*"]
        ? Selectable<DB[TB]>
        : Selection<DB, TB, InsertReturnColumns[number]>

    Type returned from inserts. Defaults to an object whose properties are the columns of InsertReturnColumns.

  • UpdateReturn = UpdateReturnColumns extends ["*"]
        ? Selectable<DB[TB]>
        : Selection<DB, TB, UpdateReturnColumns[number]>

    Type returned from updates. Defaults to an object whose properties are the columns of UpdateReturnColumns.

Hierarchy

Constructors

  • Constructs a new abstract table mapper.

    Type Parameters

    • DB

    • TB extends string

    • KeyColumns extends readonly [] | Readonly<SelectableColumnTuple<DB[TB]>> = []

    • SelectedColumns extends ["*"] | readonly SelectionColumn<DB, TB>[] = ["*"]

    • SelectedObject = SelectedRow<DB, TB, SelectedColumns extends ["*"]
          ? never
          : SelectedColumns[number], SelectedColumns>

    • InsertedObject = Insertable<DB[TB]>

    • UpdatingObject = Updateable<DB[TB]>

    • ReturnCount = bigint

    • InsertReturnColumns extends ["*"] | readonly SelectionColumn<DB, TB>[] = Readonly<KeyColumns>

    • UpdateReturnColumns extends ["*"] | readonly SelectionColumn<DB, TB>[] = []

    • InsertReturn = InsertReturnColumns extends ["*"]
          ? Selectable<DB[TB]>
          : Selection<DB, TB, InsertReturnColumns[number]>

    • UpdateReturn = UpdateReturnColumns extends ["*"]
          ? Selectable<DB[TB]>
          : Selection<DB, TB, UpdateReturnColumns[number]>

    Parameters

    • db: Kysely<DB>

      The Kysely instance, either a database or a transaction.

    • tableName: TB

      The name of the table.

    • Optional settings: Readonly<TableMapperSettings<DB, TB, KeyColumns, SelectedColumns, InsertReturnColumns, UpdateReturnColumns>>

      Settings governing mapper behavior. Default to selecting all columns and to returning no columns on insert or update.

    Returns AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>

  • Type Parameters

    • DB

    • TB extends string

    • KeyColumns extends readonly [] | Readonly<SelectableColumnTuple<DB[TB]>> = []

    • SelectedColumns extends ["*"] | readonly SelectionColumn<DB, TB>[] = ["*"]

    • SelectedObject = SelectedRow<DB, TB, SelectedColumns extends ["*"]
          ? never
          : SelectedColumns[number], SelectedColumns>

    • InsertedObject = Insertable<DB[TB]>

    • UpdatingObject = Updateable<DB[TB]>

    • ReturnCount = bigint

    • InsertReturnColumns extends ["*"] | readonly SelectionColumn<DB, TB>[] = Readonly<KeyColumns>

    • UpdateReturnColumns extends ["*"] | readonly SelectionColumn<DB, TB>[] = []

    • InsertReturn = InsertReturnColumns extends ["*"]
          ? Selectable<DB[TB]>
          : Selection<DB, TB, InsertReturnColumns[number]>

    • UpdateReturn = UpdateReturnColumns extends ["*"]
          ? Selectable<DB[TB]>
          : Selection<DB, TB, UpdateReturnColumns[number]>

    Parameters

    • db: Kysely<DB>
    • mapper: AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>

    Returns AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>

Properties

db: Kysely<DB>

The Kysely instance, either a database or a transaction.

insertReturnColumns: ["*"] | readonly SelectionColumn<DB, TB>[]

Columns to return from the table on insert.

keyColumns: KeyColumns

Columns that compose the table's primary key.

selectedColumns: SelectionColumn<DB, TB>[]

Columns to return from selection queries. [] => all columns.

settings: Readonly<TableMapperSettings<DB, TB, KeyColumns, SelectedColumns, InsertReturnColumns, UpdateReturnColumns>>

Settings governing mapper behavior.

tableName: TB

The name of the table.

transforms: TableMapperTransforms<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>

Query input and output value transforms.

updateReturnColumns: ["*"] | readonly SelectionColumn<DB, TB>[]

Columns to return from the table on update.

Methods

  • Returns a mapping query for deleting the rows of the table that match the provided filter or Kysely binary operation.

    Type Parameters

    • RE extends string | DynamicReferenceBuilder<any> | SelectQueryBuilder<any, any, Record<string, any>> | Expression<any> | SelectQueryBuilderFactory<DB, TB, Record<string, any>> | ExpressionFactory<DB, TB, any>

    Parameters

    • lhs: RE
    • op: ComparisonOperatorExpression
    • rhs: OperandValueExpressionOrList<DB, TB, RE>

    Returns MappingDeleteQuery<DB, TB, DeleteQueryBuilder<DB, TB, DeleteResult>, ReturnCount>

    A mapping query for deleting rows.

  • Type Parameters

    • RE extends string | DynamicReferenceBuilder<any> | SelectQueryBuilder<any, any, Record<string, any>> | Expression<any> | SelectQueryBuilderFactory<DB, TB, Record<string, any>> | ExpressionFactory<DB, TB, any>

    Parameters

    Returns MappingDeleteQuery<DB, TB, DeleteQueryBuilder<DB, TB, DeleteResult>, ReturnCount>

  • Returns a query builder for deleting rows from the table, caching the query builder for use with future deletions.

    Returns DeleteQueryBuilder<DB, TB, DeleteResult>

    A query builder for deleting rows from the table.

  • Returns a query builder for inserting rows into the table, caching the query builder for use with future insertions.

    Returns InsertQueryBuilder<DB, TB, InsertResult>

    A query builder for inserting rows into the table.

  • Returns a query builder for selecting rows from the table, caching the query builder for use with future selection. The query builder returns the columns and aliases specified in SelectedColumns.

    Returns SelectedColumns extends ["*"]
        ? never
        : SelectQueryBuilder<DB, TB, object & Selection<DB, TB, SelectedColumns[number]>>

    A query builder for selecting rows from the table.

  • Returns a query builder for updating rows from the table, caching the query builder for use with future updates.

    Returns UpdateQueryBuilder<DB, TB, TB, UpdateResult>

    A query builder for updating rows from the table.

  • Returns a query for inserting rows into the table.

    Returns AnyColumnsMappingInsertQuery<DB, TB, InsertQueryBuilder<DB, TB, InsertResult>, InsertedObject, InsertReturnColumns, InsertReturn>

    A mapping query for inserting rows.

  • Creates and returns a parameterized mapping query, which can be repeatedly executed with different parameter values, but which only ever compiles the underlying Kysely query once (on the first execution).

    Type Parameters

    • Parameters extends ParametersObject<Parameters>

    Parameters

    • factory: ParameterizableMappingQueryFactory<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn, AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>, Parameters, MappingDeleteQuery<DB, TB, DeleteQueryBuilder<DB, TB, DeleteResult>, ReturnCount>>

      Function that receives an object of the form { mapper, param }, where mapper is the present table mapper and param is a function for creating parameters. The argument to param is the name of the parameter, which must occur as a property of Parameters. You may parameterize inserted values, updated values, and right-hand-side values of filters. Parameters may not be arrays, but you can parameterize the individual elements of an array. Returns a parameterized mapping query.

    Returns CompilingMappingDeleteQuery<DB, TB, DeleteQueryBuilder<DB, TB, DeleteResult>, ReturnCount, Parameters>

    A parameterized mapping query

    Paramtype

    Parameters Record characterizing the available parameter names and types.

  • Type Parameters

    • Parameters extends ParametersObject<Parameters>

    Parameters

    • factory: ParameterizableMappingQueryFactory<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn, AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>, Parameters, MappingSelectQuery<DB, TB, SelectedColumns, SelectedObject, SelectQueryBuilder<DB, TB, object>>>

    Returns CompilingMappingSelectQuery<DB, TB, SelectedColumns, SelectedObject, SelectQueryBuilder<DB, TB, object>, Parameters>

  • Type Parameters

    • Parameters extends ParametersObject<Parameters>

    Parameters

    • factory: ParameterizableMappingQueryFactory<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn, AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>, Parameters, SubsettingMappingUpdateQuery<DB, TB, UpdateQueryBuilder<DB, TB, TB, UpdateResult>, UpdatingObject, UpdateReturnColumns, ReturnCount, UpdateReturn>>

    Returns CompilingMappingUpdateQuery<DB, TB, UpdateQueryBuilder<DB, TB, TB, UpdateResult>, UpdatingObject, UpdateReturnColumns, ReturnCount, UpdateReturn, Parameters>

  • Returns a reference to a column, which can be a generated string. (Shorthand for db.dynamic.ref(column).)

    Parameters

    • column: string

      The column name being referenced.

    Returns DynamicReferenceBuilder<never>

    A reference to the given column.

  • Returns a mapping query for selecting rows of the table that match the provided filter or Kysely binary operation.

    Type Parameters

    • RE extends string | DynamicReferenceBuilder<any> | SelectQueryBuilder<any, any, Record<string, any>> | Expression<any> | SelectQueryBuilderFactory<DB, TB, Record<string, any>> | ExpressionFactory<DB, TB, any>

    Parameters

    • lhs: RE
    • op: ComparisonOperatorExpression
    • rhs: OperandValueExpressionOrList<DB, TB, RE>

    Returns MappingSelectQuery<DB, TB, SelectedColumns, SelectedObject, SelectQueryBuilder<DB, TB, object>>

    A mapping query for retrieving rows as objects.

  • Type Parameters

    • RE extends string | DynamicReferenceBuilder<any> | SelectQueryBuilder<any, any, Record<string, any>> | Expression<any> | SelectQueryBuilderFactory<DB, TB, Record<string, any>> | ExpressionFactory<DB, TB, any>

    Parameters

    Returns MappingSelectQuery<DB, TB, SelectedColumns, SelectedObject, SelectQueryBuilder<DB, TB, object>>

  • Returns a mapping query for updating rows of the table that match the provided filter or Kysely binary operation.

    Type Parameters

    • RE extends string | DynamicReferenceBuilder<any> | SelectQueryBuilder<any, any, Record<string, any>> | Expression<any> | SelectQueryBuilderFactory<DB, TB, Record<string, any>> | ExpressionFactory<DB, TB, any>

    Parameters

    • lhs: RE
    • op: ComparisonOperatorExpression
    • rhs: OperandValueExpressionOrList<DB, TB, RE>

    Returns AnyColumnsMappingUpdateQuery<DB, TB, UpdateQueryBuilder<DB, TB, TB, UpdateResult>, UpdatingObject, UpdateReturnColumns, ReturnCount, UpdateReturn>

    A mapping query for updating table rows.

  • Type Parameters

    • RE extends string | DynamicReferenceBuilder<any> | SelectQueryBuilder<any, any, Record<string, any>> | Expression<any> | SelectQueryBuilderFactory<DB, TB, Record<string, any>> | ExpressionFactory<DB, TB, any>

    Parameters

    Returns AnyColumnsMappingUpdateQuery<DB, TB, UpdateQueryBuilder<DB, TB, TB, UpdateResult>, UpdatingObject, UpdateReturnColumns, ReturnCount, UpdateReturn>

Generated using TypeDoc