Skip to main content
Version: 6.4

Knex <TRecord, TResult>

Hierarchy

  • QueryInterface<TRecord, TResult>
  • EventEmitter
    • Knex

Callable

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

  • Parameters

    • tableName: TTable
    • optionaloptions: PgTableOptions

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

Index

Properties

Methods

Properties

__knex__

__knex__: string

inheritedandHaving

andHaving: Having<TRecord, TResult>

inheritedandHavingNotIn

andHavingNotIn: HavingRange<TRecord, TResult>

inheritedandWhere

andWhere: Where<TRecord, TResult>

inheritedandWhereBetween

andWhereBetween: WhereBetween<TRecord, TResult>

inheritedandWhereILike

andWhereILike: Where<TRecord, TResult>

inheritedandWhereJsonNotSubsetOf

andWhereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>

inheritedandWhereJsonNotSupersetOf

andWhereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>

inheritedandWhereJsonObject

andWhereJsonObject: WhereJsonObject<TRecord, TResult>

inheritedandWhereJsonPath

andWhereJsonPath: WhereJsonPath<TRecord, TResult>

inheritedandWhereJsonSubsetOf

andWhereJsonSubsetOf: WhereJsonObject<TRecord, TResult>

inheritedandWhereJsonSupersetOf

andWhereJsonSupersetOf: WhereJsonObject<TRecord, TResult>

inheritedandWhereLike

andWhereLike: Where<TRecord, TResult>

inheritedandWhereNot

andWhereNot: Where<TRecord, TResult>

inheritedandWhereNotBetween

andWhereNotBetween: WhereBetween<TRecord, TResult>

inheritedandWhereNotJsonObject

andWhereNotJsonObject: WhereJsonObject<TRecord, TResult>

inheritedandWhereRaw

andWhereRaw: WhereRaw<TRecord, TResult>

inheritedas

as: As<TRecord, TResult>

inheritedavg

avg: TypePreservingAggregation<TRecord, TResult, any>

inheritedavgDistinct

avgDistinct: TypePreservingAggregation<TRecord, TResult, any>

client

client: any

inheritedcolumn

column: Select<TRecord, TResult>

inheritedcolumns

columns: Select<TRecord, TResult>

inheritedcomment

comment: Comment<TRecord, TResult>

inheritedcount

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

inheritedcountDistinct

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

inheritedcrossJoin

crossJoin: Join<TRecord, TResult>

inheriteddenseRank

denseRank: AnalyticFunction<TRecord, TResult>

inheriteddistinct

distinct: Distinct<TRecord, TResult>

inheriteddistinctOn

distinctOn: DistinctOn<TRecord, TResult>

inheritedexcept

except: Except<TRecord, TResult>

inheritedfirst

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

fn

fn: FunctionHelper

inheritedfrom

from: Table<TRecord, TResult>

inheritedfromRaw

fromRaw: Table<TRecord, TResult>

inheritedfullOuterJoin

fullOuterJoin: Join<TRecord, TResult>

inheritedgroupBy

groupBy: GroupBy<TRecord, TResult>

inheritedgroupByRaw

groupByRaw: RawQueryBuilder<TRecord, TResult>

inheritedhaving

having: Having<TRecord, TResult>

inheritedhavingBetween

havingBetween: HavingRange<TRecord, TResult>

inheritedhavingIn

havingIn: HavingRange<TRecord, TResult>

inheritedhavingNotBetween

havingNotBetween: HavingRange<TRecord, TResult>

inheritedhavingNotIn

havingNotIn: HavingRange<TRecord, TResult>

inheritedhavingNotNull

havingNotNull: HavingNull<TRecord, TResult>

inheritedhavingNull

havingNull: HavingNull<TRecord, TResult>

inheritedhavingRaw

havingRaw: RawQueryBuilder<TRecord, TResult>

inheritedhavingWrapped

havingWrapped: WhereWrapped<TRecord, TResult>

inheritedhintComment

hintComment: HintComment<TRecord, TResult>

inheritedinnerJoin

innerJoin: Join<TRecord, TResult>

inheritedintersect

intersect: Intersect<TRecord, TResult>

inheritedinto

into: Table<TRecord, TResult>

optionalisTransaction

isTransaction?: boolean

inheritedjoin

join: Join<TRecord, TResult>

inheritedjoinRaw

joinRaw: JoinRaw<TRecord, TResult>

inheritedjsonExtract

jsonExtract: JsonExtract<TRecord, TResult>

inheritedjsonInsert

jsonInsert: JsonInsert<TRecord, TResult>

inheritedjsonRemove

jsonRemove: JsonRemove<TRecord, TResult>

inheritedjsonSet

jsonSet: JsonSet<TRecord, TResult>

inheritedleftJoin

leftJoin: Join<TRecord, TResult>

inheritedleftOuterJoin

leftOuterJoin: Join<TRecord, TResult>

inheritedmax

max: TypePreservingAggregation<TRecord, TResult, any>

migrate

migrate: Migrator

inheritedmin

min: TypePreservingAggregation<TRecord, TResult, any>

inheritedorderBy

orderBy: OrderBy<TRecord, TResult>

inheritedorderByRaw

orderByRaw: RawQueryBuilder<TRecord, TResult>

inheritedorHaving

orHaving: Having<TRecord, TResult>

inheritedorHavingBetween

orHavingBetween: HavingRange<TRecord, TResult>

inheritedorHavingNotBetween

orHavingNotBetween: HavingRange<TRecord, TResult>

inheritedorHavingNotIn

orHavingNotIn: HavingRange<TRecord, TResult>

inheritedorHavingNotNull

orHavingNotNull: HavingNull<TRecord, TResult>

inheritedorHavingNull

orHavingNull: HavingNull<TRecord, TResult>

inheritedorHavingRaw

orHavingRaw: RawQueryBuilder<TRecord, TResult>

inheritedorWhere

orWhere: Where<TRecord, TResult>

inheritedorWhereBetween

orWhereBetween: WhereBetween<TRecord, TResult>

inheritedorWhereExists

orWhereExists: WhereExists<TRecord, TResult>

inheritedorWhereILike

orWhereILike: Where<TRecord, TResult>

inheritedorWhereIn

orWhereIn: WhereIn<TRecord, TResult>

inheritedorWhereJsonNotSubsetOf

orWhereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>

inheritedorWhereJsonNotSupersetOf

orWhereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>

inheritedorWhereJsonObject

orWhereJsonObject: WhereJsonObject<TRecord, TResult>

inheritedorWhereJsonPath

orWhereJsonPath: WhereJsonPath<TRecord, TResult>

inheritedorWhereJsonSubsetOf

orWhereJsonSubsetOf: WhereJsonObject<TRecord, TResult>

inheritedorWhereJsonSupersetOf

orWhereJsonSupersetOf: WhereJsonObject<TRecord, TResult>

inheritedorWhereLike

orWhereLike: Where<TRecord, TResult>

inheritedorWhereNot

orWhereNot: Where<TRecord, TResult>

inheritedorWhereNotBetween

orWhereNotBetween: WhereBetween<TRecord, TResult>

inheritedorWhereNotExists

orWhereNotExists: WhereExists<TRecord, TResult>

inheritedorWhereNotIn

orWhereNotIn: WhereIn<TRecord, TResult>

inheritedorWhereNotJsonObject

orWhereNotJsonObject: WhereJsonObject<TRecord, TResult>

inheritedorWhereNotNull

orWhereNotNull: WhereNull<TRecord, TResult>

inheritedorWhereNull

orWhereNull: WhereNull<TRecord, TResult>

inheritedorWhereRaw

orWhereRaw: WhereRaw<TRecord, TResult>

inheritedouterJoin

outerJoin: Join<TRecord, TResult>

inheritedpartitionBy

partitionBy: PartitionBy<TRecord, TResult>

inheritedrank

rank: AnalyticFunction<TRecord, TResult>

raw

raw: RawBuilder<TRecord, any>

ref

ref: RefBuilder

inheritedrightJoin

rightJoin: Join<TRecord, TResult>

inheritedrightOuterJoin

rightOuterJoin: Join<TRecord, TResult>

inheritedrowNumber

rowNumber: AnalyticFunction<TRecord, TResult>

schema

schema: SchemaBuilder

seed

seed: Seeder

inheritedselect

select: Select<TRecord, TResult>

inheritedsum

sum: TypePreservingAggregation<TRecord, TResult, any>

inheritedsumDistinct

sumDistinct: TypePreservingAggregation<TRecord, TResult, any>

inheritedtable

table: Table<TRecord, TResult>

inheritedunion

union: Union<TRecord, TResult>

inheritedunionAll

unionAll: Union<TRecord, TResult>

inheritedupdateFrom

updateFrom: Table<TRecord, TResult>

userParams

userParams: Record<string, any>

inheritedusing

using: Using<TRecord, TResult>

VERSION

VERSION: string

inheritedwhere

where: Where<TRecord, TResult>

inheritedwhereBetween

whereBetween: WhereBetween<TRecord, TResult>

inheritedwhereExists

whereExists: WhereExists<TRecord, TResult>

inheritedwhereILike

whereILike: Where<TRecord, TResult>

inheritedwhereIn

whereIn: WhereIn<TRecord, TResult>

inheritedwhereJsonNotSubsetOf

whereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>

inheritedwhereJsonNotSupersetOf

whereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>

inheritedwhereJsonObject

whereJsonObject: WhereJsonObject<TRecord, TResult>

inheritedwhereJsonPath

whereJsonPath: WhereJsonPath<TRecord, TResult>

inheritedwhereJsonSubsetOf

whereJsonSubsetOf: WhereJsonObject<TRecord, TResult>

inheritedwhereJsonSupersetOf

whereJsonSupersetOf: WhereJsonObject<TRecord, TResult>

inheritedwhereLike

whereLike: Where<TRecord, TResult>

inheritedwhereNot

whereNot: Where<TRecord, TResult>

inheritedwhereNotBetween

whereNotBetween: WhereBetween<TRecord, TResult>

inheritedwhereNotExists

whereNotExists: WhereExists<TRecord, TResult>

inheritedwhereNotIn

whereNotIn: WhereIn<TRecord, TResult>

inheritedwhereNotJsonObject

whereNotJsonObject: WhereJsonObject<TRecord, TResult>

inheritedwhereNotNull

whereNotNull: WhereNull<TRecord, TResult>

inheritedwhereNull

whereNull: WhereNull<TRecord, TResult>

inheritedwhereRaw

whereRaw: WhereRaw<TRecord, TResult>

inheritedwhereWrapped

whereWrapped: WhereWrapped<TRecord, TResult>

inheritedwith

with: With<TRecord, TResult>

inheritedwithMaterialized

withMaterialized: With<TRecord, TResult>

inheritedwithNotMaterialized

withNotMaterialized: With<TRecord, TResult>

inheritedwithRaw

withRaw: WithRaw<TRecord, TResult>

inheritedwithRecursive

withRecursive: With<TRecord, TResult>

inheritedwithSchema

withSchema: WithSchema<TRecord, TResult>

inheritedwithWrapped

withWrapped: WithWrapped<TRecord, TResult>

Methods

optionalinherited[captureRejectionSymbol]

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

    • error: Error
    • event: string | symbol
    • rest...args: AnyRest

    Returns void

inheritedaddListener

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

    @since

    v0.1.26


    Parameters

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

      Returns this

    batchInsert

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

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

      Returns BatchInsertBuilder<TRecord2, TResult2>

    inheritedclear

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

      • statement: ClearStatements

      Returns QueryBuilder<TRecord, TResult>

    inheritedclearCounters

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

    inheritedclearGroup

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

    inheritedclearHaving

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

    inheritedclearOrder

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

    inheritedclearSelect

    • 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>

    inheritedclearWhere

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

    inheriteddecrement

    • 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>

    inheriteddel

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

      • returning: *
      • optionaloptions: DMLOptions

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

    inheriteddelete

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

    inheritedemit

    • emit(eventName: string | symbol, ...args: AnyRest): boolean
    • Synchronously calls each of the listeners registered for the event named eventName, 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: AnyRest

      Returns boolean

    inheritedeventNames

    • 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)[]

    inheritedgetMaxListeners

    • 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

    inheritedincrement

    • 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

    inheritedinsert

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

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

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

    inheritedlimit

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

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

      Returns QueryBuilder<TRecord, TResult>

    inheritedlistenerCount

    • 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

    inheritedlisteners

    • 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[]

    inheritedmodify

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

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

      Returns QueryBuilder<TRecord2, TResult2>

    inheritedoff

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

      @since

      v10.0.0


      Parameters

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

        Returns this

      inheritedoffset

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

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

        Returns QueryBuilder<TRecord, TResult>

      inheritedon

      • on(eventName: string | symbol, listener: (...args: any[]) => void): this
      • 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 eventName and 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. The emitter.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 this

        inheritedonce

        • once(eventName: string | symbol, listener: (...args: any[]) => void): this
        • Adds a one-time listener 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. The emitter.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 this

          inheritedonConflict

          • onConflict(column: TKey): OnConflictQueryBuilder<TRecord, TResult>
          • onConflict(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>
          • Parameters

            • column: TKey

            Returns OnConflictQueryBuilder<TRecord, TResult>

          inheritedpluck

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

            • column: K

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

          inheritedprependListener

          • prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this
          • 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 eventName and 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 this

            inheritedprependOnceListener

            • prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this
            • 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 this

              queryBuilder

              • queryBuilder(): QueryBuilder<TRecord2, TResult2>
              • Returns QueryBuilder<TRecord2, TResult2>

              inheritedrawListeners

              • 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[]

              inheritedremoveAllListeners

              • removeAllListeners(eventName?: string | symbol): this
              • 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

                • optionaleventName: string | symbol

                Returns this

              inheritedremoveListener

              • removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this
              • Removes the specified listener from the listener array for the event named eventName.

                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 any removeListener() 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 this

                inheritedreturning

                • returning(column: *, options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never, false, {}, false, {}, never>[]>
                • returning(column: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • returning(columns: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • returning(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>[]>

                inheritedsetMaxListeners

                • setMaxListeners(n: number): this
                • 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 to Infinity (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 this

                transaction

                • transaction(config?: TransactionConfig): Promise<Transaction<any, any[]>>
                • transaction(transactionScope?: null, config?: TransactionConfig): Promise<Transaction<any, any[]>>
                • transaction(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

                inheritedtruncate

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

                inheritedupdate

                • update(columnName: K1, value: DbColumn<ResolveTableType<TRecord, update>[K1]>, returning: K2, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update(columnName: K1, value: DbColumn<ResolveTableType<TRecord, update>[K1]>, returning: readonly K2[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update(columnName: K, value: DbColumn<TRecord[K]>): QueryBuilder<TRecord, number>
                • update(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(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord<TRecord>, update> : DbRecordArr<TRecord>, returning: TKey, options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord<TRecord>, update> : DbRecordArr<TRecord>, returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord<TRecord>, update> : DbRecordArr<TRecord>, returning: TKey | readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord<TRecord>, update> : DbRecordArr<TRecord>, returning: readonly TKey[], options?: DMLOptions): QueryBuilder<TRecord, TResult2>
                • update(data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord<TRecord>, update> : DbRecordArr<TRecord>): QueryBuilder<TRecord, TResult2>
                • update(columnName: string, value: Value): QueryBuilder<TRecord, TResult2>
                • Parameters

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

                  Returns QueryBuilder<TRecord, TResult2>

                inheritedupsert

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

                  • data: TRecord extends CompositeTableType<unknown, unknown, Partial<unknown>, Partial<unknown>> ? ResolveTableType<TRecord<TRecord>, upsert> | readonly ResolveTableType<TRecord<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