Skip to content

KnexRepository

Defined in: knex-repository.ts:18

T extends Record<string, unknown>

D = Partial<T>

new KnexRepository<T, D>(app): KnexRepository<T, D>

Defined in: knex-repository.ts:42

MantleApplication

KnexRepository<T, D>

protected _trx: Transaction<any, any[]> | null = null

Defined in: knex-repository.ts:20


readonly columnCase: "camelCase" | "snake_case" = "camelCase"

Defined in: knex-repository.ts:35

Naming convention used to derive column names from entity field names. “camelCase” (default) uses entity field names verbatim as column names. “snake_case” converts every field automatically (userId -> user_id) so the entity/type can stay camelCase while the table uses snake_case columns.


readonly createdAtField: string = "createdAt"

Defined in: knex-repository.ts:26

Entity-side field written for auto-managed creation timestamps.

"createdAt"

readonly fieldMap: Record<string, string> = {}

Defined in: knex-repository.ts:40

Explicit entity-field-to-column overrides, applied before columnCase conversion. Use this for individual columns that don’t follow the table’s general convention.


readonly idField: string = "id"

Defined in: knex-repository.ts:23


protected readonly knex: Knex

Defined in: knex-repository.ts:19


abstract readonly tableName: string

Defined in: knex-repository.ts:22


readonly timestamps: boolean = true

Defined in: knex-repository.ts:24


readonly updatedAtField: string = "updatedAt"

Defined in: knex-repository.ts:28

Entity-side field written for auto-managed update timestamps.

"updatedAt"

get db(): QueryBuilder

Defined in: knex-repository.ts:47

Raw query builder for this table, respecting any active transaction.

QueryBuilder


get protected qb(): Knex<any, any[]> | Transaction<any, any[]>

Defined in: knex-repository.ts:79

Knex<any, any[]> | Transaction<any, any[]>

protected buildQuery(params?): QueryBuilder

Defined in: knex-repository.ts:94

QueryParams

QueryBuilder


count(params?): Promise<number>

Defined in: knex-repository.ts:297

QueryParams

Promise<number>

Repository.count


deleteById(id): Promise<T>

Defined in: knex-repository.ts:272

Id

Promise<T>

Repository.deleteById


describe(): RepositoryCapabilities

Defined in: knex-repository.ts:51

Optional capability introspection. All

RepositoryCapabilities

adapters implement it; user repositories may omit it.

Repository.describe


findAll(params?): Promise<T[]>

Defined in: knex-repository.ts:152

QueryParams

Promise<T[]>

Repository.findAll


findById(id): Promise<T | null>

Defined in: knex-repository.ts:164

Id

Promise<T | null>

Repository.findById


protected mapDataToColumns(data): Record<string, unknown>

Defined in: knex-repository.ts:130

Renames the keys of a data payload from entity field names to column names.

Record<string, unknown>

Record<string, unknown>


protected mapRowToEntity(row): T

Defined in: knex-repository.ts:135

Renames the keys of a returned row from column names to entity field names.

Record<string, unknown>

T


patchById(id, data): Promise<T>

Defined in: knex-repository.ts:243

Id

D

Promise<T>

Repository.patchById


save(data): Promise<T>

Defined in: knex-repository.ts:175

D

Promise<T>

Repository.save


saveAll(data): Promise<T[]>

Defined in: knex-repository.ts:192

D[]

Promise<T[]>

Repository.saveAll


protected toColumn(field): string

Defined in: knex-repository.ts:117

Translates an entity field name to its column name (fieldMap override, then columnCase convention).

string

string


protected toEntityField(column): string

Defined in: knex-repository.ts:123

Translates a column name back to its entity field name — the inverse of toColumn.

string

string


updateById(id, data): Promise<T>

Defined in: knex-repository.ts:217

Id

D

Promise<T>

Repository.updateById


withTransaction<R>(callback): Promise<R>

Defined in: knex-repository.ts:69

Run a set of repository operations inside a single database transaction. The callback receives a transaction-scoped copy of this repository.

R

(repo) => Promise<R>

Promise<R>


protected wrapError(err): Error

Defined in: knex-repository.ts:313

unknown

Error