rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
294 lines (293 loc) • 10.4 kB
TypeScript
import { SelectQuery } from "./SelectQuery";
import { SqlComponent } from "./SqlComponent";
import { IdentifierString, RawString, ValueComponent, WindowFrameExpression, QualifiedName } from "./ValueComponent";
export declare class SelectItem extends SqlComponent {
static kind: symbol;
value: ValueComponent;
identifier: IdentifierString | null;
constructor(value: ValueComponent, name?: string | null);
}
export declare class SelectClause extends SqlComponent {
static kind: symbol;
items: SelectItem[];
distinct: DistinctComponent | null;
constructor(items: SelectItem[], distinct?: DistinctComponent | null);
}
export type DistinctComponent = Distinct | DistinctOn;
export declare class Distinct extends SqlComponent {
static kind: symbol;
constructor();
}
export declare class DistinctOn extends SqlComponent {
static kind: symbol;
value: ValueComponent;
constructor(value: ValueComponent);
}
export declare class WhereClause extends SqlComponent {
static kind: symbol;
condition: ValueComponent;
constructor(condition: ValueComponent);
}
export declare class PartitionByClause extends SqlComponent {
static kind: symbol;
value: ValueComponent;
constructor(value: ValueComponent);
}
export declare class WindowFrameClause extends SqlComponent {
static kind: symbol;
name: IdentifierString;
expression: WindowFrameExpression;
constructor(name: string, expression: WindowFrameExpression);
}
/**
* Represents a collection of window definitions (WINDOW clause in SQL).
* @param windows Array of WindowFrameClause
*/
export declare class WindowsClause extends SqlComponent {
static kind: symbol;
windows: WindowFrameClause[];
constructor(windows: WindowFrameClause[]);
}
export declare enum SortDirection {
Ascending = "asc",
Descending = "desc"
}
export declare enum NullsSortDirection {
First = "first",
Last = "last"
}
export type OrderByComponent = OrderByItem | ValueComponent;
export declare class OrderByClause extends SqlComponent {
static kind: symbol;
order: OrderByComponent[];
constructor(items: OrderByComponent[]);
}
export declare class OrderByItem extends SqlComponent {
static kind: symbol;
value: ValueComponent;
sortDirection: SortDirection;
nullsPosition: NullsSortDirection | null;
constructor(expression: ValueComponent, sortDirection: SortDirection | null, nullsPosition: NullsSortDirection | null);
}
export declare class GroupByClause extends SqlComponent {
static kind: symbol;
grouping: ValueComponent[];
constructor(expression: ValueComponent[]);
}
export declare class HavingClause extends SqlComponent {
static kind: symbol;
condition: ValueComponent;
constructor(condition: ValueComponent);
}
export type SourceComponent = TableSource | FunctionSource | SubQuerySource | ParenSource;
export declare class TableSource extends SqlComponent {
static kind: symbol;
qualifiedName: QualifiedName;
/**
* For backward compatibility: returns the namespaces as IdentifierString[] | null (readonly)
*/
get namespaces(): IdentifierString[] | null;
/**
* For backward compatibility: returns the table name as IdentifierString (readonly)
*/
get table(): IdentifierString;
/**
* For backward compatibility: returns the table name as IdentifierString (readonly)
*/
get identifier(): IdentifierString;
constructor(namespaces: string[] | IdentifierString[] | null, table: string | IdentifierString);
getSourceName(): string;
}
export declare class FunctionSource extends SqlComponent {
static kind: symbol;
qualifiedName: QualifiedName;
argument: ValueComponent | null;
constructor(name: string | IdentifierString | {
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 function name as RawString | IdentifierString (readonly)
*/
get name(): RawString | IdentifierString;
}
export declare class ParenSource extends SqlComponent {
static kind: symbol;
source: SourceComponent;
constructor(source: SourceComponent);
}
export declare class SubQuerySource extends SqlComponent {
static kind: symbol;
query: SelectQuery;
constructor(query: SelectQuery);
}
export declare class SourceExpression extends SqlComponent {
static kind: symbol;
datasource: SourceComponent;
aliasExpression: SourceAliasExpression | null;
constructor(datasource: SourceComponent, aliasExpression: SourceAliasExpression | null);
getAliasName(): string | null;
}
export type JoinConditionComponent = JoinOnClause | JoinUsingClause;
export declare class JoinOnClause extends SqlComponent {
static kind: symbol;
condition: ValueComponent;
constructor(condition: ValueComponent);
}
export declare class JoinUsingClause extends SqlComponent {
static kind: symbol;
condition: ValueComponent;
constructor(condition: ValueComponent);
}
export declare class JoinClause extends SqlComponent {
static kind: symbol;
joinType: RawString;
source: SourceExpression;
condition: JoinConditionComponent | null;
lateral: boolean;
constructor(joinType: string, source: SourceExpression, condition: JoinConditionComponent | null, lateral: boolean);
getSourceAliasName(): string | null;
}
export declare class FromClause extends SqlComponent {
static kind: symbol;
source: SourceExpression;
joins: JoinClause[] | null;
constructor(source: SourceExpression, join: JoinClause[] | null);
getSourceAliasName(): string | null;
/**
* Returns all SourceExpression objects in this FROM clause, including main source and all JOIN sources.
*/
getSources(): SourceExpression[];
}
export declare class CommonTable extends SqlComponent {
static kind: symbol;
query: SelectQuery;
materialized: boolean | null;
aliasExpression: SourceAliasExpression;
constructor(query: SelectQuery, aliasExpression: SourceAliasExpression | string, materialized: boolean | null);
getSourceAliasName(): string;
}
export declare class WithClause extends SqlComponent {
static kind: symbol;
recursive: boolean;
tables: CommonTable[];
constructor(recursive: boolean, tables: CommonTable[]);
}
export declare class LimitClause extends SqlComponent {
static kind: symbol;
value: ValueComponent;
constructor(limit: ValueComponent);
}
export declare enum FetchType {
Next = "next",
First = "first"
}
export declare enum FetchUnit {
RowsOnly = "rows only",
Percent = "percent",
PercentWithTies = "percent with ties"
}
export declare class OffsetClause extends SqlComponent {
static kind: symbol;
value: ValueComponent;
constructor(value: ValueComponent);
}
export declare class FetchClause extends SqlComponent {
static kind: symbol;
expression: FetchExpression;
constructor(expression: FetchExpression);
}
export declare class FetchExpression extends SqlComponent {
static kind: symbol;
type: FetchType;
count: ValueComponent;
unit: FetchUnit | null;
constructor(type: FetchType, count: ValueComponent, unit: FetchUnit | null);
}
export declare enum LockMode {
Update = "update",
Share = "share",
KeyShare = "key share",
NokeyUpdate = "no key update"
}
export declare class ForClause extends SqlComponent {
static kind: symbol;
lockMode: LockMode;
constructor(lockMode: LockMode);
}
export declare class SourceAliasExpression extends SqlComponent {
static kind: symbol;
table: IdentifierString;
columns: IdentifierString[] | null;
constructor(alias: string, columnAlias: string[] | null);
}
export declare class ReturningClause extends SqlComponent {
static kind: symbol;
columns: IdentifierString[];
/**
* Constructs a ReturningClause.
* @param columns Array of IdentifierString or string representing column names.
*/
constructor(columns: (IdentifierString | string)[]);
}
export declare class SetClause extends SqlComponent {
static kind: symbol;
items: SetClauseItem[];
constructor(items: (SetClauseItem | {
column: string | IdentifierString;
value: ValueComponent;
})[]);
}
/**
* Represents a single SET clause item in an UPDATE statement.
*/
/**
* Represents a single SET clause item in an UPDATE statement.
* Now supports namespaces for fully qualified column names (e.g. schema.table.column).
*/
/**
* Represents a single SET clause item in an UPDATE statement.
* Now supports namespaces for fully qualified column names (e.g. schema.table.column).
* Refactored to use QualifiedName for unified name/namespace handling.
*/
export declare class SetClauseItem extends SqlComponent {
static kind: symbol;
qualifiedName: QualifiedName;
value: ValueComponent;
constructor(column: string | IdentifierString | {
namespaces: string[] | IdentifierString[] | null;
column: string | IdentifierString;
}, value: ValueComponent);
/**
* 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;
/**
* Returns the fully qualified column name as a string.
*/
getFullName(): string;
}
export declare class UpdateClause extends SqlComponent {
static kind: symbol;
source: SourceExpression;
constructor(source: SourceExpression);
getSourceAliasName(): string | null;
}
/**
* Represents the target table (with optional alias/schema) and columns for an INSERT statement.
* @param source The target table as a SourceExpression (can include schema, alias, etc.)
* @param columns Array of column names (as strings)
*/
export declare class InsertClause extends SqlComponent {
source: SourceExpression;
columns: IdentifierString[];
constructor(source: SourceExpression, columns: string[]);
}