import { BelongsToRelation, HasOneRelation, Db, Adapter, AdapterOptions, QueryLogOptions, HasManyRelation, HasAndBelongsToManyRelation, Query, defaultsKey, BaseRelation, EmptyObject, RelationQuery, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsAll, ColumnTypesBase, ColumnsShape, ColumnShapeOutput, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb'; interface BelongsTo extends RelationThunkBase { type: 'belongsTo'; returns: 'one'; options: BelongsToRelation['options']; } declare type BelongsToInfo = { params: Record; populate: never; chainedCreate: false; chainedDelete: false; }; interface HasOne extends RelationThunkBase { type: 'hasOne'; returns: 'one'; options: HasOneRelation['options']; } declare type HasOneInfo = { params: Relation['options'] extends { primaryKey: string; } ? Record : Relation['options'] extends { through: string; } ? RelationInfo['params'] : never; populate: Relation['options'] extends { foreignKey: string; } ? Relation['options']['foreignKey'] : never; chainedCreate: Relation['options'] extends { primaryKey: string; } ? true : false; chainedDelete: true; }; declare function transaction(this: T, fn: (db: T) => Promise): Promise; declare type OrchidORM = { [K in keyof T]: DbModel; } & { $transaction: typeof transaction; $adapter: Adapter; $queryBuilder: Db; $close(): Promise; }; declare const orchidORM: ({ log, logger, ...options }: ({ adapter: Adapter; } | Omit) & QueryLogOptions, models: T) => OrchidORM; interface HasMany extends RelationThunkBase { type: 'hasMany'; returns: 'many'; options: HasManyRelation['options']; } declare type HasManyInfo = { params: Relation['options'] extends { primaryKey: string; } ? Record : Relation['options'] extends { through: string; } ? RelationInfo['params'] : never; populate: Relation['options'] extends { foreignKey: string; } ? Relation['options']['foreignKey'] : never; chainedCreate: Relation['options'] extends { primaryKey: string; } ? true : false; chainedDelete: true; }; interface HasAndBelongsToMany extends RelationThunkBase { type: 'hasAndBelongsToMany'; returns: 'many'; options: HasAndBelongsToManyRelation['options']; } declare type HasAndBelongsToManyInfo = { params: Record; populate: never; chainedCreate: true; chainedDelete: true; }; interface RelationThunkBase { type: string; returns: 'one' | 'many'; fn(): ModelClass; options: BaseRelation['options']; } declare type RelationThunk = BelongsTo | HasOne | HasMany | HasAndBelongsToMany; declare type RelationThunks = Record; declare type Relation>, Info extends RelationInfo = RelationInfo> = { type: Relations[K]['type']; returns: Relations[K]['returns']; key: K; model: M; query: M; joinQuery(fromQuery: Query, toQuery: Query): Query; defaults: Info['populate']; nestedCreateQuery: [Info['populate']] extends [never] ? M : M & { [defaultsKey]: Record; }; nestedInsert: BaseRelation['nestedInsert']; nestedUpdate: BaseRelation['nestedUpdate']; primaryKey: string; options: Relations[K]['options']; }; declare type RelationScopeOrModel = Relation['options']['scope'] extends (q: Query) => Query ? ReturnType : DbModel>; declare type RelationInfo = Relation extends BelongsTo ? BelongsToInfo : Relation extends HasOne ? HasOneInfo : Relation extends HasMany ? HasManyInfo : Relation extends HasAndBelongsToMany ? HasAndBelongsToManyInfo : never; declare type MapRelation, Info extends { params: Record; populate: string; chainedCreate: boolean; chainedDelete: boolean; } = RelationInfo> = RelationQuery : SetQueryReturnsOneOptional : SetQueryReturnsAll, Relation['options']['required'] extends boolean ? Relation['options']['required'] : false, Info['chainedCreate'], Info['chainedDelete']>; declare type MapRelations = 'relations' extends keyof T ? T['relations'] extends RelationThunks ? { [K in keyof T['relations']]: MapRelation; } : EmptyObject : EmptyObject; declare type ModelClass = new () => T; declare type ModelClasses = Record; declare type ModelToDb = Db; } : Query['relations'] : Query['relations'], T['columnTypes']> & { definedAs: string; db: OrchidORM; }; declare type DbModel = ModelToDb> & Omit>, keyof Query>; declare type ModelConfig = { shape: ColumnsShape; type: unknown; }; declare type ScopeFn = (q: DbModel) => Scope; declare type Model = { table: string; columns: ModelConfig; schema?: string; columnTypes: ColumnTypesBase; }; declare const createModel: (options: { columnTypes: CT; }) => { new (): { table: string; columns: ModelConfig; schema?: string | undefined; columnTypes: CT; setColumns: (fn: (t: CT) => T) => { shape: T; type: ColumnShapeOutput; }; belongsTo, Scope extends Query, Options extends { primaryKey: keyof InstanceType["columns"]["shape"]; foreignKey: keyof Self["columns"]["shape"]; scope?: ScopeFn | undefined; required?: boolean | undefined; }>(this: Self, fn: () => Related, options: Options): { type: "belongsTo"; returns: "one"; fn: () => Related; options: Options; }; hasOne, Scope_1 extends Query, Through extends string, Source extends string, Options_1 extends ({ primaryKey: keyof Self_1["columns"]["shape"]; foreignKey: keyof InstanceType["columns"]["shape"]; } | { through: Through; source: Source; }) & { scope?: ScopeFn | undefined; required?: boolean | undefined; }>(this: Self_1, fn: () => Related_1, options: Options_1): { type: "hasOne"; returns: "one"; fn: () => Related_1; options: Options_1; }; hasMany, Scope_2 extends Query, Through_1 extends string, Source_1 extends string, Options_2 extends ({ primaryKey: keyof Self_2["columns"]["shape"]; foreignKey: keyof InstanceType["columns"]["shape"]; } | { through: Through_1; source: Source_1; }) & { scope?: ScopeFn | undefined; required?: boolean | undefined; }>(this: Self_2, fn: () => Related_2, options: Options_2): { type: "hasMany"; returns: "many"; fn: () => Related_2; options: Options_2; }; hasAndBelongsToMany, Scope_3 extends Query, Options_3 extends { primaryKey: keyof Self_3["columns"]["shape"]; associationPrimaryKey: keyof InstanceType["columns"]["shape"]; foreignKey: string; associationForeignKey: string; joinTable: string; scope?: ScopeFn | undefined; required?: boolean | undefined; }>(this: Self_3, fn: () => Related_3, options: Options_3): { type: "hasAndBelongsToMany"; returns: "many"; fn: () => Related_3; options: Options_3; }; }; }; declare type QueryMethods = Record any>; declare type QueryOne = SetQueryReturns>; declare type MethodsBase = { queryMethods?: QueryMethods; queryOneMethods?: QueryMethods>; queryWithWhereMethods?: QueryMethods>; queryOneWithWhereMethods?: QueryMethods>>; methods?: Record; }; declare type MapQueryMethods = Methods extends QueryMethods ? { [K in keyof Methods]: Methods[K] extends (q: any, ...args: infer Args) => infer Result ? (this: T, ...args: Args) => Result extends Query ? MergeQuery : Result : never; } : EmptyObject; declare type MapMethods> = MapQueryMethods & MapQueryMethods, QueryOne, Methods['queryOneMethods']> & MapQueryMethods, WhereResult, Methods['queryWithWhereMethods']> & MapQueryMethods>, QueryOne>, Methods['queryOneWithWhereMethods']> & (Methods['methods'] extends Record ? Methods['methods'] : EmptyObject); declare type Repo, Mapped = MapMethods> = ((q: Q) => Q & Mapped) & T & Mapped; declare const createRepo: >(model: T, methods: Methods) => Repo>; export { DbModel, MapMethods, MapQueryMethods, MethodsBase, Model, ModelClass, ModelClasses, ModelToDb, OrchidORM, QueryMethods, Repo, createModel, createRepo, orchidORM };