Libraries v5.2.0
    Preparing search index...

    Type Alias DbContext<TMap>

    DbContext: { readonly [K in keyof TMap]: DbSet<TMap[K]> } & {
        knex: Knex;
        transaction<T>(
            callback: (db: DbContext<TMap>) => Promise<T>,
            options?: TransactionOptions,
        ): Promise<T>;
        withTransaction(trx: Transaction): DbContext<TMap>;
    }

    The shape of the context object returned by createDb: every registered entity becomes a typed DbSet property.

    Type Parameters

    Type Declaration

    • Readonlyknex: Knex

      The underlying Knex instance the context was constructed with.

    • transaction: function
      • Run callback inside a Knex transaction. The callback receives a new DbContext whose DbSets are bound to the transaction.

        Type Parameters

        • T

        Parameters

        Returns Promise<T>

    • withTransaction: function
      • Return a new DbContext whose DbSets are bound to trx. Useful when you already have a Knex transaction in scope.

        Parameters

        • trx: Transaction

        Returns DbContext<TMap>