rawsql-ts
Version:
High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
122 lines (121 loc) • 4.55 kB
TypeScript
import { SqlComponent } from "./SqlComponent";
import type { SelectQuery } from "./SelectQuery";
import { IdentifierString, RawString, ValueComponent, TypeValue, QualifiedName } from "./ValueComponent";
import { SimpleSelectQuery } from "./SimpleSelectQuery";
export type ReferentialAction = 'cascade' | 'restrict' | 'no action' | 'set null' | 'set default';
export type ConstraintDeferrability = 'deferrable' | 'not deferrable' | null;
export type ConstraintInitially = 'immediate' | 'deferred' | null;
export type MatchType = 'full' | 'partial' | 'simple' | null;
/**
* Represents a REFERENCES clause definition that can be shared between column and table constraints.
*/
export declare class ReferenceDefinition extends SqlComponent {
static kind: symbol;
targetTable: QualifiedName;
columns: IdentifierString[] | null;
matchType: MatchType;
onDelete: ReferentialAction | null;
onUpdate: ReferentialAction | null;
deferrable: ConstraintDeferrability;
initially: ConstraintInitially;
constructor(params: {
targetTable: QualifiedName;
columns?: IdentifierString[] | null;
matchType?: MatchType;
onDelete?: ReferentialAction | null;
onUpdate?: ReferentialAction | null;
deferrable?: ConstraintDeferrability;
initially?: ConstraintInitially;
});
}
export type ColumnConstraintKind = 'not-null' | 'null' | 'default' | 'primary-key' | 'unique' | 'references' | 'check' | 'generated-always-identity' | 'generated-by-default-identity' | 'raw';
/**
* Column-level constraint definition.
*/
export declare class ColumnConstraintDefinition extends SqlComponent {
static kind: symbol;
kind: ColumnConstraintKind;
constraintName?: IdentifierString;
defaultValue?: ValueComponent;
checkExpression?: ValueComponent;
reference?: ReferenceDefinition;
rawClause?: RawString;
constructor(params: {
kind: ColumnConstraintKind;
constraintName?: IdentifierString;
defaultValue?: ValueComponent;
checkExpression?: ValueComponent;
reference?: ReferenceDefinition;
rawClause?: RawString;
});
}
export type TableConstraintKind = 'primary-key' | 'unique' | 'foreign-key' | 'check' | 'raw';
/**
* Table-level constraint definition.
*/
export declare class TableConstraintDefinition extends SqlComponent {
static kind: symbol;
kind: TableConstraintKind;
constraintName?: IdentifierString;
columns: IdentifierString[] | null;
reference?: ReferenceDefinition;
checkExpression?: ValueComponent;
rawClause?: RawString;
deferrable: ConstraintDeferrability;
initially: ConstraintInitially;
constructor(params: {
kind: TableConstraintKind;
constraintName?: IdentifierString;
columns?: IdentifierString[] | null;
reference?: ReferenceDefinition;
checkExpression?: ValueComponent;
rawClause?: RawString;
deferrable?: ConstraintDeferrability;
initially?: ConstraintInitially;
});
}
/**
* Represents a single column definition within CREATE TABLE.
*/
export declare class TableColumnDefinition extends SqlComponent {
static kind: symbol;
name: IdentifierString;
dataType?: TypeValue | RawString;
constraints: ColumnConstraintDefinition[];
constructor(params: {
name: IdentifierString;
dataType?: TypeValue | RawString;
constraints?: ColumnConstraintDefinition[];
});
}
export declare class CreateTableQuery extends SqlComponent {
static kind: symbol;
tableName: IdentifierString;
namespaces: string[] | null;
isTemporary: boolean;
ifNotExists: boolean;
columns: TableColumnDefinition[];
tableConstraints: TableConstraintDefinition[];
tableOptions?: RawString | null;
asSelectQuery?: SelectQuery;
withDataOption: 'with-data' | 'with-no-data' | null;
constructor(params: {
tableName: string;
namespaces?: string[] | null;
isTemporary?: boolean;
ifNotExists?: boolean;
columns?: TableColumnDefinition[];
tableConstraints?: TableConstraintDefinition[];
tableOptions?: RawString | null;
asSelectQuery?: SelectQuery;
withDataOption?: 'with-data' | 'with-no-data' | null;
});
/**
* Returns a SelectQuery that selects all columns from this table.
*/
getSelectQuery(): SimpleSelectQuery;
/**
* Returns a SelectQuery that counts all rows in this table.
*/
getCountQuery(): SimpleSelectQuery;
}