Options
All
  • Public
  • Public/Protected
  • All
Menu

Class QueryUpsert

An 'upsert' query is using the values of the primary key fields to find and update a record, if not found a new record is created and the query behaves like an 'insert'.

since

1.1.0

see

QueryInsert

Hierarchy

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new QueryUpsert(connection: Connection, table: string, values: Record): QueryUpsert
  • Creates an upsert query for one table of an API connection.

    Parameters

    • connection: Connection

      The API connection.

    • table: string

      The name of the table to update or create a new record into.

    • values: Record

      The field values to set when the query is executed.

    Returns QueryUpsert

Properties

Protected _upsert

_upsert: boolean = false

Accessors

fields

table

  • get table(): string
  • The table name where the new record is to be created.

    Returns string

Methods

execute

  • execute(timeout?: number): Promise<number>
  • An alias for go method.

    since

    1.1.0

    Parameters

    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<number>

fetch

  • fetch(timeout?: number): Promise<Record>
  • Asynchronously executes the insert query and, when fulfilled, returns the created row.

    since

    1.1.0

    Parameters

    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<Record>

go

  • go(timeout?: number): Promise<number>
  • Asynchronously executes the insert query and, when fulfilled, returns the number of affected (created) rows.

    since

    1.1.0

    Parameters

    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<number>

set

  • Set the value to be assigned for a field when the query is executed.

    since

    1.1.0

    Parameters

    • fieldName: string

      The name of the field, use square brackets to specify an array item.

    • value: FieldValue | FieldValue[]

      The value to set for that field.

    • Optional extent: number

    Returns QueryInsert

    Returns the current query instance (fluent interface).

Static execute

  • execute(connection: Connection, query: IQueryInsert, fetch?: boolean, upsert?: boolean, timeout?: number): Promise<Record | number>
  • Asynchronously executes the insert query on the connection and, when fulfilled, returns the created row or the number of rows affected.

    Parameters

    • connection: Connection

      An open connection to the akera.io application server.

    • query: IQueryInsert

      The insert query definition, table name and at least the primary key values are mandatory.

    • Default value fetch: boolean = false

      If set to true the complete record will be returned if created (field values might be updated by triggers).

    • Default value upsert: boolean = false

      If set and a record with the same primary key values is found the record is updated, else the insert fails.

    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<Record | number>

Static normalizeSetFields