Options
All
  • Public
  • Public/Protected
  • All
Menu

Class QueryInsert

An 'insert' query is creating a new record in the table and sets the values for each field specified in the query. If any unique constraint is violated the insert fails.

since

1.1.0

see

QueryUpsert

Hierarchy

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

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

    since

    1.1.0

    Parameters

    • connection: Connection

      The API connection.

    • table: string

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

    • values: Record

      The field values to set when the query is executed.

    Returns QueryInsert

Properties

Protected _upsert

_upsert: boolean = false

Accessors

fields

  • The field and values to set when the query is executed.

    Returns ISetField[]

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