import type { SQLQuery } from '@databases/sql';
import { type JSONValue } from '../../shared/src/json.ts';
import type { AST, CorrelatedSubquery, Correlation, Ordering, SimpleCondition } from '../../zero-protocol/src/ast.ts';
import type { Schema } from '../../zero-schema/src/builder/schema-builder.ts';
import { type NameMapper } from '../../zero-schema/src/name-mapper.ts';
import type { ServerSchema } from '../../zero-schema/src/server-schema.ts';
import type { Format } from '../../zql/src/ivm/view.ts';
type Table = {
    zql: string;
    alias: string;
};
type QualifiedColumn = {
    table: Table;
    zql: string;
};
type ServerSpec = {
    schema: ServerSchema;
    mapper: NameMapper;
};
export type Spec = {
    server: ServerSpec;
    zql: Schema['tables'];
    aliasCount: number;
};
export declare function compile(serverSchema: ServerSchema, zqlSchema: Schema, ast: AST, format?: Format | undefined): SQLQuery;
export declare function limit(limit: number | undefined, singular: boolean | undefined): SQLQuery;
export declare function orderBy(spec: Spec, orderBy: Ordering | undefined, table: Table): SQLQuery;
export declare function makeCorrelator(spec: Spec, parentFields: readonly QualifiedColumn[], childZqlFields: readonly string[]): (childTable: Table) => SQLQuery;
export declare function simple(spec: Spec, condition: SimpleCondition, table: Table): SQLQuery;
export declare function any(spec: Spec, condition: SimpleCondition, table: Table): SQLQuery;
export declare function distinctFrom(spec: Spec, condition: SimpleCondition, table: Table): SQLQuery;
export declare function makeJunctionJoin(spec: Spec, relationship: CorrelatedSubquery): {
    join: SQLQuery;
    participatingTables: ReturnType<typeof pullTablesForJunction>;
};
export declare function pullTablesForJunction(spec: Spec, relationship: CorrelatedSubquery): [
    {
        table: Table;
        correlation: Correlation;
        limit: number | undefined;
    },
    {
        table: Table;
        correlation: Correlation;
        limit: number | undefined;
    }
];
export declare function extractZqlResult(pgResult: Array<any>): JSONValue;
export {};
//# sourceMappingURL=compiler.d.ts.map