import { type AbstractType, type Constructor, type Field, type FieldType } from "@dao-xyz/borsh";
import * as types from "@peerbit/indexer-interface";
import { type PlanningSession } from "./query-planner.js";
export type SQLLiteValue = string | number | null | bigint | Uint8Array | Int8Array | ArrayBuffer;
export type BindableValue = string | bigint | number | Uint8Array | Int8Array | ArrayBuffer | null;
export declare const u64ToI64: (u64: bigint | number) => bigint;
export declare const i64ToU64: (i64: number | bigint) => bigint;
export declare const convertToSQLType: (value: boolean | bigint | string | number | Uint8Array, type?: FieldType) => BindableValue;
export declare const escapeColumnName: (name: string, char?: string) => string;
export declare class MissingFieldError extends Error {
    constructor(message: string);
}
export declare const convertFromSQLType: (value: boolean | bigint | string | number | Uint8Array, type: FieldType | undefined) => any;
export declare const toSQLType: (type: FieldType, isOptional?: boolean) => string;
type SQLField = {
    name: string;
    key: string;
    definition: string;
    type: string;
    isPrimary: boolean;
    from: Field | undefined;
    unwrappedType: FieldType | undefined;
    path: string[];
    describesExistenceOfAnother?: string;
};
type SQLConstraint = {
    name: string;
    definition: string;
};
export interface Table {
    name: string;
    ctor: Constructor<any>;
    primary: string | false;
    primaryIndex: number;
    primaryField?: SQLField;
    path: string[];
    parentPath: string[] | undefined;
    fields: SQLField[];
    constraints: SQLConstraint[];
    children: Table[];
    inline: boolean;
    parent: Table | undefined;
    referencedInArray: boolean;
    isSimpleValue: boolean;
    indices: Set<string>;
}
export declare const getSQLTable: (ctor: AbstractType<any>, path: string[], primary: string | false, inline: boolean, addJoinField: ((fields: SQLField[], constraints: SQLConstraint[]) => void) | undefined, fromOptionalField?: boolean) => Table[];
export declare const getTableName: (path: string[] | undefined, clazz: string | Constructor<any>) => any;
export declare const CHILD_TABLE_ID = "__id";
export declare const ARRAY_INDEX_COLUMN = "__index";
export declare const PARENT_TABLE_ID = "__parent_id";
export declare const getSQLFields: (tableName: string, path: string[], ctor: Constructor<any>, primary: string | false, addJoinFieldFromParent?: (fields: SQLField[], constraints: SQLConstraint[]) => void, tables?: Table[], isOptional?: boolean) => {
    fields: SQLField[];
    constraints: SQLConstraint[];
    dependencies: Table[];
};
export declare const resolveTable: <B extends boolean, R = B extends true ? Table : Table | undefined>(key: string[], tables: Map<string, Table>, clazz: string | Constructor<any>, throwOnMissing: B) => R;
export declare const insert: (insertFn: (values: any[], table: Table, options?: {
    requireId?: boolean;
}) => Promise<any> | any, obj: Record<string, any>, tables: Map<string, Table>, table: Table, fields: Field[], handleNestedCallback?: (cb: (parentId: any) => Promise<void>) => Promise<void> | void | number, parentId?: any, index?: number, options?: {
    insertSimpleVecRows?: (rows: any[][], table: Table) => Promise<void> | void;
}) => Promise<void>;
export declare const getTablePrefixedField: (table: Table, key: string, skipPrefix?: boolean) => string;
export declare const getTableNameFromPrefixedField: (prefixedField: string) => string;
export declare const getInlineTableFieldName: (path: string[] | string | undefined, key?: string) => string;
export declare const selectChildren: (childrenTable: Table) => string;
export declare const generateSelectQuery: (table: Table, selects: {
    from: string;
    as: string;
}[]) => string;
export declare const selectAllFieldsFromTables: (tables: Table[], shape: types.Shape | undefined) => {
    selects: {
        from: string;
        as: string;
    }[];
    joins: Map<string, JoinOrRootTable>;
    groupBy: string | undefined;
}[];
export declare const selectAllFieldsFromTable: (table: Table, shape: types.Shape | undefined) => {
    groupBy: string | undefined;
    selects: {
        from: string;
        as: string;
    }[];
    join: Map<string, JoinTable>;
};
export declare const resolveInstanceFromValue: <T, S extends types.Shape | undefined>(fromTablePrefixedValues: Record<string, any>, tables: Map<string, Table>, table: Table, resolveChildren: (parentId: any, table: Table) => Promise<any[]>, tablePrefixed: boolean, shape?: S) => Promise<types.ReturnTypeFromShape<T, S>>;
export declare const fromRowToObj: (row: any, ctor: Constructor<any>) => any;
export declare const convertDeleteRequestToQuery: (request: types.DeleteOptions, tables: Map<string, Table>, table: Table) => {
    sql: string;
    bindable: any[];
};
export declare const convertSumRequestToQuery: (request: types.SumOptions, tables: Map<string, Table>, table: Table) => {
    sql: string;
    bindable: any[];
};
export declare const convertCountRequestToQuery: (request: types.CountOptions | undefined, tables: Map<string, Table>, table: Table) => {
    sql: string;
    bindable: any[];
};
export declare const convertSearchRequestToQuery: (request: {
    query: types.Query[];
    sort?: types.Sort[] | types.Sort;
} | undefined, tables: Map<string, Table>, rootTables: Table[], options?: {
    shape?: types.Shape | undefined;
    fetchAll?: boolean;
    planner?: PlanningSession;
}) => {
    sql: string;
    bindable: any[];
};
export declare const buildJoin: (joinBuilder: Map<string, JoinOrRootTable>, options?: {
    planner?: PlanningSession;
}) => {
    join: string;
};
export declare const convertQueryToSQLQuery: (query: types.Query, tables: Map<string, Table>, table: Table, joinBuilder: Map<string, JoinOrRootTable>, path: string[], tableAlias: string | undefined, skipKeys: number) => {
    where: string;
    bindable: any[];
};
type JoinOrRootTable = JoinTable | RootTable;
type JoinTable = {
    table: Table;
    as: string;
    type: "left" | "cross";
    columns: string[];
};
type RootTable = {
    type: "root";
    table: Table;
    as: string;
    columns: string[];
};
export {};
//# sourceMappingURL=schema.d.ts.map