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.
24 lines (23 loc) • 1.46 kB
TypeScript
import type { QueryOrderBy } from './order-by.js';
import type { FieldPathByShape, SchemaShape } from './schema.js';
import { type ComparisonWhereValue, type PredicateOp, type QueryWhere, type WhereComparisonOp, type WhereExpr } from './where.js';
export interface QuerySchema<TShape extends SchemaShape = SchemaShape> {
where?: QueryWhere<TShape> | null;
orderBy?: QueryOrderBy<TShape>[];
limit?: number;
offset?: number;
mate?: Record<string, any>;
table?: string;
}
interface AgnosticQuery<TShape extends SchemaShape = SchemaShape> {
toJSON(): QuerySchema<TShape>;
where(cb: (eb: WhereExpr<TShape>) => WhereExpr<TShape>): AgnosticQuery<TShape>;
where<Col extends FieldPathByShape<TShape> | (keyof TShape & string), Op extends WhereComparisonOp>(col: Col, op: Op, value: ComparisonWhereValue<TShape, Col, Op>): AgnosticQuery<TShape>;
where<Col extends FieldPathByShape<TShape> | (keyof TShape & string), Op extends PredicateOp>(col: Col, op: Op): AgnosticQuery<TShape>;
where(where?: QueryWhere<TShape> | null): AgnosticQuery<TShape>;
orderBy<Col extends FieldPathByShape<TShape> | (keyof TShape & string)>(col: Col, direction?: 'asc' | 'desc'): AgnosticQuery<TShape>;
limit(value?: number): AgnosticQuery<TShape>;
offset(value?: number): AgnosticQuery<TShape>;
}
export declare const aq: <TShape extends SchemaShape = SchemaShape>(state?: QuerySchema<TShape>) => AgnosticQuery<TShape>;
export {};