Libraries
    Preparing search index...

    Interface DbSet<TEntity>

    Typed query starter for a registered entity. Structurally it behaves like a fresh EntityQuery — every method invocation allocates a new underlying SchemaQueryBuilder so chains stay isolated.

    Additional members beyond EntityQuery:

    • entity — the wrapped Entity definition.
    • query() — explicit factory for a fresh EntityQuery (rarely needed).
    • withTransaction(trx) — return a new DbSet bound to a transaction.
    interface DbSet<TEntity extends Entity<any, any, any>> {
        entity: TEntity;
        andWhere(
            column: ColumnRef<EntitySchema<TEntity>>,
            operator: string,
            value: any,
        ): this;
        andWhere(column: ColumnRef<EntitySchema<TEntity>>, value: any): this;
        andWhere(record: Record<string, any>): this;
        andWhere(callback: (builder: QueryBuilder) => void): this;
        andWhere(raw: Raw): this;
        apply(fn: (builder: QueryBuilder) => void): this;
        avg(column: Raw<any> | ColumnRef<EntitySchema<TEntity>>): this;
        bulkInsert(
            rows: InferType<
                ReturnType<EntitySchema<TEntity>["makeAllPropsOptional"]>,
            >[],
            opts?: {
                chunkSize?: number;
                conflictColumns?: ColumnRef<EntitySchema<TEntity>>[];
                onConflict?: "ignore" | "merge";
            },
        ): Promise<EntityResult<TEntity>[]>;
        bulkUpdate(
            updates: readonly {
                set: Partial<InferType<TLocalSchema>>;
                where: Partial<InferType<TLocalSchema>>;
            }[],
        ): Promise<number>;
        bulkUpsert(
            rows: InferType<
                ReturnType<EntitySchema<TEntity>["makeAllPropsOptional"]>,
            >[],
            opts: {
                chunkSize?: number;
                conflictColumns: ColumnRef<EntitySchema<TEntity>>[];
            },
        ): Promise<EntityResult<TEntity>[]>;
        count(column?: Raw<any> | ColumnRef<EntitySchema<TEntity>>): this;
        countDistinct(column?: Raw<any> | ColumnRef<EntitySchema<TEntity>>): this;
        delete(): Promise<number>;
        distinct(...columns: (Raw<any> | ColumnRef<EntitySchema<TEntity>>)[]): this;
        execute(): Promise<EntityResult<TEntity>[]>;
        find(
            pk: PrimaryKeyValueOf<EntitySchema<TEntity>>,
        ): Promise<EntityResult<TEntity> | undefined>;
        findMany(
            pks: readonly PrimaryKeyValueOf<EntitySchema<TEntity>>[],
        ): Promise<EntityResult<TEntity>[]>;
        findOrFail(
            pk: PrimaryKeyValueOf<EntitySchema<TEntity>>,
        ): Promise<EntityResult<TEntity>>;
        first(): Promise<EntityResult<TEntity> | undefined>;
        groupBy(...columns: (Raw<any> | ColumnRef<EntitySchema<TEntity>>)[]): this;
        groupByRaw(sql: string, ...bindings: any[]): this;
        hardDelete(): Promise<number>;
        having(
            column: Raw<any> | ColumnRef<EntitySchema<TEntity>>,
            operator: string,
            value: any,
        ): this;
        havingRaw(sql: string, ...bindings: any[]): this;
        include<K extends string>(
            sel: (t: RelKeyTree<TEntity>) => K,
            customize?: (q: SchemaQueryBuilder<any, any>) => void,
        ): EntityQuery<TEntity, WithIncluded<TEntity, EntityResult<TEntity>, K>>;
        includeVariant<TVariant extends string, TRel extends string>(
            variantKey: TVariant,
            relationName: TRel,
            customize?: (q: SchemaQueryBuilder<any, any>) => void,
        ): EntityQuery<
            TEntity,
            TRel extends keyof EntityRelations<TEntity> & string
                ? WithVariantIncluded<TEntity, EntityResult<TEntity>, TVariant, TRel>
                : EntityResult<TEntity>,
        >;
        insert(
            data: InferType<
                ReturnType<EntitySchema<TEntity>["makeAllPropsOptional"]>,
            >,
        ): Promise<EntityResult<TEntity>>;
        insertMany(
            data: InferType<
                ReturnType<EntitySchema<TEntity>["makeAllPropsOptional"]>,
            >[],
        ): Promise<EntityResult<TEntity>[]>;
        joinMany<
            TForeignSchema extends
                ObjectSchemaBuilder<any, any, any, any, any, any, any>,
            TFieldName extends string,
        >(
            spec: JoinManySpec<EntitySchema<TEntity>, TForeignSchema, TFieldName>,
        ): SchemaQueryBuilder<
            EntitySchema<TEntity>,
            WithJoinedMany<EntityResult<TEntity>, TFieldName, TForeignSchema>,
        >;
        joinOne<
            TForeignSchema extends
                ObjectSchemaBuilder<any, any, any, any, any, any, any>,
            TFieldName extends string,
            TRequired extends boolean = true,
        >(
            spec: JoinOneSpec<
                EntitySchema<TEntity>,
                TForeignSchema,
                TFieldName,
                TRequired,
            >,
        ): SchemaQueryBuilder<
            EntitySchema<TEntity>,
            WithJoinedOne<
                EntityResult<TEntity>,
                TFieldName,
                TForeignSchema,
                TRequired,
            >,
        >;
        limit(n: number): this;
        max(column: Raw<any> | ColumnRef<EntitySchema<TEntity>>): this;
        min(column: Raw<any> | ColumnRef<EntitySchema<TEntity>>): this;
        offset(n: number): this;
        ofVariant<K extends string>(variantKey: K): VariantDbSet<TEntity, K>;
        onConflict(
            ...conflictColumns: ColumnRef<EntitySchema<TEntity>>[],
        ): OnConflictBuilder<EntitySchema<TEntity>, EntityResult<TEntity>>;
        onlyDeleted(): this;
        orderBy(
            column: Raw<any> | ColumnRef<EntitySchema<TEntity>>,
            direction?: "asc" | "desc",
        ): this;
        orderByRaw(sql: string, ...bindings: any[]): this;
        orWhere(
            column: ColumnRef<EntitySchema<TEntity>>,
            operator: string,
            value: any,
        ): this;
        orWhere(column: ColumnRef<EntitySchema<TEntity>>, value: any): this;
        orWhere(record: Record<string, any>): this;
        orWhere(callback: (builder: QueryBuilder) => void): this;
        orWhere(raw: Raw): this;
        orWhereIn(
            column: ColumnRef<EntitySchema<TEntity>>,
            values: readonly any[] | QueryBuilder<any, any>,
        ): this;
        orWhereNotIn(
            column: ColumnRef<EntitySchema<TEntity>>,
            values: readonly any[] | QueryBuilder<any, any>,
        ): this;
        orWhereNotNull(column: ColumnRef<EntitySchema<TEntity>>): this;
        orWhereNull(column: ColumnRef<EntitySchema<TEntity>>): this;
        paginate(
            opts: { page: number; pageSize: number },
        ): Promise<PaginationResult<EntityResult<TEntity>>>;
        paginateAfter(
            opts: {
                column?: ColumnRef<EntitySchema<TEntity>>;
                cursor?: any;
                direction?: "asc" | "desc";
                limit: number;
            },
        ): Promise<CursorPaginationResult<EntityResult<TEntity>>>;
        pluck<K extends string>(
            column: ColumnRef<EntitySchema<TEntity>>,
        ): Promise<EntityResult<TEntity>[K][]>;
        projected<K extends string>(
            name: K,
        ): SchemaQueryBuilder<
            EntitySchema<TEntity>,
            Pick<
                EntityResult<TEntity>,
                ProjectionKeysOf<EntitySchema<TEntity>, K> & keyof EntityResult<TEntity>,
            >,
        >;
        query(): EntityQuery<TEntity, EntityResult<TEntity>>;
        restore(): Promise<EntityResult<TEntity>[]>;
        save(graph: SaveGraph<TEntity>): Promise<EntityResult<TEntity>>;
        scoped<K extends never>(name: K): this;
        select(...columns: (Raw<any> | ColumnRef<EntitySchema<TEntity>>)[]): this;
        select<TSel extends SelectSelector<EntitySchema<TEntity>>>(
            selector: TSel,
        ): SchemaQueryBuilder<
            EntitySchema<TEntity>,
            SelectProjection<ReturnType<TSel>>,
        >;
        selectRaw(sql: string, bindings?: any[]): this;
        selectVariants(keys: string[]): this;
        sum(column: Raw<any> | ColumnRef<EntitySchema<TEntity>>): this;
        then<TReturn1 = EntityResult<TEntity>[], TReturn2 = never>(
            onfulfilled?:
                | (
                    (value: EntityResult<TEntity>[]) => TReturn1 | PromiseLike<TReturn1>
                )
                | null,
            onrejected?: ((reason: any) => TReturn2 | PromiseLike<TReturn2>) | null,
        ): Promise<TReturn1 | TReturn2>;
        toKnexQuery(): QueryBuilder;
        toQuery(): string;
        toString(): string;
        transacting(
            trx: Transaction,
        ): SchemaQueryBuilder<EntitySchema<TEntity>, EntityResult<TEntity>>;
        unscoped(): this;
        update(
            data: Partial<InferType<TLocalSchema>>,
        ): Promise<EntityResult<TEntity>[]>;
        upsert(
            data: InferType<
                ReturnType<EntitySchema<TEntity>["makeAllPropsOptional"]>,
            >,
            opts: {
                conflictColumns: ColumnRef<EntitySchema<TEntity>>[];
                updateColumns?: ColumnRef<EntitySchema<TEntity>>[];
            },
        ): Promise<EntityResult<TEntity>>;
        where(
            column: ColumnRef<EntitySchema<TEntity>>,
            operator: string,
            value: any,
        ): this;
        where(column: ColumnRef<EntitySchema<TEntity>>, value: any): this;
        where(raw: Raw, operator: string, value: any): this;
        where(callback: (builder: QueryBuilder) => void): this;
        where(record: Record<string, any>): this;
        where(raw: Raw): this;
        whereBetween(
            column: ColumnRef<EntitySchema<TEntity>>,
            range: readonly [any, any],
        ): this;
        whereExists(
            callback: QueryBuilder<any, any> | QueryCallback<any, unknown[]>,
        ): this;
        whereILike(column: ColumnRef<EntitySchema<TEntity>>, value: string): this;
        whereIn(
            column: ColumnRef<EntitySchema<TEntity>>,
            values: readonly any[] | QueryBuilder<any, any>,
        ): this;
        whereJsonPath(
            column: ColumnRef<EntitySchema<TEntity>>,
            path: string,
            operator?: string,
            value?: any,
        ): this;
        whereLike(column: ColumnRef<EntitySchema<TEntity>>, value: string): this;
        whereNot(
            column: ColumnRef<EntitySchema<TEntity>>,
            operator: string,
            value: any,
        ): this;
        whereNot(column: ColumnRef<EntitySchema<TEntity>>, value: any): this;
        whereNot(record: Record<string, any>): this;
        whereNot(callback: (builder: QueryBuilder) => void): this;
        whereNot(raw: Raw): this;
        whereNotBetween(
            column: ColumnRef<EntitySchema<TEntity>>,
            range: readonly [any, any],
        ): this;
        whereNotExists(
            callback: QueryBuilder<any, any> | QueryCallback<any, unknown[]>,
        ): this;
        whereNotIn(
            column: ColumnRef<EntitySchema<TEntity>>,
            values: readonly any[] | QueryBuilder<any, any>,
        ): this;
        whereNotNull(column: ColumnRef<EntitySchema<TEntity>>): this;
        whereNull(column: ColumnRef<EntitySchema<TEntity>>): this;
        whereRaw(sql: string, ...bindings: any[]): this;
        whereVariant(
            key: string,
            column: string,
            operator: string,
            value: any,
        ): this;
        withDeleted(): this;
        withTransaction(trx: Transaction): DbSet<TEntity>;
    }

    Type Parameters

    • TEntity extends Entity<any, any, any>

    Hierarchy (View Summary)

    Index

    Properties

    entity: TEntity

    The wrapped entity definition.

    Methods

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Parameters

      • record: Record<string, any>

      Returns this

    • Parameters

      • callback: (builder: QueryBuilder) => void

      Returns this

    • Parameters

      • raw: Raw

      Returns this

    • Parameters

      • fn: (builder: QueryBuilder) => void

      Returns this

    • Parameters

      Returns Promise<number>

    • Returns Promise<number>

    • Parameters

      • sql: string
      • ...bindings: any[]

      Returns this

    • Returns Promise<number>

    • Parameters

      • sql: string
      • ...bindings: any[]

      Returns this

    • Parameters

      • n: number

      Returns this

    • Parameters

      • n: number

      Returns this

    • Return a typed variant view pre-filtered to variantKey.

      Behaves like EF Core's Set<DerivedType>(): all reads automatically filter by the discriminator value, and insert / update / delete apply the correct single-table (STI) or two-table (CTI) logic.

      const assigned = db.activities.ofVariant('assigned');

      // Insert a new variant row (discriminator set automatically):
      await assigned.insert({ todoId: 42, userId: 7, assigneeId: 9 });

      // Update variant-specific columns for matching rows:
      await assigned.where(t => t.id, activityId).update({ assigneeId: 10 });

      // Delete variant rows (CTI: variant table first, then base):
      await assigned.where(t => t.id, activityId).delete();

      // Find by PK (result is narrowed to the variant branch):
      const a = await assigned.find(activityId);
      // a.type === 'assigned' and a.assigneeId is available

      Type Parameters

      • K extends string

      Parameters

      • variantKey: K

      Returns VariantDbSet<TEntity, K>

    • Returns this

    • Parameters

      • sql: string
      • ...bindings: any[]

      Returns this

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Parameters

      • record: Record<string, any>

      Returns this

    • Parameters

      • callback: (builder: QueryBuilder) => void

      Returns this

    • Parameters

      • raw: Raw

      Returns this

    • Persist a nested write graph (root + related entities) in a single transaction. Each node is INSERTed when its primary-key fields are absent and UPDATEd when they are present (composite-PK aware).

      Topology:

      • belongsTo parents are saved first; their PKs feed the root's FK.
      • The root row is then written.
      • hasOne / hasMany / belongsToMany children inherit the root's PK into their FK column.
      • belongsToMany children may be passed as full nested graphs (new rows) or as { pk: value } references (link existing rows).

      If called inside an existing transaction (via withTransaction), the outer transaction is reused; otherwise a fresh one is opened and automatically rolled back on failure.

      Parameters

      Returns Promise<EntityResult<TEntity>>

    • Type Parameters

      • K extends never

      Parameters

      • name: K

      Returns this

    • Parameters

      • sql: string
      • Optionalbindings: any[]

      Returns this

    • Parameters

      • keys: string[]

      Returns this

    • Returns QueryBuilder

    • Returns string

    • Returns string

    • Returns this

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Parameters

      • raw: Raw
      • operator: string
      • value: any

      Returns this

    • Parameters

      • callback: (builder: QueryBuilder) => void

      Returns this

    • Parameters

      • record: Record<string, any>

      Returns this

    • Parameters

      • raw: Raw

      Returns this

    • Parameters

      • callback: QueryBuilder<any, any> | QueryCallback<any, unknown[]>

      Returns this

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Parameters

      • record: Record<string, any>

      Returns this

    • Parameters

      • callback: (builder: QueryBuilder) => void

      Returns this

    • Parameters

      • raw: Raw

      Returns this

    • Parameters

      • callback: QueryBuilder<any, any> | QueryCallback<any, unknown[]>

      Returns this

    • Parameters

      • sql: string
      • ...bindings: any[]

      Returns this

    • Parameters

      • key: string
      • column: string
      • operator: string
      • value: any

      Returns this

    • Returns this