rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
207 lines (206 loc) • 8.17 kB
TypeScript
import { PartitionByClause, OrderByClause } from "./Clause";
import { SelectQuery } from "./SelectQuery";
import { SqlComponent } from "./SqlComponent";
export type ValueComponent = ValueList | ColumnReference | FunctionCall | UnaryExpression | BinaryExpression | LiteralValue | ParameterExpression | SwitchCaseArgument | CaseKeyValuePair | RawString | IdentifierString | ParenExpression | CastExpression | CaseExpression | ArrayExpression | ArrayQueryExpression | BetweenExpression | InlineQuery | StringSpecifierExpression | TypeValue | TupleExpression;
export declare class InlineQuery extends SqlComponent {
static kind: symbol;
selectQuery: SelectQuery;
constructor(selectQuery: SelectQuery);
}
export declare class ValueList extends SqlComponent {
static kind: symbol;
values: ValueComponent[];
constructor(values: ValueComponent[]);
}
export declare class ColumnReference extends SqlComponent {
/**
* For backward compatibility: returns the namespaces as IdentifierString[] | null (readonly)
*/
get namespaces(): IdentifierString[] | null;
/**
* For backward compatibility: returns the column name as IdentifierString (readonly)
*/
get column(): IdentifierString;
static kind: symbol;
qualifiedName: QualifiedName;
constructor(namespaces: string | string[] | IdentifierString[] | null, column: string | IdentifierString);
toString(): string;
getNamespace(): string;
}
export declare class FunctionCall extends SqlComponent {
static kind: symbol;
qualifiedName: QualifiedName;
argument: ValueComponent | null;
over: OverExpression | null;
constructor(namespaces: string | string[] | IdentifierString[] | null, name: string | RawString | IdentifierString, argument: ValueComponent | null, over: OverExpression | null);
/**
* For backward compatibility: returns the namespaces as IdentifierString[] | null (readonly)
*/
get namespaces(): IdentifierString[] | null;
/**
* For backward compatibility: returns the function name as RawString | IdentifierString (readonly)
*/
get name(): RawString | IdentifierString;
}
export type OverExpression = WindowFrameExpression | IdentifierString;
export declare enum WindowFrameType {
Rows = "rows",
Range = "range",
Groups = "groups"
}
export declare enum WindowFrameBound {
UnboundedPreceding = "unbounded preceding",
UnboundedFollowing = "unbounded following",
CurrentRow = "current row"
}
export type FrameBoundaryComponent = WindowFrameBoundStatic | WindowFrameBoundaryValue;
export declare class WindowFrameBoundStatic extends SqlComponent {
static kind: symbol;
bound: WindowFrameBound;
constructor(bound: WindowFrameBound);
}
export declare class WindowFrameBoundaryValue extends SqlComponent {
static kind: symbol;
value: ValueComponent;
isFollowing: boolean;
constructor(value: ValueComponent, isFollowing: boolean);
}
export declare class WindowFrameSpec extends SqlComponent {
static kind: symbol;
frameType: WindowFrameType;
startBound: FrameBoundaryComponent;
endBound: FrameBoundaryComponent | null;
constructor(frameType: WindowFrameType, startBound: FrameBoundaryComponent, endBound: FrameBoundaryComponent | null);
}
export declare class WindowFrameExpression extends SqlComponent {
static kind: symbol;
partition: PartitionByClause | null;
order: OrderByClause | null;
frameSpec: WindowFrameSpec | null;
constructor(partition: PartitionByClause | null, order: OrderByClause | null, frameSpec?: WindowFrameSpec | null);
}
export declare class UnaryExpression extends SqlComponent {
static kind: symbol;
operator: RawString;
expression: ValueComponent;
constructor(operator: string, expression: ValueComponent);
}
export declare class BinaryExpression extends SqlComponent {
static kind: symbol;
left: ValueComponent;
operator: RawString;
right: ValueComponent;
constructor(left: ValueComponent, operator: string, right: ValueComponent);
}
export declare class LiteralValue extends SqlComponent {
static kind: symbol;
value: string | number | boolean | null;
constructor(value: string | number | boolean | null);
}
export declare class ParameterExpression extends SqlComponent {
static kind: symbol;
name: RawString;
value: any | null;
/**
* The index assigned by the formatter when generating parameterized queries.
* Used for naming parameters like $1, $2, etc.
*/
index: number | null;
constructor(name: string, value?: any | null);
}
export declare class SwitchCaseArgument extends SqlComponent {
static kind: symbol;
cases: CaseKeyValuePair[];
elseValue: ValueComponent | null;
constructor(cases: CaseKeyValuePair[], elseValue?: ValueComponent | null);
}
export declare class CaseKeyValuePair extends SqlComponent {
static kind: symbol;
key: ValueComponent;
value: ValueComponent;
constructor(key: ValueComponent, value: ValueComponent);
}
export declare class RawString extends SqlComponent {
static kind: symbol;
value: string;
constructor(value: string);
}
export declare class IdentifierString extends SqlComponent {
static kind: symbol;
name: string;
constructor(alias: string);
}
export declare class ParenExpression extends SqlComponent {
static kind: symbol;
expression: ValueComponent;
constructor(expression: ValueComponent);
}
export declare class CastExpression extends SqlComponent {
static kind: symbol;
input: ValueComponent;
castType: TypeValue;
constructor(input: ValueComponent, castType: TypeValue);
}
export declare class CaseExpression extends SqlComponent {
static kind: symbol;
condition: ValueComponent | null;
switchCase: SwitchCaseArgument;
constructor(condition: ValueComponent | null, switchCase: SwitchCaseArgument);
}
export declare class ArrayExpression extends SqlComponent {
static kind: symbol;
expression: ValueComponent;
constructor(expression: ValueComponent);
}
export declare class ArrayQueryExpression extends SqlComponent {
static kind: symbol;
query: SelectQuery;
constructor(query: SelectQuery);
}
export declare class BetweenExpression extends SqlComponent {
static kind: symbol;
expression: ValueComponent;
lower: ValueComponent;
upper: ValueComponent;
negated: boolean;
constructor(expression: ValueComponent, lower: ValueComponent, upper: ValueComponent, negated: boolean);
}
export declare class StringSpecifierExpression extends SqlComponent {
static kind: symbol;
specifier: RawString;
value: LiteralValue;
constructor(specifier: string, value: string);
}
export declare class TypeValue extends SqlComponent {
static kind: symbol;
qualifiedName: QualifiedName;
argument: ValueComponent | null;
constructor(namespaces: string[] | IdentifierString[] | null, name: string | RawString | IdentifierString, argument?: ValueComponent | null);
/**
* For backward compatibility: returns the namespaces as IdentifierString[] | null (readonly)
*/
get namespaces(): IdentifierString[] | null;
/**
* For backward compatibility: returns the type name as RawString | IdentifierString (readonly)
*/
get name(): RawString | IdentifierString;
getTypeName(): string;
}
export declare class TupleExpression extends SqlComponent {
static kind: symbol;
values: ValueComponent[];
constructor(values: ValueComponent[]);
}
/**
* Represents a qualified name with optional namespaces (e.g. schema.table, db.schema.function)
*/
export declare class QualifiedName extends SqlComponent {
static kind: symbol;
/** List of namespaces (e.g. schema, database) */
namespaces: IdentifierString[] | null;
/** The actual name (e.g. table, function, type, column) */
name: RawString | IdentifierString;
constructor(namespaces: string | string[] | IdentifierString[] | null, name: string | RawString | IdentifierString);
/** Returns the full qualified name as a string (dot-separated) */
toString(): string;
}