import { type CursorPaginatedResult, type PaginatedResult } from "../pagination/index.ts"; import { type BelongsToManyRelation, type BelongsToRelation, type HasManyRelation, type HasManyThroughRelation, type MorphManyRelation, type MorphOneRelation, type MorphToRelation } from "./relationships.ts"; import { RepositoryQuery } from "./repositoryQuery.ts"; import type { TableDefinition } from "./table.ts"; import type { MutationValues, QueryOptions, QueryWhere, UpdateValues } from "./types.ts"; import type { WhereNode } from "./whereBuilder.ts"; type ExtendedQueryOptions = QueryOptions & { whereNodes?: WhereNode[]; }; interface DatabaseConnection { unsafe(query: string, params?: readonly unknown[]): Promise; begin?(callback: (transaction: DatabaseConnection) => Promise): Promise; /** SQLite closes synchronously; pooled drivers return a promise. */ close?(): void | Promise; } interface SqlDatabaseConnection extends DatabaseConnection { (strings: TemplateStringsArray, ...values: unknown[]): Promise; } type ErrorFactory = (value: TValue) => Error; declare class BaseRepository { protected readonly table: TableDefinition; protected readonly connection: DatabaseConnection; constructor(table: TableDefinition, connection?: DatabaseConnection); count(options?: ExtendedQueryOptions): Promise; findAll(options?: ExtendedQueryOptions): Promise; paginate(options: { page: number; perPage: number; } & Omit, "limit" | "offset">): Promise>; chunk(count: number, callback: (rows: TEntity[]) => Promise, options?: Omit, "limit" | "offset">): Promise; chunkById(count: number, callback: (rows: TEntity[]) => Promise, options?: Omit, "limit" | "offset" | "orderBy">): Promise; cursorPaginate(options: { perPage: number; cursor?: TEntity[PrimaryKey]; cursorColumn?: PrimaryKey; direction?: "asc" | "desc"; } & Omit, "limit" | "offset">): Promise>; findById(id: TEntity[PrimaryKey]): Promise; findByIdOrThrow(id: TEntity[PrimaryKey], errorFactory?: ErrorFactory): Promise; findByIds(ids: readonly TEntity[PrimaryKey][]): Promise; firstOrNull(where: QueryWhere, options?: Omit, "where" | "limit">): Promise; upsert(values: MutationValues, conflictColumns: readonly (keyof TEntity & string)[], updateColumns?: readonly (keyof TEntity & string)[]): Promise; incrementById(id: TEntity[PrimaryKey], column: keyof TEntity & string, amount?: number, extra?: UpdateValues): Promise; decrementById(id: TEntity[PrimaryKey], column: keyof TEntity & string, amount?: number, extra?: UpdateValues): Promise; create(values: MutationValues): Promise; updateById(id: TEntity[PrimaryKey], changes: UpdateValues): Promise; updateByIdOrThrow(id: TEntity[PrimaryKey], changes: UpdateValues, errorFactory?: ErrorFactory): Promise; deleteById(id: TEntity[PrimaryKey]): Promise; softDeleteById(id: TEntity[PrimaryKey]): Promise; forceDeleteById(id: TEntity[PrimaryKey]): Promise; restoreById(id: TEntity[PrimaryKey]): Promise; withConnection(connection: DatabaseConnection): this; getConnection(): DatabaseConnection; getTable(): TableDefinition; query(where?: QueryWhere): RepositoryQuery; protected findWhere(where: QueryWhere, options?: Omit, "where">): Promise; protected countWhere(where?: QueryWhere, options?: Pick, "withTrashed" | "onlyTrashed" | "joins" | "groupBy">, whereNodes?: readonly WhereNode[]): Promise; protected averageColumn(column: keyof TEntity & string, where?: QueryWhere): Promise; protected averageExpression(expression: string, alias: string, where?: QueryWhere): Promise; sum(column: keyof TEntity & string, where?: QueryWhere): Promise; avg(column: keyof TEntity & string, where?: QueryWhere): Promise; min(column: keyof TEntity & string, where?: QueryWhere): Promise; max(column: keyof TEntity & string, where?: QueryWhere): Promise; private aggregateColumn; protected pluckNumberValues(expression: string, alias: string, options?: QueryOptions): Promise; protected countGroupedBy(column: K, where?: QueryWhere): Promise>; findByHasManyRelation(relation: HasManyRelation, parentId: TParent[LocalKey], options?: Omit, "where">): Promise; loadHasManyForParents(parents: readonly TParent[], relation: HasManyRelation, options?: Omit, "where">): Promise>; findHasManyThrough(parentId: unknown, relation: HasManyThroughRelation, options?: QueryOptions): Promise; loadHasManyThroughForParents(parents: readonly TParent[], relation: HasManyThroughRelation, options?: QueryOptions): Promise>; private throughSoftDeleteClause; private buildThroughWhere; loadBelongsToForParents(children: readonly TChild[], relation: BelongsToRelation, parentRepository: BaseRepository, options?: Omit, "where">): Promise>; loadMorphManyForParents(parents: readonly TParent[], relation: MorphManyRelation, options?: Omit, "where">): Promise>; loadMorphOneForParents(parents: readonly TParent[], relation: MorphOneRelation, options?: Omit, "where">): Promise>; loadMorphToForChildren(children: readonly TChild[], relation: MorphToRelation, repositoriesByType: ReadonlyMap>, options?: Omit, "where">): Promise>; loadBelongsToManyForParents(parents: readonly TParent[], relation: BelongsToManyRelation, relatedRepository: BaseRepository, options?: Omit, "where">): Promise>; } export { BaseRepository }; export default BaseRepository; export type { DatabaseConnection, SqlDatabaseConnection };