UNPKG

@uwdata/mosaic-sql

Version:

SQL query construction and analysis.

294 lines 8.82 kB
import type { FilterExpr, FromExpr, GroupByExpr, MaybeArray, OrderByExpr, SelectExpr, WithExpr } from '../types.js'; import type { SampleMethod } from './sample.js'; import { FromClauseNode } from './from.js'; import { ExprNode, SQLNode } from './node.js'; import { SampleClauseNode } from './sample.js'; import { SelectClauseNode } from './select.js'; import { WindowClauseNode, type WindowDefNode } from './window.js'; import { WithClauseNode } from './with.js'; /** * Check if a value is a selection query or set operation. * @param value The value to check. */ export declare function isQuery(value: unknown): value is Query; /** * Check if a value is a selection query. * @param value The value to check. */ export declare function isSelectQuery(value: unknown): value is SelectQuery; /** * Check if a value is a describe query. * @param value The value to check. */ export declare function isDescribeQuery(value: unknown): value is DescribeQuery; export declare class Query extends ExprNode { /** * Create a new WITH clause with the given CTE queries. * @param expr The WITH CTE queries. */ static with(...expr: WithExpr[]): WithClause; /** * Create a new select query with the given SELECT expressions. * @param expr The SELECT expressions. */ static select(...expr: SelectExpr[]): SelectQuery; /** * Create a new select query with the given FROM expressions. * @param expr The FROM expressions. */ static from(...expr: FromExpr[]): SelectQuery; /** * Create a new UNION set operation over the given queries. * @param queries The queries. */ static union(...queries: MaybeArray<Query>[]): SetOperation; /** * Create a new UNION ALL set operation over the given queries. * @param queries The queries. */ static unionAll(...queries: MaybeArray<Query>[]): SetOperation; /** * Create a new INTERSECT set operation over the given queries. * @param queries The queries. */ static intersect(...queries: MaybeArray<Query>[]): SetOperation; /** * Create a new EXCEPT set operation over the given queries. * @param queries The queries. */ static except(...queries: MaybeArray<Query>[]): SetOperation; /** * Create a new describe query for the given input query. * @param query The query to describe. */ static describe(query: Query): DescribeQuery; _with: WithClauseNode[]; _orderby: ExprNode[]; _limitPerc: boolean; _limit?: ExprNode; _offset?: ExprNode; cteFor?: Query | null; /** * Instantiate a new query. */ constructor(type: string); /** * Return a list of subqueries. */ get subqueries(): Query[]; /** * Clone this query. */ clone(): this; /** * Add a pointer to the query for which this query is a CTE. * @param query The query for which this query is a CTE. */ setCteFor(query: Query | null): void; /** * Add WITH common table expressions (CTEs). * @param expr Expressions to add. */ with(...expr: WithExpr[]): this; /** * Add ORDER BY expressions. * @param expr Expressions to add. */ orderby(...expr: OrderByExpr[]): this; /** * Set the query result LIMIT as a percentage value. * @param value The limit percentage value. */ limitPercent(value: number | ExprNode): this; /** * Set the query result LIMIT. * @param value The limit value. */ limit(value: number | ExprNode): this; /** * Set the query result OFFSET. * @param value The offset value. */ offset(value: number | ExprNode): this; } export declare class SelectQuery extends Query { _select: SelectClauseNode[]; _from: FromClauseNode[]; _where: ExprNode[]; _sample?: SampleClauseNode; _groupby: ExprNode[]; _having: ExprNode[]; _window: WindowClauseNode[]; _qualify: ExprNode[]; _distinct: boolean; /** * Instantiate a new select query. */ constructor(); /** * Return a list of subqueries. */ get subqueries(): Query[]; /** * Clone this query. */ clone(): this; /** * Add SELECT expressions. * @param expr Expressions to add. */ select(...expr: SelectExpr[]): this; /** * Set SELECT expressions, replacing any prior expressions. * @param expr Expressions to add. */ setSelect(...expr: SelectExpr[]): this; /** * Indicate if this query should retrieve distinct values only. * @param value The distinct flag */ distinct(value?: boolean): this; /** * Add table FROM expressions. * @param expr Expressions to add. */ from(...expr: FromExpr[]): this; /** * Set FROM expressions, replacing any prior expressions. * @param expr Expressions to add. */ setFrom(...expr: FromExpr[]): this; /** * Set SAMPLE settings. * @param value Either a sample clause node or the sample size as either * a row count or percentage. * @param method The sampling method to use. * @param seed The random seed. */ sample(value: number | SampleClauseNode, method?: SampleMethod, seed?: number): this; /** * Add WHERE expressions. * @param expr Expressions to add. */ where(...expr: FilterExpr[]): this; /** * Set WHERE expressions, replacing any prior expressions. * @param expr Expressions to add. */ setWhere(...expr: FilterExpr[]): this; /** * Add GROUP BY expressions. * @param expr Expressions to add. */ groupby(...expr: GroupByExpr[]): this; /** * Set GROUP BY expressions, replacing any prior expressions. * @param expr Expressions to add. */ setGroupby(...expr: GroupByExpr[]): this; /** * Add HAVING expressions. * @param expr Expressions to add. */ having(...expr: FilterExpr[]): this; /** * Add WINDOW definitions. * @param expr Window definitions to add. */ window(...expr: (Record<string, WindowDefNode> | null)[]): this; /** * Add QUALIFY expressions. * @param expr Expressions to add. */ qualify(...expr: FilterExpr[]): this; /** * Generate a SQL query string. */ toString(): string; } export declare class DescribeQuery extends SQLNode { readonly query: Query; /** * Instantiate a describe query. * @param query The query to describe. */ constructor(query: Query); /** * Clone this describe query. */ clone(): this; /** * Generate a SQL query string. */ toString(): string; } export declare class SetOperation extends Query { /** The set operation to perform. */ readonly op: string; /** The input queries to the set operation. */ readonly queries: Query[]; /** * Instantiate a new set operation instance. * @param op The set operation. * @param queries The subqueries. */ constructor(op: string, queries: Query[]); /** * Add a pointer to the query for which this query is a CTE. * @param query The query for which this query is a CTE. */ setCteFor(query: Query | null): void; /** * Return a list of subqueries. */ get subqueries(): Query[]; /** * Clone this set operation. */ clone(): this; /** * Generate a SQL query string. */ toString(): string; } declare class WithClause { /** The common table expressions (CTE). */ readonly _with: WithExpr[]; /** * Instantiate a new WITH clause instance. * @param expr The WITH CTE queries. */ constructor(...expr: WithExpr[]); /** * Create a new select query with the given SELECT expressions. * @param expr The SELECT expressions. */ select(...expr: SelectExpr[]): SelectQuery; /** * Create a new select query with the given FROM expressions. * @param expr The FROM expressions. */ from(...expr: FromExpr[]): SelectQuery; /** * Create a new UNION set operation over the given queries. * @param queries The queries. */ union(...queries: Query[]): SetOperation; /** * Create a new UNION ALL set operation over the given queries. * @param queries The queries. */ unionAll(...queries: Query[]): SetOperation; /** * Create a new INTERSECT set operation over the given queries. * @param queries The queries. */ intersect(...queries: Query[]): SetOperation; /** * Create a new EXCEPT set operation over the given queries. * @param queries The queries. */ except(...queries: Query[]): SetOperation; } export {}; //# sourceMappingURL=query.d.ts.map