rawsql-ts
Version:
High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
291 lines (290 loc) • 8.42 kB
TypeScript
import { SqlComponent } from "./SqlComponent";
import { QualifiedName, IdentifierString, ValueComponent, RawString } from "./ValueComponent";
import { TableConstraintDefinition, TableColumnDefinition } from "./CreateTableQuery";
export type DropBehavior = 'cascade' | 'restrict' | null;
export type IndexSortOrder = 'asc' | 'desc' | null;
export type IndexNullsOrder = 'first' | 'last' | null;
/**
* DROP TABLE statement representation.
*/
export declare class DropTableStatement extends SqlComponent {
static kind: symbol;
tables: QualifiedName[];
ifExists: boolean;
behavior: DropBehavior;
constructor(params: {
tables: QualifiedName[];
ifExists?: boolean;
behavior?: DropBehavior;
});
}
/**
* DROP INDEX statement representation.
*/
export declare class DropIndexStatement extends SqlComponent {
static kind: symbol;
indexNames: QualifiedName[];
ifExists: boolean;
concurrently: boolean;
behavior: DropBehavior;
constructor(params: {
indexNames: QualifiedName[];
ifExists?: boolean;
concurrently?: boolean;
behavior?: DropBehavior;
});
}
/**
* Column definition within CREATE INDEX clause.
*/
export declare class IndexColumnDefinition extends SqlComponent {
static kind: symbol;
expression: ValueComponent;
sortOrder: IndexSortOrder;
nullsOrder: IndexNullsOrder;
collation?: QualifiedName | null;
operatorClass?: QualifiedName | null;
constructor(params: {
expression: ValueComponent;
sortOrder?: IndexSortOrder;
nullsOrder?: IndexNullsOrder;
collation?: QualifiedName | null;
operatorClass?: QualifiedName | null;
});
}
/**
* CREATE INDEX statement representation.
*/
export declare class CreateIndexStatement extends SqlComponent {
static kind: symbol;
unique: boolean;
concurrently: boolean;
ifNotExists: boolean;
indexName: QualifiedName;
tableName: QualifiedName;
usingMethod?: IdentifierString | RawString | null;
columns: IndexColumnDefinition[];
include?: IdentifierString[] | null;
where?: ValueComponent;
withOptions?: RawString | null;
tablespace?: IdentifierString | null;
constructor(params: {
unique?: boolean;
concurrently?: boolean;
ifNotExists?: boolean;
indexName: QualifiedName;
tableName: QualifiedName;
usingMethod?: IdentifierString | RawString | null;
columns: IndexColumnDefinition[];
include?: IdentifierString[] | null;
where?: ValueComponent;
withOptions?: RawString | null;
tablespace?: IdentifierString | null;
});
}
/**
* ALTER TABLE ... ADD CONSTRAINT action.
*/
export declare class AlterTableAddConstraint extends SqlComponent {
static kind: symbol;
constraint: TableConstraintDefinition;
ifNotExists: boolean;
notValid: boolean;
constructor(params: {
constraint: TableConstraintDefinition;
ifNotExists?: boolean;
notValid?: boolean;
});
}
/**
* ALTER TABLE ... DROP CONSTRAINT action.
*/
export declare class AlterTableDropConstraint extends SqlComponent {
static kind: symbol;
constraintName: IdentifierString;
ifExists: boolean;
behavior: DropBehavior;
constructor(params: {
constraintName: IdentifierString;
ifExists?: boolean;
behavior?: DropBehavior;
});
}
/**
* ALTER TABLE ... DROP COLUMN action.
*/
export declare class AlterTableDropColumn extends SqlComponent {
static kind: symbol;
columnName: IdentifierString;
ifExists: boolean;
behavior: DropBehavior;
constructor(params: {
columnName: IdentifierString;
ifExists?: boolean;
behavior?: DropBehavior;
});
}
/**
* ALTER TABLE ... ADD COLUMN action.
*/
export declare class AlterTableAddColumn extends SqlComponent {
static kind: symbol;
column: TableColumnDefinition;
ifNotExists: boolean;
constructor(params: {
column: TableColumnDefinition;
ifNotExists?: boolean;
});
}
/**
* ALTER TABLE ... ALTER COLUMN ... SET/DROP DEFAULT action.
*/
export declare class AlterTableAlterColumnDefault extends SqlComponent {
static kind: symbol;
columnName: IdentifierString;
setDefault: ValueComponent | null;
dropDefault: boolean;
constructor(params: {
columnName: IdentifierString;
setDefault?: ValueComponent | null;
dropDefault?: boolean;
});
}
export type AlterTableAction = AlterTableAddConstraint | AlterTableDropConstraint | AlterTableDropColumn | AlterTableAddColumn | AlterTableAlterColumnDefault;
/**
* ALTER TABLE statement representation with constraint-centric actions.
*/
export declare class AlterTableStatement extends SqlComponent {
static kind: symbol;
table: QualifiedName;
only: boolean;
ifExists: boolean;
actions: AlterTableAction[];
constructor(params: {
table: QualifiedName;
only?: boolean;
ifExists?: boolean;
actions: AlterTableAction[];
});
}
/**
* Standalone DROP CONSTRAINT statement representation.
*/
export declare class DropConstraintStatement extends SqlComponent {
static kind: symbol;
constraintName: IdentifierString;
ifExists: boolean;
behavior: DropBehavior;
constructor(params: {
constraintName: IdentifierString;
ifExists?: boolean;
behavior?: DropBehavior;
});
}
/**
* Option entry within an EXPLAIN statement.
*/
export declare class ExplainOption extends SqlComponent {
static kind: symbol;
name: IdentifierString;
value: ValueComponent | null;
constructor(params: {
name: IdentifierString;
value?: ValueComponent | null;
});
}
/**
* EXPLAIN statement representation.
*/
export declare class ExplainStatement extends SqlComponent {
static kind: symbol;
options: ExplainOption[] | null;
statement: SqlComponent;
constructor(params: {
options?: ExplainOption[] | null;
statement: SqlComponent;
});
}
/**
* ANALYZE statement representation.
*/
export declare class AnalyzeStatement extends SqlComponent {
static kind: symbol;
verbose: boolean;
target: QualifiedName | null;
columns: IdentifierString[] | null;
constructor(params?: {
verbose?: boolean;
target?: QualifiedName | null;
columns?: IdentifierString[] | null;
});
}
/**
* Sequence option clauses are collected in order and emitted as the user wrote them.
* Each clause is specialized by its discriminating `kind`.
*/
export interface SequenceIncrementClause {
kind: "increment";
value: ValueComponent;
}
export interface SequenceStartClause {
kind: "start";
value: ValueComponent;
}
export interface SequenceMinValueClause {
kind: "minValue";
value?: ValueComponent;
noValue?: boolean;
}
export interface SequenceMaxValueClause {
kind: "maxValue";
value?: ValueComponent;
noValue?: boolean;
}
export interface SequenceCacheClause {
kind: "cache";
value?: ValueComponent;
noValue?: boolean;
}
export interface SequenceCycleClause {
kind: "cycle";
enabled: boolean;
}
export interface SequenceRestartClause {
kind: "restart";
value?: ValueComponent;
}
export interface SequenceOwnedByClause {
kind: "ownedBy";
target?: QualifiedName;
none?: boolean;
}
export type SequenceOptionClause = SequenceIncrementClause | SequenceStartClause | SequenceMinValueClause | SequenceMaxValueClause | SequenceCacheClause | SequenceCycleClause | SequenceRestartClause | SequenceOwnedByClause;
/**
* CREATE SEQUENCE statement representation.
*/
export declare class CreateSequenceStatement extends SqlComponent {
static kind: symbol;
sequenceName: QualifiedName;
ifNotExists: boolean;
clauses: SequenceOptionClause[];
constructor(params: {
sequenceName: QualifiedName;
ifNotExists?: boolean;
clauses?: SequenceOptionClause[];
});
}
/**
* ALTER SEQUENCE statement representation.
*/
export declare class AlterSequenceStatement extends SqlComponent {
static kind: symbol;
sequenceName: QualifiedName;
ifExists: boolean;
clauses: SequenceOptionClause[];
constructor(params: {
sequenceName: QualifiedName;
ifExists?: boolean;
clauses?: SequenceOptionClause[];
});
}