Skip to main content
Version: 5.9

Knex <TRecord, TResult>

Hierarchy

  • QueryInterface<TRecord, TResult>
  • EventEmitter
    • Knex

Callable

  • Knex<TTable>(tableName: TTable, options?: PgTableOptions): QueryBuilder<TableType<TTable>, DeferredKeySelection<ResolveTableType<TableType<TTable>, base>, never, false, {}, false, {}, never>[]>
  • Knex<TRecord2, TResult2>(tableName?: TableDescriptor | AliasDict, options?: PgTableOptions): QueryBuilder<TRecord2, TResult2>

  • Type parameters

    • TTable: never

    Parameters

    • tableName: TTable
    • optionaloptions: PgTableOptions

    Returns QueryBuilder<TableType<TTable>, DeferredKeySelection<ResolveTableType<TableType<TTable>, base>, never, false, {}, false, {}, never>[]>

Index

Properties

Methods

Properties

VERSION

VERSION: string

__knex__

__knex__: string

andHaving

andHaving: Having<TRecord, TResult>

andHavingNotIn

andHavingNotIn: HavingRange<TRecord, TResult>

andWhere

andWhere: Where<TRecord, TResult>

andWhereBetween

andWhereBetween: WhereBetween<TRecord, TResult>

andWhereILike

andWhereILike: Where<TRecord, TResult>

andWhereJsonNotSubsetOf

andWhereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>

andWhereJsonNotSupersetOf

andWhereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>

andWhereJsonObject

andWhereJsonObject: WhereJsonObject<TRecord, TResult>

andWhereJsonPath

andWhereJsonPath: WhereJsonPath<TRecord, TResult>

andWhereJsonSubsetOf

andWhereJsonSubsetOf: WhereJsonObject<TRecord, TResult>

andWhereJsonSupersetOf

andWhereJsonSupersetOf: WhereJsonObject<TRecord, TResult>

andWhereLike

andWhereLike: Where<TRecord, TResult>

andWhereNot

andWhereNot: Where<TRecord, TResult>

andWhereNotBetween

andWhereNotBetween: WhereBetween<TRecord, TResult>

andWhereNotJsonObject

andWhereNotJsonObject: WhereJsonObject<TRecord, TResult>

andWhereRaw

andWhereRaw: WhereRaw<TRecord, TResult>

as

as: As<TRecord, TResult>

avg

avg: TypePreservingAggregation<TRecord, TResult, any>

avgDistinct

avgDistinct: TypePreservingAggregation<TRecord, TResult, any>

client

client: any

column

column: Select<TRecord, TResult>

columns

columns: Select<TRecord, TResult>

comment

comment: Comment<TRecord, TResult>

count

count: AsymmetricAggregation<TRecord, TResult, string | number>

countDistinct

countDistinct: AsymmetricAggregation<TRecord, TResult, string | number>

crossJoin

crossJoin: Join<TRecord, TResult>

denseRank

denseRank: AnalyticFunction<TRecord, TResult>

distinct

distinct: Distinct<TRecord, TResult>

distinctOn

distinctOn: DistinctOn<TRecord, TResult>

except

except: Except<TRecord, TResult>

first

first: Select<TRecord, AddUnionMember<UnwrapArrayMember<TResult>, undefined>>

fn

fn: FunctionHelper

from

from: Table<TRecord, TResult>

fromRaw

fromRaw: Table<TRecord, TResult>

fullOuterJoin

fullOuterJoin: Join<TRecord, TResult>

groupBy

groupBy: GroupBy<TRecord, TResult>

groupByRaw

groupByRaw: RawQueryBuilder<TRecord, TResult>

having

having: Having<TRecord, TResult>

havingBetween

havingBetween: HavingRange<TRecord, TResult>

havingIn

havingIn: HavingRange<TRecord, TResult>

havingNotBetween

havingNotBetween: HavingRange<TRecord, TResult>

havingNotIn

havingNotIn: HavingRange<TRecord, TResult>

havingNotNull

havingNotNull: HavingNull<TRecord, TResult>

havingNull

havingNull: HavingNull<TRecord, TResult>

havingRaw

havingRaw: RawQueryBuilder<TRecord, TResult>

havingWrapped

havingWrapped: WhereWrapped<TRecord, TResult>

hintComment

hintComment: HintComment<TRecord, TResult>

innerJoin

innerJoin: Join<TRecord, TResult>

intersect

intersect: Intersect<TRecord, TResult>

into

into: Table<TRecord, TResult>

optionalisTransaction

isTransaction?: boolean

join

join: Join<TRecord, TResult>

joinRaw

joinRaw: JoinRaw<TRecord, TResult>

jsonExtract

jsonExtract: JsonExtract<TRecord, TResult>

jsonInsert

jsonInsert: JsonInsert<TRecord, TResult>

jsonRemove

jsonRemove: JsonRemove<TRecord, TResult>

jsonSet

jsonSet: JsonSet<TRecord, TResult>

leftJoin

leftJoin: Join<TRecord, TResult>

leftOuterJoin

leftOuterJoin: Join<TRecord, TResult>

max

max: TypePreservingAggregation<TRecord, TResult, any>

migrate

migrate: Migrator

min

min: TypePreservingAggregation<TRecord, TResult, any>

orHaving

orHaving: Having<TRecord, TResult>

orHavingBetween

orHavingBetween: HavingRange<TRecord, TResult>

orHavingNotBetween

orHavingNotBetween: HavingRange<TRecord, TResult>

orHavingNotIn

orHavingNotIn: HavingRange<TRecord, TResult>

orHavingRaw

orHavingRaw: RawQueryBuilder<TRecord, TResult>

orWhere

orWhere: Where<TRecord, TResult>

orWhereBetween

orWhereBetween: WhereBetween<TRecord, TResult>

orWhereExists

orWhereExists: WhereExists<TRecord, TResult>

orWhereILike

orWhereILike: Where<TRecord, TResult>

orWhereIn

orWhereIn: WhereIn<TRecord, TResult>

orWhereJsonNotSubsetOf

orWhereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>

orWhereJsonNotSupersetOf

orWhereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>

orWhereJsonObject

orWhereJsonObject: WhereJsonObject<TRecord, TResult>

orWhereJsonPath

orWhereJsonPath: WhereJsonPath<TRecord, TResult>

orWhereJsonSubsetOf

orWhereJsonSubsetOf: WhereJsonObject<TRecord, TResult>

orWhereJsonSupersetOf

orWhereJsonSupersetOf: WhereJsonObject<TRecord, TResult>

orWhereLike

orWhereLike: Where<TRecord, TResult>

orWhereNot

orWhereNot: Where<TRecord, TResult>

orWhereNotBetween

orWhereNotBetween: WhereBetween<TRecord, TResult>

orWhereNotExists

orWhereNotExists: WhereExists<TRecord, TResult>

orWhereNotIn

orWhereNotIn: WhereIn<TRecord, TResult>

orWhereNotJsonObject

orWhereNotJsonObject: WhereJsonObject<TRecord, TResult>

orWhereNotNull

orWhereNotNull: WhereNull<TRecord, TResult>

orWhereNull

orWhereNull: WhereNull<TRecord, TResult>

orWhereRaw

orWhereRaw: WhereRaw<TRecord, TResult>

orderBy

orderBy: OrderBy<TRecord, TResult>

orderByRaw

orderByRaw: RawQueryBuilder<TRecord, TResult>

outerJoin

outerJoin: Join<TRecord, TResult>

partitionBy

partitionBy: PartitionBy<TRecord, TResult>

rank

rank: AnalyticFunction<TRecord, TResult>

raw

raw: RawBuilder<TRecord, any>

ref

ref: RefBuilder

rightJoin

rightJoin: Join<TRecord, TResult>

rightOuterJoin

rightOuterJoin: Join<TRecord, TResult>

rowNumber

rowNumber: AnalyticFunction<TRecord, TResult>

schema

schema: SchemaBuilder

seed

seed: Seeder

select

select: Select<TRecord, TResult>

sum

sum: TypePreservingAggregation<TRecord, TResult, any>

sumDistinct

sumDistinct: TypePreservingAggregation<TRecord, TResult, any>

table

table: Table<TRecord, TResult>

union

union: Union<TRecord, TResult>

unionAll

unionAll: Union<TRecord, TResult>

updateFrom

updateFrom: Table<TRecord, TResult>

userParams

userParams: Record<string, any>

using

using: Using<TRecord, TResult>

where

where: Where<TRecord, TResult>

whereBetween

whereBetween: WhereBetween<TRecord, TResult>

whereExists

whereExists: WhereExists<TRecord, TResult>

whereILike

whereILike: Where<TRecord, TResult>

whereIn

whereIn: WhereIn<TRecord, TResult>

whereJsonNotSubsetOf

whereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>

whereJsonNotSupersetOf

whereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>

whereJsonObject

whereJsonObject: WhereJsonObject<TRecord, TResult>

whereJsonPath

whereJsonPath: WhereJsonPath<TRecord, TResult>

whereJsonSubsetOf

whereJsonSubsetOf: WhereJsonObject<TRecord, TResult>

whereJsonSupersetOf

whereJsonSupersetOf: WhereJsonObject<TRecord, TResult>

whereLike

whereLike: Where<TRecord, TResult>

whereNot

whereNot: Where<TRecord, TResult>

whereNotBetween

whereNotBetween: WhereBetween<TRecord, TResult>

whereNotExists

whereNotExists: WhereExists<TRecord, TResult>

whereNotIn

whereNotIn: WhereIn<TRecord, TResult>

whereNotJsonObject

whereNotJsonObject: WhereJsonObject<TRecord, TResult>

whereNotNull

whereNotNull: WhereNull<TRecord, TResult>

whereNull

whereNull: WhereNull<TRecord, TResult>

whereRaw

whereRaw: WhereRaw<TRecord, TResult>

whereWrapped

whereWrapped: WhereWrapped<TRecord, TResult>

with

with: With<TRecord, TResult>

withMaterialized

withMaterialized: With<TRecord, TResult>

withNotMaterialized

withNotMaterialized: With<TRecord, TResult>

withRaw

withRaw: WithRaw<TRecord, TResult>

withRecursive

withRecursive: With<TRecord, TResult>

withSchema

withSchema: WithSchema<TRecord, TResult>

withWrapped

withWrapped: WithWrapped<TRecord, TResult>

Methods

optional[captureRejectionSymbol]

  • [captureRejectionSymbol](error: Error, event: string, ...args: any[]): void
  • Parameters

    • error: Error
    • event: string
    • rest...args: any[]

    Returns void

addListener

  • addListener(eventName: string | symbol, listener: (...args: any[]) => void): Knex<TRecord, TResult>
  • Alias for emitter.on(eventName, listener).

    @since

    v0.1.26


    Parameters

    • eventName: string | symbol
    • listener: (...args: any[]) => void

      Returns Knex<TRecord, TResult>

    batchInsert

    • batchInsert<TRecord2, TResult2>(tableName: TableDescriptor, data: TRecord2 extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? readonly ResolveTableType<TRecord2, insert>[] : readonly DbRecordArr<TRecord2>[], chunkSize?: number): BatchInsertBuilder<TRecord2, TResult2>
    • Type parameters

      • TRecord2: {} = TRecord
      • TResult2 = number[]

      Parameters

      • tableName: TableDescriptor
      • data: TRecord2 extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? readonly ResolveTableType<TRecord2, insert>[] : readonly DbRecordArr<TRecord2>[]
      • optionalchunkSize: number

      Returns BatchInsertBuilder<TRecord2, TResult2>

    clear

    • clear(statement: ClearStatements): QueryBuilder<TRecord, TResult>
    • Parameters

      • statement: ClearStatements

      Returns QueryBuilder<TRecord, TResult>

    clearCounters

    • clearCounters(): QueryBuilder<TRecord, TResult>
    • Returns QueryBuilder<TRecord, TResult>

    clearGroup

    • clearGroup(): QueryBuilder<TRecord, TResult>
    • Returns QueryBuilder<TRecord, TResult>

    clearHaving

    • clearHaving(): QueryBuilder<TRecord, TResult>
    • Returns QueryBuilder<TRecord, TResult>

    clearOrder

    • clearOrder(): QueryBuilder<TRecord, TResult>
    • Returns QueryBuilder<TRecord, TResult>

    clearSelect

    • clearSelect(): QueryBuilder<TRecord, UnwrapArrayMember<TResult> extends DeferredKeySelection<TBase, TKeys, true, any, any, any, any> ? DeferredKeySelection<TBase, never, false, {}, false, {}, never>[] : TResult>
    • Returns QueryBuilder<TRecord, UnwrapArrayMember<TResult> extends DeferredKeySelection<TBase, TKeys, true, any, any, any, any> ? DeferredKeySelection<TBase, never, false, {}, false, {}, never>[] : TResult>

    clearWhere

    • clearWhere(): QueryBuilder<TRecord, TResult>
    • Returns QueryBuilder<TRecord, TResult>

    decrement

    • decrement(columnName: keyof TRecord, amount?: number): QueryBuilder<TRecord, number>
    • decrement(columnName: string, amount?: number): QueryBuilder<TRecord, number>
    • decrement(columns: { [ column in string | number | symbol ]: number }): QueryBuilder<TRecord, number>
    • Parameters

      • columnName: keyof TRecord
      • optionalamount: number

      Returns QueryBuilder<TRecord, number>

    del

    • del(returning: *, options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>
    • del<TKey, TResult2>(returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • del<TKey, TResult2>(returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2[]>
    • del<TResult2>(returning: string | readonly string[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • del<TResult2>(): QueryBuilder<TRecord, TResult2>
    • Parameters

      • returning: *
      • optionaloptions: DMLOptions

      Returns QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>

    delete

    • delete(returning: *, options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>
    • delete<TKey, TResult2>(returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • delete<TKey, TResult2>(returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • delete<TResult2>(returning: string | Raw<any> | readonly (string | Raw<any>)[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • delete<TResult2>(): QueryBuilder<TRecord, TResult2>
    • Parameters

      • returning: *
      • optionaloptions: DMLOptions

      Returns QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>

    destroy

    • destroy(callback: Function): void
    • destroy(): Promise<void>
    • Parameters

      • callback: Function

      Returns void

    emit

    • emit(eventName: string | symbol, ...args: any[]): boolean
    • Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each.

      Returns true if the event had listeners, false otherwise.

      import { EventEmitter } from 'node:events';
      const myEmitter = new EventEmitter();

      // First listener
      myEmitter.on('event', function firstListener() {
      console.log('Helloooo! first listener');
      });
      // Second listener
      myEmitter.on('event', function secondListener(arg1, arg2) {
      console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
      });
      // Third listener
      myEmitter.on('event', function thirdListener(...args) {
      const parameters = args.join(', ');
      console.log(`event with parameters ${parameters} in third listener`);
      });

      console.log(myEmitter.listeners('event'));

      myEmitter.emit('event', 1, 2, 3, 4, 5);

      // Prints:
      // [
      // [Function: firstListener],
      // [Function: secondListener],
      // [Function: thirdListener]
      // ]
      // Helloooo! first listener
      // event with parameters 1, 2 in second listener
      // event with parameters 1, 2, 3, 4, 5 in third listener
      @since

      v0.1.26


      Parameters

      • eventName: string | symbol
      • rest...args: any[]

      Returns boolean

    eventNames

    • eventNames(): (string | symbol)[]
    • Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

      import { EventEmitter } from 'node:events';

      const myEE = new EventEmitter();
      myEE.on('foo', () => {});
      myEE.on('bar', () => {});

      const sym = Symbol('symbol');
      myEE.on(sym, () => {});

      console.log(myEE.eventNames());
      // Prints: [ 'foo', 'bar', Symbol(symbol) ]
      @since

      v6.0.0


      Returns (string | symbol)[]

    getMaxListeners

    • getMaxListeners(): number
    • Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.

      @since

      v1.0.0


      Returns number

    increment

    • increment(columnName: keyof TRecord, amount?: number): QueryBuilder<TRecord, number>
    • increment(columnName: string, amount?: number): QueryBuilder<TRecord, number>
    • increment(columns: { [ column in string | number | symbol ]: number }): QueryBuilder<TRecord, number>
    • Parameters

      • columnName: keyof TRecord
      • optionalamount: number

      Returns QueryBuilder<TRecord, number>

    initialize

    • initialize(config?: Config<any>): void
    • Parameters

      • optionalconfig: Config<any>

      Returns void

    insert

    • insert(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, insert> | readonly ResolveTableType<TRecord, insert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: *, options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>
    • insert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, insert> | readonly ResolveTableType<TRecord, insert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • insert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, insert> | readonly ResolveTableType<TRecord, insert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • insert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, insert> | readonly ResolveTableType<TRecord, insert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • insert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, insert> | readonly ResolveTableType<TRecord, insert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
    • insert<TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, insert> | readonly ResolveTableType<TRecord, insert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[]): QueryBuilder<TRecord, TResult2>
    • Parameters

      • data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, insert> | readonly ResolveTableType<TRecord, insert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[]
      • returning: *
      • optionaloptions: DMLOptions

      Returns QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>

    limit

    • limit(limit: number, options?: string | Readonly<{ skipBinding?: boolean }>): QueryBuilder<TRecord, TResult>
    • Parameters

      • limit: number
      • optionaloptions: string | Readonly<{ skipBinding?: boolean }>

      Returns QueryBuilder<TRecord, TResult>

    listenerCount

    • listenerCount(eventName: string | symbol, listener?: Function): number
    • Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

      @since

      v3.2.0


      Parameters

      • eventName: string | symbol

        The name of the event being listened for

      • optionallistener: Function

        The event handler function

      Returns number

    listeners

    • listeners(eventName: string | symbol): Function[]
    • Returns a copy of the array of listeners for the event named eventName.

      server.on('connection', (stream) => {
      console.log('someone connected!');
      });
      console.log(util.inspect(server.listeners('connection')));
      // Prints: [ [Function] ]
      @since

      v0.1.26


      Parameters

      • eventName: string | symbol

      Returns Function[]

    modify

    • modify<TRecord2, TResult2>(callback: QueryCallbackWithArgs<TRecord, any>, ...args: any[]): QueryBuilder<TRecord2, TResult2>
    • Type parameters

      • TRecord2: {} = any
      • TResult2: {} = any

      Parameters

      • callback: QueryCallbackWithArgs<TRecord, any>
      • rest...args: any[]

      Returns QueryBuilder<TRecord2, TResult2>

    off

    • off(eventName: string | symbol, listener: (...args: any[]) => void): Knex<TRecord, TResult>
    • Alias for emitter.removeListener().

      @since

      v10.0.0


      Parameters

      • eventName: string | symbol
      • listener: (...args: any[]) => void

        Returns Knex<TRecord, TResult>

      offset

      • offset(offset: number, options?: boolean | Readonly<{ skipBinding?: boolean }>): QueryBuilder<TRecord, TResult>
      • Parameters

        • offset: number
        • optionaloptions: boolean | Readonly<{ skipBinding?: boolean }>

        Returns QueryBuilder<TRecord, TResult>

      on

      • on(eventName: string | symbol, listener: (...args: any[]) => void): Knex<TRecord, TResult>
      • Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple times.

        server.on('connection', (stream) => {
        console.log('someone connected!');
        });

        Returns a reference to the EventEmitter, so that calls can be chained.

        By default, event listeners are invoked in the order they are added. Theemitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

        import { EventEmitter } from 'node:events';
        const myEE = new EventEmitter();
        myEE.on('foo', () => console.log('a'));
        myEE.prependListener('foo', () => console.log('b'));
        myEE.emit('foo');
        // Prints:
        // b
        // a
        @since

        v0.1.101


        Parameters

        • eventName: string | symbol

          The name of the event.

        • listener: (...args: any[]) => void

          The callback function

          Returns Knex<TRecord, TResult>

        onConflict

        • onConflict<TKey>(column: TKey): OnConflictQueryBuilder<TRecord, TResult>
        • onConflict<TKey>(columns: readonly TKey[]): OnConflictQueryBuilder<TRecord, TResult>
        • onConflict(columns: string): OnConflictQueryBuilder<TRecord, TResult>
        • onConflict(columns: string[]): OnConflictQueryBuilder<TRecord, TResult>
        • onConflict(raw: Raw<any>): OnConflictQueryBuilder<TRecord, TResult>
        • onConflict(): OnConflictQueryBuilder<TRecord, TResult>
        • Type parameters

          • TKey: string

          Parameters

          • column: TKey

          Returns OnConflictQueryBuilder<TRecord, TResult>

        once

        • once(eventName: string | symbol, listener: (...args: any[]) => void): Knex<TRecord, TResult>
        • Adds a one-timelistener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

          server.once('connection', (stream) => {
          console.log('Ah, we have our first user!');
          });

          Returns a reference to the EventEmitter, so that calls can be chained.

          By default, event listeners are invoked in the order they are added. Theemitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

          import { EventEmitter } from 'node:events';
          const myEE = new EventEmitter();
          myEE.once('foo', () => console.log('a'));
          myEE.prependOnceListener('foo', () => console.log('b'));
          myEE.emit('foo');
          // Prints:
          // b
          // a
          @since

          v0.3.0


          Parameters

          • eventName: string | symbol

            The name of the event.

          • listener: (...args: any[]) => void

            The callback function

            Returns Knex<TRecord, TResult>

          pluck

          • pluck<K>(column: K): QueryBuilder<TRecord, TRecord[K][]>
          • pluck<TResult2>(column: string): QueryBuilder<TRecord, TResult2>
          • Type parameters

            • K: string | number | symbol

            Parameters

            • column: K

            Returns QueryBuilder<TRecord, TRecord[K][]>

          prependListener

          • prependListener(eventName: string | symbol, listener: (...args: any[]) => void): Knex<TRecord, TResult>
          • Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple times.

            server.prependListener('connection', (stream) => {
            console.log('someone connected!');
            });

            Returns a reference to the EventEmitter, so that calls can be chained.

            @since

            v6.0.0


            Parameters

            • eventName: string | symbol

              The name of the event.

            • listener: (...args: any[]) => void

              The callback function

              Returns Knex<TRecord, TResult>

            prependOnceListener

            • prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): Knex<TRecord, TResult>
            • Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

              server.prependOnceListener('connection', (stream) => {
              console.log('Ah, we have our first user!');
              });

              Returns a reference to the EventEmitter, so that calls can be chained.

              @since

              v6.0.0


              Parameters

              • eventName: string | symbol

                The name of the event.

              • listener: (...args: any[]) => void

                The callback function

                Returns Knex<TRecord, TResult>

              queryBuilder

              • queryBuilder<TRecord2, TResult2>(): QueryBuilder<TRecord2, TResult2>
              • Type parameters

                • TRecord2: {} = TRecord
                • TResult2 = TResult

                Returns QueryBuilder<TRecord2, TResult2>

              rawListeners

              • rawListeners(eventName: string | symbol): Function[]
              • Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

                import { EventEmitter } from 'node:events';
                const emitter = new EventEmitter();
                emitter.once('log', () => console.log('log once'));

                // Returns a new Array with a function `onceWrapper` which has a property
                // `listener` which contains the original listener bound above
                const listeners = emitter.rawListeners('log');
                const logFnWrapper = listeners[0];

                // Logs "log once" to the console and does not unbind the `once` event
                logFnWrapper.listener();

                // Logs "log once" to the console and removes the listener
                logFnWrapper();

                emitter.on('log', () => console.log('log persistently'));
                // Will return a new Array with a single function bound by `.on()` above
                const newListeners = emitter.rawListeners('log');

                // Logs "log persistently" twice
                newListeners[0]();
                emitter.emit('log');
                @since

                v9.4.0


                Parameters

                • eventName: string | symbol

                Returns Function[]

              removeAllListeners

              • removeAllListeners(event?: string | symbol): Knex<TRecord, TResult>
              • Removes all listeners, or those of the specified eventName.

                It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

                Returns a reference to the EventEmitter, so that calls can be chained.

                @since

                v0.1.26


                Parameters

                • optionalevent: string | symbol

                Returns Knex<TRecord, TResult>

              removeListener

              • removeListener(eventName: string | symbol, listener: (...args: any[]) => void): Knex<TRecord, TResult>
              • Removes the specified listener from the listener array for the event namedeventName.

                const callback = (stream) => {
                console.log('someone connected!');
                };
                server.on('connection', callback);
                // ...
                server.removeListener('connection', callback);

                removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

                Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that anyremoveListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them fromemit() in progress. Subsequent events behave as expected.

                import { EventEmitter } from 'node:events';
                class MyEmitter extends EventEmitter {}
                const myEmitter = new MyEmitter();

                const callbackA = () => {
                console.log('A');
                myEmitter.removeListener('event', callbackB);
                };

                const callbackB = () => {
                console.log('B');
                };

                myEmitter.on('event', callbackA);

                myEmitter.on('event', callbackB);

                // callbackA removes listener callbackB but it will still be called.
                // Internal listener array at time of emit [callbackA, callbackB]
                myEmitter.emit('event');
                // Prints:
                // A
                // B

                // callbackB is now removed.
                // Internal listener array [callbackA]
                myEmitter.emit('event');
                // Prints:
                // A

                Because listeners are managed using an internal array, calling this will change the position indices of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

                When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping')listener is removed:

                import { EventEmitter } from 'node:events';
                const ee = new EventEmitter();

                function pong() {
                console.log('pong');
                }

                ee.on('ping', pong);
                ee.once('ping', pong);
                ee.removeListener('ping', pong);

                ee.emit('ping');
                ee.emit('ping');

                Returns a reference to the EventEmitter, so that calls can be chained.

                @since

                v0.1.26


                Parameters

                • eventName: string | symbol
                • listener: (...args: any[]) => void

                  Returns Knex<TRecord, TResult>

                returning

                • returning(column: *, options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>
                • returning<TKey, TResult2>(column: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • returning<TKey, TResult2>(columns: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • returning<TResult2>(column: string | Raw<any> | readonly (string | Raw<any>)[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • Parameters

                  • column: *
                  • optionaloptions: DMLOptions

                  Returns QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>

                setMaxListeners

                • setMaxListeners(n: number): Knex<TRecord, TResult>
                • By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set toInfinity (or 0) to indicate an unlimited number of listeners.

                  Returns a reference to the EventEmitter, so that calls can be chained.

                  @since

                  v0.3.5


                  Parameters

                  • n: number

                  Returns Knex<TRecord, TResult>

                transaction

                • transaction(config?: TransactionConfig): Promise<Transaction<any, any[]>>
                • transaction(transactionScope?: null, config?: TransactionConfig): Promise<Transaction<any, any[]>>
                • transaction<T>(transactionScope: (trx: Transaction<any, any[]>) => void | Promise<T>, config?: TransactionConfig): Promise<T>
                • Parameters

                  • optionalconfig: TransactionConfig

                  Returns Promise<Transaction<any, any[]>>

                transactionProvider

                • transactionProvider(config?: TransactionConfig): TransactionProvider
                • Parameters

                  • optionalconfig: TransactionConfig

                  Returns TransactionProvider

                truncate

                • truncate(): QueryBuilder<TRecord, void>
                • Returns QueryBuilder<TRecord, void>

                update

                • update<K1, K2, TResult2>(columnName: K1, value: DbColumn<ResolveTableType<TRecord, update>[K1]>, returning: K2, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update<K1, K2, TResult2>(columnName: K1, value: DbColumn<ResolveTableType<TRecord, update>[K1]>, returning: readonly K2[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update<K>(columnName: K, value: DbColumn<TRecord[K]>): QueryBuilder<TRecord, number>
                • update<TResult2>(columnName: string, value: Value, returning: string | readonly string[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update(data: DbRecordArr<TRecord>, returning: *, options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>
                • update<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, update> : DbRecordArr<TRecord>, returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, update> : DbRecordArr<TRecord>, returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, update> : DbRecordArr<TRecord>, returning: TKey | readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, update> : DbRecordArr<TRecord>, returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update<TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, update> : DbRecordArr<TRecord>): QueryBuilder<TRecord, TResult2>
                • update<TResult2>(columnName: string, value: Value): QueryBuilder<TRecord, TResult2>
                • Type parameters

                  • K1: string
                  • K2: string
                  • TResult2 = AddAliases<AddKey<SetBase<UnwrapArrayMember<TResult>, ResolveTableType<TRecord, base>>, K2>, {}>[]

                  Parameters

                  • columnName: K1
                  • value: DbColumn<ResolveTableType<TRecord, update>[K1]>
                  • returning: K2
                  • optionaloptions: DMLOptions

                  Returns QueryBuilder<TRecord, TResult2>

                upsert

                • upsert(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, upsert> | readonly ResolveTableType<TRecord, upsert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: *, options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>
                • upsert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, upsert> | readonly ResolveTableType<TRecord, upsert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • upsert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, upsert> | readonly ResolveTableType<TRecord, upsert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • upsert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, upsert> | readonly ResolveTableType<TRecord, upsert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • upsert<TKey, TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, upsert> | readonly ResolveTableType<TRecord, upsert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[], returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • upsert<TResult2>(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, upsert> | readonly ResolveTableType<TRecord, upsert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[]): QueryBuilder<TRecord, TResult2>
                • Parameters

                  • data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord, upsert> | readonly ResolveTableType<TRecord, upsert>[] : DbRecordArr<TRecord> | readonly DbRecordArr<TRecord>[]
                  • returning: *
                  • optionaloptions: DMLOptions

                  Returns QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>

                withUserParams

                • withUserParams(params: Record<string, any>): Knex<any, any[]>
                • Parameters

                  • params: Record<string, any>

                  Returns Knex<any, any[]>

                Page Options