UNPKG

agnostic-query

Version:

Type-safe fluent builder for portable query schemas. Runtime-agnostic, database-agnostic — the same QuerySchema drives Drizzle, Kysely, db0, or raw SQL.

73 lines (72 loc) 1.92 kB
import type { QuerySchema } from '../core/index'; import type { SchemaShape } from '../core/schema'; import type { TSelectQueryBuilder } from './types.js'; export type KyselyNodeUnaryOp = '=' | '>' | '>=' | '<' | '<=' | 'like' | 'ilike'; type IdentifierNode = { kind: 'IdentifierNode'; name: string; }; type ColumnNode = { kind: 'ColumnNode'; column: IdentifierNode; }; type ReferenceNode = { kind: 'ReferenceNode'; column: ColumnNode; }; type BinaryOperationNode = { kind: 'BinaryOperationNode'; leftOperand: ReferenceNode; operator: OperatorNode; rightOperand: ValueNode; } | { kind: 'BinaryOperationNode'; leftOperand: ReferenceNode; operator: { kind: 'OperatorNode'; operator: 'in'; }; rightOperand: PrimitiveValueListNode; }; type OperatorNode = { kind: 'OperatorNode'; operator: KyselyNodeUnaryOp; }; type ValueNode = { kind: 'ValueNode'; value: any; }; type PrimitiveValueListNode = { kind: 'PrimitiveValueListNode'; values: any[]; }; type AndNode = { kind: 'AndNode'; left: BinaryOperationNode | AndNode | ParensNode; right: BinaryOperationNode; }; type OrNode = { kind: 'OrNode'; left: BinaryOperationNode; right: BinaryOperationNode; }; type ParensNode = { kind: 'ParensNode'; node: OrNode | AndNode; }; type RawNode = { kind: 'RawNode'; sqlFragments: string[]; parameters: any[]; }; type UnaryOperationNode = { kind: 'UnaryOperationNode'; operator: { kind: 'OperatorNode'; operator: 'not'; }; operand: BinaryOperationNode; }; export type OperationNode = ParensNode | OrNode | UnaryOperationNode | BinaryOperationNode | AndNode | ReferenceNode | RawNode; export declare const fromKysely: <TShape extends SchemaShape, TableName extends string>(queryBuilder: TSelectQueryBuilder<TShape, TableName>) => QuerySchema<TShape>; export {};