rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
64 lines (63 loc) • 3.04 kB
TypeScript
import { UpdateQuery } from '../models/UpdateQuery';
import { BinarySelectQuery, SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
import { CreateTableQuery } from "../models/CreateTableQuery";
import { InsertQuery } from "../models/InsertQuery";
/**
* QueryBuilder provides static methods to build or convert various SQL query objects.
*/
export declare class QueryBuilder {
/**
* Builds a BinarySelectQuery by combining an array of SelectQuery using the specified operator.
* Throws if less than two queries are provided.
* @param queries Array of SelectQuery to combine
* @param operator SQL operator to use (e.g. 'union', 'union all', 'intersect', 'except')
* @returns BinarySelectQuery
*/
static buildBinaryQuery(queries: SelectQuery[], operator: string): BinarySelectQuery;
private constructor();
/**
* Converts a SELECT query to a standard SimpleSelectQuery form.
* @param query The query to convert
* @returns A SimpleSelectQuery
*/
static buildSimpleQuery(query: SelectQuery): SimpleSelectQuery;
private static buildSimpleBinaryQuery;
/**
* Converts a ValuesQuery to a SimpleSelectQuery with sequentially numbered columns or user-specified columns
*
* @param query The VALUES query to convert
* @param columns Optional: column names
* @returns A SimpleSelectQuery
*/
private static buildSimpleValuesQuery;
/**
* Creates a SELECT clause with a single * (all columns) item
*
* @returns A SELECT clause with *
*/
private static createSelectAllClause;
/**
* Converts a SELECT query to a CREATE TABLE query (CREATE [TEMPORARY] TABLE ... AS SELECT ...)
* @param query The SELECT query to use as the source
* @param tableName The name of the table to create
* @param isTemporary If true, creates a temporary table
* @returns A CreateTableQuery instance
*/
static buildCreateTableQuery(query: SelectQuery, tableName: string, isTemporary?: boolean): CreateTableQuery;
/**
* Converts a SELECT query to an INSERT query (INSERT INTO ... SELECT ...)
* @param selectQuery The SELECT query to use as the source
* @param tableName The name of the table to insert into
* @param columns Optional: array of column names. If omitted, columns are inferred from the selectQuery
* @returns An InsertQuery instance
*/
static buildInsertQuery(selectQuery: SimpleSelectQuery, tableName: string): InsertQuery;
/**
* Builds an UPDATE query from a SELECT query, table name, and primary key(s).
* @param selectQuery The SELECT query providing new values (must select all columns to update and PKs)
* @param updateTableExprRaw The table name to update
* @param primaryKeys The primary key column name(s)
* @returns UpdateQuery instance
*/
static buildUpdateQuery(selectQuery: SimpleSelectQuery, selectSourceName: string, updateTableExprRaw: string, primaryKeys: string | string[]): UpdateQuery;
}