import { AbstractClassType, ClassType, TypeAnnotation } from '@deepkit/core';
import { ActiveRecord, ActiveRecordClassType, Database, DatabaseAdapter, DatabaseSession, FilterQuery, OrmEntity } from '@deepkit/orm';
import { SQLDatabaseQuery, SqlQuery } from '@deepkit/sql';
import { AutoIncrement, ReceiveType, ReflectionClass, Type } from '@deepkit/type';
import { MutexKey } from '../helpers';
import { ObjectKeysMatching } from '../types';
declare const PreCommitHooksSymbol: unique symbol;
declare const PostCommitHooksSymbol: unique symbol;
declare module '@deepkit/orm' {
    interface DatabaseSession {
        [PreCommitHooksSymbol]?: (() => Promise<void>)[];
        [PostCommitHooksSymbol]?: (() => Promise<void>)[];
        addPreCommitHook(hook: () => Promise<void>): void;
        addPostCommitHook(hook: () => Promise<void>): void;
        acquireSessionLock(key: MutexKey | MutexKey[]): Promise<void>;
    }
}
type QueryClassType<T> = ReceiveType<T> | ClassType<T> | AbstractClassType<T> | ReflectionClass<T>;
export declare class BaseDatabase<A extends DatabaseAdapter = DatabaseAdapter> extends Database<A> {
    constructor(adapter: A, schemas?: (Type | ClassType | ReflectionClass<any>)[]);
    query: <T extends OrmEntity>(type?: QueryClassType<T>, txn?: DatabaseSession<DatabaseAdapter>) => SQLDatabaseQuery<T>;
    transaction<T>(callback: (session: DatabaseSession<A>) => Promise<T>): Promise<T>;
    session<T>(worker: (session: DatabaseSession<A>) => Promise<T>): Promise<T>;
    withTransaction<R>(txn: DatabaseSession<A> | undefined, callback: (session: DatabaseSession<A>) => Promise<R>): Promise<R>;
    withSession<R>(session: DatabaseSession<A> | undefined, callback: (session: DatabaseSession<A>) => Promise<R>): Promise<R>;
    rawExecute(sqlIn: SqlQuery | string, existingSession?: DatabaseSession<any>): Promise<{
        affectedRows: number;
        insertId: number;
        warningStatus: number;
    }>;
    rawExecuteUnsafe(sqlIn: string, bindings: any[], existingSession?: DatabaseSession<any>): Promise<{
        affectedRows: number;
        insertId: number;
        warningStatus: number;
    }>;
    rawQuery(sqlIn: SqlQuery | string, existingSession?: DatabaseSession<any>): Promise<unknown[]>;
    rawFind<T>(sqlIn: SqlQuery | string, existingSession?: DatabaseSession<any>, type?: ReceiveType<T>): Promise<T[]>;
    rawFindUnsafe<T>(sqlIn: string, bindings: any[], existingSession?: DatabaseSession<any>, type?: ReceiveType<T>): Promise<T[]>;
    rawFindOne<T>(sqlIn: SqlQuery | string, existingSession?: DatabaseSession<any>, type?: ReceiveType<T>): Promise<T | undefined>;
    rawFindOneUnsafe<T>(sqlIn: string, bindings: any[], existingSession?: DatabaseSession<any>, type?: ReceiveType<T>): Promise<T | undefined>;
    createSqlQuery(sqlIn: string, bindings: any[]): SqlQuery;
}
type FieldsMatching<T, V> = {
    [K in keyof T]: T[K] extends V ? (T[K] extends Function ? never : K) : never;
}[keyof T];
export type DataTypes = string | number | boolean | Date | object | null;
export type EntityFieldKeys<T extends object> = FieldsMatching<T, DataTypes>;
export type EntityFields<T extends object> = Pick<T, EntityFieldKeys<T>>;
export type EntityClassFields<T extends ClassType> = Pick<InstanceType<T>, EntityFieldKeys<InstanceType<T>>>;
export declare type HasDefault = TypeAnnotation<'dksf:hasDefault'>;
export type OptionalKeys<T extends object> = ObjectKeysMatching<T, HasDefault> | ObjectKeysMatching<T, null> | ObjectKeysMatching<T, AutoIncrement>;
export type EntityOptionals<T extends object> = {
    [K in keyof Pick<T, OptionalKeys<T>>]?: T[K];
} & {
    [K in keyof Omit<T, OptionalKeys<T>>]: T[K];
};
export type NewEntityFields<T extends object> = EntityOptionals<EntityFields<T>>;
export declare function createEntity<D extends T, T extends ActiveRecord = ActiveRecord>(Entity: ClassType<T>, data: NewEntityFields<D>): T;
export declare function createEntities<D extends T, T extends ActiveRecord = ActiveRecord>(Entity: ClassType<T>, data: NewEntityFields<D>[]): T[];
export declare function createQueuedEntity<D extends T, T extends ActiveRecord = ActiveRecord>(Entity: ClassType<T>, data: NewEntityFields<D>, session: DatabaseSession<any>): T;
export declare function createQueuedEntities<D extends T, T extends ActiveRecord = ActiveRecord>(Entity: ClassType<T>, data: NewEntityFields<D>[], session: DatabaseSession<any>): T[];
export declare function persistEntity<T extends ActiveRecord>(entity: T, session?: DatabaseSession<any>): Promise<void>;
export declare function persistEntities<T extends ActiveRecord>(entities: T[], session?: DatabaseSession<any>): Promise<void>;
export declare function createPersistedEntity<D extends T, T extends ActiveRecord = ActiveRecord>(Entity: ClassType<T>, data: NewEntityFields<D>, session?: DatabaseSession<any>): Promise<T>;
export declare function createPersistedEntities<D extends T, T extends ActiveRecord = ActiveRecord>(Entity: ClassType<T>, data: NewEntityFields<D>[], session?: DatabaseSession<any>): Promise<T[]>;
export declare function getPKFieldForEntity(EntityClass: ActiveRecordClassType): string;
export declare function getPKFieldForEntityInstance(entity: any): string;
type EntityFilter<T extends ActiveRecordClassType> = FilterQuery<InstanceType<T>> | string | number;
export declare function getEntityOrUndefined<T extends ActiveRecordClassType>(EntityClass: T, filter: EntityFilter<T>): Promise<InstanceType<T> | undefined>;
export declare function getEntityOr404<T extends ActiveRecordClassType>(EntityClass: T, filter: EntityFilter<T>): Promise<InstanceType<T>>;
export declare function getEntity<T extends ActiveRecordClassType>(EntityClass: T, filter: EntityFilter<T>): Promise<InstanceType<T>>;
export declare function entityExists<T extends ActiveRecordClassType>(EntityClass: T, filter: EntityFilter<T>): Promise<boolean>;
export declare function getEntityFields<T extends ActiveRecord>(entity: T): EntityFields<T>;
export declare function logSql(sql: string, bindings?: any[]): void;
export {};
export declare type __ΩDataTypes = any[];
export declare type __ΩEntityFieldKeys = any[];
export declare type __ΩEntityFields = any[];
export declare type __ΩEntityClassFields = any[];
export declare type __ΩHasDefault = any[];
export declare type __ΩOptionalKeys = any[];
export declare type __ΩEntityOptionals = any[];
export declare type __ΩNewEntityFields = any[];
//# sourceMappingURL=common.d.ts.map