sql-parser-cst
Advanced tools
Comparing version 0.7.0 to 0.8.0
import { BaseNode, Keyword } from "./Base"; | ||
import { ColumnDefinition } from "./CreateTable"; | ||
import { Identifier, ListExpr, TableRef } from "./Expr"; | ||
import { Identifier, ListExpr, Table } from "./Expr"; | ||
export interface AlterTableStmt extends BaseNode { | ||
type: "alter_table_stmt"; | ||
alterTableKw: [Keyword<"ALTER">, Keyword<"TABLE">]; | ||
table: TableRef; | ||
table: Table; | ||
actions: ListExpr<AlterAction>; | ||
@@ -14,3 +14,3 @@ } | ||
renameKw: Keyword<"RENAME"> | [Keyword<"RENAME">, Keyword<"TO" | "AS">]; | ||
newName: TableRef; | ||
newName: Table; | ||
} | ||
@@ -17,0 +17,0 @@ export interface AlterRenameColumn extends BaseNode { |
import { BaseNode, Keyword } from "./Base"; | ||
import { ListExpr, TableRef } from "./Expr"; | ||
import { ListExpr, Table } from "./Expr"; | ||
export interface AnalyzeStmt extends BaseNode { | ||
@@ -7,3 +7,3 @@ type: "analyze_stmt"; | ||
tableKw?: Keyword<"TABLE">; | ||
tables: ListExpr<TableRef>; | ||
tables: ListExpr<Table>; | ||
} |
import { BaseNode, Keyword } from "./Base"; | ||
import { StringLiteral } from "./Literal"; | ||
import { Expr, Identifier, ListExpr, ParenExpr, TableRef } from "./Expr"; | ||
import { Expr, Identifier, ListExpr, ParenExpr, Table } from "./Expr"; | ||
import { SortSpecification } from "./Select"; | ||
@@ -39,3 +39,3 @@ export declare type AllConstraintNodes = Constraint<ColumnConstraint | TableConstraint> | ColumnConstraint | TableConstraint | ConstraintName | ConstraintDeferrable | ReferencesSpecification | ReferentialAction | ReferentialMatch | OnConflictClause; | ||
referencesKw: Keyword<"REFERENCES">; | ||
table: TableRef; | ||
table: Table; | ||
columns?: ParenExpr<ListExpr<Identifier>>; | ||
@@ -42,0 +42,0 @@ options: (ReferentialAction | ReferentialMatch)[]; |
import { BaseNode, Keyword } from "./Base"; | ||
import { ColumnConstraint, Constraint, TableConstraint } from "./Constraint"; | ||
import { Identifier, ListExpr, PairExpr, ParenExpr, TableRef } from "./Expr"; | ||
import { Identifier, ListExpr, PairExpr, ParenExpr, Table } from "./Expr"; | ||
import { Literal, NumberLiteral, StringLiteral } from "./Literal"; | ||
@@ -13,3 +13,3 @@ import { SubSelect } from "./Select"; | ||
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">]; | ||
table: TableRef; | ||
table: Table; | ||
columns?: ParenExpr<ListExpr<ColumnDefinition | TableConstraint | Constraint<TableConstraint>>>; | ||
@@ -16,0 +16,0 @@ options?: ListExpr<TableOption>; |
import { Alias } from "./Alias"; | ||
import { BaseNode, Keyword } from "./Base"; | ||
import { TableRef } from "./Expr"; | ||
import { Table } from "./Expr"; | ||
import { ReturningClause, WhereClause, WithClause } from "./Select"; | ||
@@ -10,5 +10,5 @@ export interface DeleteStmt extends BaseNode { | ||
fromKw: Keyword<"FROM">; | ||
table: TableRef | Alias<TableRef>; | ||
table: Table | Alias<Table>; | ||
where?: WhereClause; | ||
returning?: ReturningClause; | ||
} |
import { BaseNode, Keyword } from "./Base"; | ||
import { ListExpr, TableRef } from "./Expr"; | ||
import { ListExpr, Table } from "./Expr"; | ||
export interface DropTableStmt extends BaseNode { | ||
@@ -9,4 +9,4 @@ type: "drop_table_stmt"; | ||
ifExistsKw?: [Keyword<"IF">, Keyword<"EXISTS">]; | ||
tables: ListExpr<TableRef>; | ||
tables: ListExpr<Table>; | ||
behaviorKw?: Keyword<"CASCADE" | "RESTRICT">; | ||
} |
@@ -1,8 +0,8 @@ | ||
import { AllColumns, BaseNode, Keyword } from "./Base"; | ||
import { AllColumns, BaseNode, Empty, Keyword } from "./Base"; | ||
import { DataType } from "./CreateTable"; | ||
import { Literal, StringLiteral } from "./Literal"; | ||
import { Node } from "./Node"; | ||
import { SubSelect, WhereClause, WindowDefinition } from "./Select"; | ||
export declare type AllExprNodes = Expr | DistinctArg | CastArg | ExtractFrom | FilterArg | OverArg | CaseWhen | CaseElse | IntervalUnitRange | PairExpr | WeekExpr | ArraySubscript | ArraySubscriptSpecifier; | ||
export declare type Expr = ListExpr | ParenExpr | BinaryExpr | PrefixOpExpr | PostfixOpExpr | FuncCall | TableFuncCall | CastExpr | RaiseExpr | ExtractExpr | BetweenExpr | CaseExpr | IntervalExpr | StringWithCharset | Literal | MemberExpr | TableRef | Identifier | Parameter | TypedExpr | ArrayExpr | StructExpr; | ||
import { LimitClause, OrderByClause, SubSelect, WhereClause, WindowDefinition } from "./Select"; | ||
export declare type AllExprNodes = Expr | FuncArgs | NamedArg | CastArg | CastFormat | ExtractFrom | FilterArg | OverArg | CaseWhen | CaseElse | IntervalUnitRange | PairExpr | WeekExpr | ArraySubscript | ArraySubscriptSpecifier; | ||
export declare type Expr = ListExpr | ParenExpr | BinaryExpr | PrefixOpExpr | PostfixOpExpr | FuncCall | CastExpr | RaiseExpr | ExtractExpr | BetweenExpr | CaseExpr | IntervalExpr | StringWithCharset | Literal | MemberExpr | BigQueryQuotedMemberExpr | Identifier | Parameter | TypedExpr | ArrayExpr | StructExpr; | ||
export interface ListExpr<T = Node> extends BaseNode { | ||
@@ -39,11 +39,14 @@ type: "list_expr"; | ||
type: "func_call"; | ||
name: Identifier; | ||
args?: ParenExpr<ListExpr<Expr | AllColumns | DistinctArg | SubSelect>>; | ||
name: Identifier | MemberExpr; | ||
args?: ParenExpr<FuncArgs>; | ||
filter?: FilterArg; | ||
over?: OverArg; | ||
} | ||
export interface TableFuncCall extends BaseNode { | ||
type: "table_func_call"; | ||
name: TableRef; | ||
args: ParenExpr<ListExpr<Expr>>; | ||
export interface FuncArgs extends BaseNode { | ||
type: "func_args"; | ||
distinctKw?: Keyword<"DISTINCT">; | ||
args: ListExpr<Expr | AllColumns | SubSelect | NamedArg>; | ||
nullHandlingKw?: [Keyword<"IGNORE" | "RESPECT">, Keyword<"NULLS">]; | ||
orderBy?: OrderByClause; | ||
limit?: LimitClause; | ||
} | ||
@@ -60,5 +63,5 @@ export interface FilterArg extends BaseNode { | ||
} | ||
export interface DistinctArg extends BaseNode { | ||
type: "distinct_arg"; | ||
distinctKw: Keyword<"DISTINCT">; | ||
export interface NamedArg extends BaseNode { | ||
type: "named_arg"; | ||
name: Identifier; | ||
value: Expr; | ||
@@ -76,3 +79,9 @@ } | ||
dataType: DataType; | ||
format?: CastFormat; | ||
} | ||
export interface CastFormat extends BaseNode { | ||
type: "cast_format"; | ||
formatKw: Keyword<"FORMAT">; | ||
string: Expr; | ||
} | ||
export interface RaiseExpr extends BaseNode { | ||
@@ -147,4 +156,9 @@ type: "raise_expr"; | ||
object: Expr; | ||
property: ArraySubscript | Identifier | AllColumns; | ||
property: ArraySubscript | Identifier | AllColumns | Empty; | ||
} | ||
export interface BigQueryQuotedMemberExpr extends BaseNode { | ||
type: "bigquery_quoted_member_expr"; | ||
expr: MemberExpr; | ||
} | ||
export declare type Table = MemberExpr | Identifier | BigQueryQuotedMemberExpr; | ||
export interface ArraySubscript extends BaseNode { | ||
@@ -159,8 +173,2 @@ type: "array_subscript"; | ||
} | ||
export interface TableRef extends BaseNode { | ||
type: "table_ref"; | ||
catalog?: Identifier; | ||
schema?: Identifier; | ||
table: Identifier; | ||
} | ||
export interface Identifier extends BaseNode { | ||
@@ -167,0 +175,0 @@ type: "identifier"; |
import { BaseNode, Keyword } from "./Base"; | ||
import { Identifier, ListExpr, ParenExpr, TableRef } from "./Expr"; | ||
import { Identifier, ListExpr, ParenExpr, Table } from "./Expr"; | ||
import { SortSpecification, WhereClause } from "./Select"; | ||
@@ -10,5 +10,5 @@ export interface CreateIndexStmt extends BaseNode { | ||
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">]; | ||
name: TableRef; | ||
name: Table; | ||
onKw: Keyword<"ON">; | ||
table: TableRef; | ||
table: Table; | ||
columns: ParenExpr<ListExpr<SortSpecification | Identifier>>; | ||
@@ -21,5 +21,5 @@ where?: WhereClause; | ||
ifExistsKw?: [Keyword<"IF">, Keyword<"EXISTS">]; | ||
indexes: ListExpr<TableRef>; | ||
indexes: ListExpr<Table>; | ||
onKw?: Keyword<"ON">; | ||
table?: TableRef; | ||
table?: Table; | ||
} |
import { BaseNode, Keyword } from "./Base"; | ||
import { Expr, Identifier, ListExpr, ParenExpr, TableRef } from "./Expr"; | ||
import { Expr, Identifier, ListExpr, ParenExpr, Table } from "./Expr"; | ||
import { Alias } from "./Alias"; | ||
@@ -17,3 +17,3 @@ import { ReturningClause, SortSpecification, SubSelect, WhereClause, WithClause } from "./Select"; | ||
intoKw?: Keyword<"INTO">; | ||
table: TableRef | Alias<TableRef>; | ||
table: Table | Alias<Table>; | ||
columns?: ParenExpr<ListExpr<Identifier>>; | ||
@@ -20,0 +20,0 @@ } |
import { BaseNode, Keyword } from "./Base"; | ||
export declare type Literal = StringLiteral | NumberLiteral | BlobLiteral | BooleanLiteral | NullLiteral | DateTimeLiteral; | ||
export declare type Literal = StringLiteral | NumberLiteral | BlobLiteral | BooleanLiteral | NullLiteral | DateTimeLiteral | JsonLiteral | NumericLiteral; | ||
export interface StringLiteral extends BaseNode { | ||
@@ -33,1 +33,11 @@ type: "string"; | ||
} | ||
export interface JsonLiteral extends BaseNode { | ||
type: "json"; | ||
jsonKw: Keyword<"JSON">; | ||
string: StringLiteral; | ||
} | ||
export interface NumericLiteral extends BaseNode { | ||
type: "numeric"; | ||
numericKw: Keyword<"NUMERIC" | "BIGNUMERIC">; | ||
string: StringLiteral; | ||
} |
@@ -1,6 +0,6 @@ | ||
import { BaseNode, Empty, Keyword } from "./Base"; | ||
import { Expr, FuncCall, Identifier, ListExpr, ParenExpr, TableFuncCall, TableRef } from "./Expr"; | ||
import { AllColumns, BaseNode, Empty, Keyword } from "./Base"; | ||
import { Expr, FuncCall, Identifier, ListExpr, MemberExpr, ParenExpr, Table } from "./Expr"; | ||
import { Alias } from "./Alias"; | ||
import { FrameClause } from "./WindowFrame"; | ||
export declare type AllSelectNodes = CompoundSelectStmt | SelectStmt | WithClause | CommonTableExpression | SelectClause | FromClause | WhereClause | GroupByClause | HavingClause | WindowClause | QualifyClause | NamedWindow | WindowDefinition | OrderByClause | PartitionByClause | LimitClause | JoinExpr | IndexedTableRef | NotIndexedTableRef | UnnestExpr | PivotExpr | PivotForIn | JoinOnSpecification | JoinUsingSpecification | SortSpecification | ReturningClause; | ||
export declare type AllSelectNodes = CompoundSelectStmt | SelectStmt | WithClause | CommonTableExpression | SelectClause | ExceptColumns | ReplaceColumns | FromClause | WhereClause | GroupByClause | GroupByRollup | HavingClause | WindowClause | QualifyClause | NamedWindow | WindowDefinition | OrderByClause | PartitionByClause | LimitClause | JoinExpr | IndexedTable | NotIndexedTable | UnnestWithOffsetExpr | UnnestExpr | PivotExpr | PivotForIn | UnpivotExpr | UnpivotForIn | TablesampleExpr | TablesamplePercent | JoinOnSpecification | JoinUsingSpecification | SortSpecification | ReturningClause; | ||
export interface CompoundSelectStmt extends BaseNode { | ||
@@ -34,9 +34,23 @@ type: "compound_select_stmt"; | ||
selectKw: Keyword<"SELECT">; | ||
options: Keyword<"ALL" | "DISTINCT" | "DISTINCTROW" | "HIGH_PRIORITY" | "STRAIGHT_JOIN" | "SQL_CALC_FOUND_ROWS" | "SQL_CACHE" | "SQL_NO_CACHE" | "SQL_BIG_RESULT" | "SQL_SMALL_RESULT" | "SQL_BUFFER_RESULT">[]; | ||
columns: ListExpr<Expr | Alias<Expr> | Empty>; | ||
distinctKw?: Keyword<"ALL" | "DISTINCT" | "DISTINCTROW">; | ||
options: Keyword<"HIGH_PRIORITY" | "STRAIGHT_JOIN" | "SQL_CALC_FOUND_ROWS" | "SQL_CACHE" | "SQL_NO_CACHE" | "SQL_BIG_RESULT" | "SQL_SMALL_RESULT" | "SQL_BUFFER_RESULT">[]; | ||
asStructOrValueKw?: [Keyword<"AS">, Keyword<"STRUCT" | "VALUE">]; | ||
columns: ListExpr<AllColumns | ExceptColumns | ReplaceColumns | Expr | Alias<Expr> | Empty>; | ||
} | ||
export interface ExceptColumns extends BaseNode { | ||
type: "except_columns"; | ||
expr: MemberExpr | AllColumns; | ||
exceptKw: Keyword<"EXCEPT">; | ||
columns: ParenExpr<ListExpr<Identifier>>; | ||
} | ||
export interface ReplaceColumns extends BaseNode { | ||
type: "replace_columns"; | ||
expr: MemberExpr | AllColumns; | ||
replaceKw: Keyword<"REPLACE">; | ||
columns: ParenExpr<ListExpr<Alias<Expr>>>; | ||
} | ||
export interface FromClause extends BaseNode { | ||
type: "from_clause"; | ||
fromKw: Keyword<"FROM">; | ||
expr: JoinExprLeft; | ||
expr: TableExpr; | ||
} | ||
@@ -51,4 +65,9 @@ export interface WhereClause extends BaseNode { | ||
groupByKw: [Keyword<"GROUP">, Keyword<"BY">]; | ||
columns: ListExpr<Expr>; | ||
columns: ListExpr<Expr> | GroupByRollup; | ||
} | ||
export interface GroupByRollup extends BaseNode { | ||
type: "group_by_rollup"; | ||
rollupKw: Keyword<"ROLLUP">; | ||
columns: ParenExpr<ListExpr<Expr>>; | ||
} | ||
export interface HavingClause extends BaseNode { | ||
@@ -95,6 +114,6 @@ type: "having_clause"; | ||
} | ||
declare type JoinExprLeft = JoinExpr | PivotExpr | TableOrSubquery; | ||
declare type TableExpr = JoinExpr | PivotExpr | UnpivotExpr | TablesampleExpr | TableOrSubquery; | ||
export interface JoinExpr extends BaseNode { | ||
type: "join_expr"; | ||
left: JoinExprLeft; | ||
left: TableExpr; | ||
operator: JoinOp | ","; | ||
@@ -105,14 +124,19 @@ right: TableOrSubquery; | ||
declare type JoinOp = Keyword<"NATURAL" | "LEFT" | "RIGHT" | "FULL" | "OUTER" | "INNER" | "CROSS" | "JOIN">[] | Keyword<"JOIN" | "STRAIGHT_JOIN">; | ||
export declare type TableOrSubquery = TableRef | TableFuncCall | IndexedTableRef | NotIndexedTableRef | ParenExpr<SubSelect | JoinExprLeft> | UnnestExpr | Alias<TableOrSubquery>; | ||
export interface IndexedTableRef extends BaseNode { | ||
type: "indexed_table_ref"; | ||
table: TableRef | Alias<TableRef>; | ||
export declare type TableOrSubquery = Table | FuncCall | IndexedTable | NotIndexedTable | ParenExpr<SubSelect | TableExpr> | UnnestWithOffsetExpr | UnnestExpr | Alias<TableOrSubquery>; | ||
export interface IndexedTable extends BaseNode { | ||
type: "indexed_table"; | ||
table: Table | Alias<Table>; | ||
indexedByKw: [Keyword<"INDEXED">, Keyword<"BY">]; | ||
index: Identifier; | ||
} | ||
export interface NotIndexedTableRef extends BaseNode { | ||
type: "not_indexed_table_ref"; | ||
table: TableRef | Alias<TableRef>; | ||
export interface NotIndexedTable extends BaseNode { | ||
type: "not_indexed_table"; | ||
table: Table | Alias<Table>; | ||
notIndexedKw: [Keyword<"NOT">, Keyword<"INDEXED">]; | ||
} | ||
export interface UnnestWithOffsetExpr extends BaseNode { | ||
type: "unnest_with_offset_expr"; | ||
unnest: UnnestExpr | MemberExpr | Identifier | Alias<UnnestExpr | MemberExpr | Identifier>; | ||
withOffsetKw: [Keyword<"WITH">, Keyword<"OFFSET">]; | ||
} | ||
export interface UnnestExpr extends BaseNode { | ||
@@ -125,3 +149,3 @@ type: "unnest_expr"; | ||
type: "pivot_expr"; | ||
left: JoinExprLeft; | ||
left: TableExpr; | ||
pivotKw: Keyword<"PIVOT">; | ||
@@ -138,2 +162,28 @@ args: ParenExpr<PivotForIn>; | ||
} | ||
export interface UnpivotExpr extends BaseNode { | ||
type: "unpivot_expr"; | ||
left: TableExpr; | ||
unpivotKw: Keyword<"UNPIVOT">; | ||
nullHandlingKw?: [Keyword<"INCLUDE" | "EXCLUDE">, Keyword<"NULLS">]; | ||
args: ParenExpr<UnpivotForIn>; | ||
} | ||
export interface UnpivotForIn extends BaseNode { | ||
type: "unpivot_for_in"; | ||
valuesColumn: Identifier | ParenExpr<ListExpr<Identifier>>; | ||
forKw: Keyword<"FOR">; | ||
nameColumn: Identifier; | ||
inKw: Keyword<"IN">; | ||
unpivotColumns: ParenExpr<ListExpr<Identifier | Alias<Expr>>> | ParenExpr<ListExpr<ParenExpr<ListExpr<Identifier>> | Alias<ParenExpr<ListExpr<Identifier>>>>>; | ||
} | ||
export interface TablesampleExpr extends BaseNode { | ||
type: "tablesample_expr"; | ||
left: TableExpr; | ||
tablesampleKw: [Keyword<"TABLESAMPLE">, Keyword<"SYSTEM">]; | ||
args: ParenExpr<TablesamplePercent>; | ||
} | ||
export interface TablesamplePercent extends BaseNode { | ||
type: "tablesample_percent"; | ||
percent: Expr; | ||
percentKw: Keyword<"PERCENT">; | ||
} | ||
export interface JoinOnSpecification extends BaseNode { | ||
@@ -140,0 +190,0 @@ type: "join_on_specification"; |
import { BaseNode, Keyword } from "./Base"; | ||
import { Expr, FuncCall, Identifier, ParenExpr, TableRef } from "./Expr"; | ||
import { Expr, FuncCall, Identifier, ParenExpr, Table } from "./Expr"; | ||
import { Literal, StringLiteral } from "./Literal"; | ||
@@ -30,3 +30,3 @@ export declare type AllSqliteNodes = SqliteStmt | PragmaAssignment | PragmaFuncCall; | ||
reindexKw: Keyword<"REINDEX">; | ||
table?: TableRef; | ||
table?: Table; | ||
} | ||
@@ -36,7 +36,7 @@ export interface PragmaStmt extends BaseNode { | ||
pragmaKw: Keyword<"PRAGMA">; | ||
pragma: TableRef | PragmaAssignment | PragmaFuncCall; | ||
pragma: Table | PragmaAssignment | PragmaFuncCall; | ||
} | ||
export interface PragmaAssignment extends BaseNode { | ||
type: "pragma_assignment"; | ||
name: TableRef; | ||
name: Table; | ||
value: Literal | Keyword; | ||
@@ -46,3 +46,3 @@ } | ||
type: "pragma_func_call"; | ||
name: TableRef; | ||
name: Table; | ||
args: ParenExpr<Literal | Keyword>; | ||
@@ -58,5 +58,5 @@ } | ||
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">]; | ||
table: TableRef; | ||
table: Table; | ||
usingKw: Keyword<"USING">; | ||
module: FuncCall; | ||
} |
import { BaseNode, Keyword } from "./Base"; | ||
import { Expr, Identifier, ListExpr, TableRef } from "./Expr"; | ||
import { Expr, Identifier, ListExpr, Table } from "./Expr"; | ||
import { Program } from "./Program"; | ||
@@ -11,6 +11,6 @@ export declare type AllTriggerNodes = CreateTriggerStmt | DropTriggerStmt | TriggerEvent | TriggerCondition | TriggerBody | TriggerCondition | TriggerBody; | ||
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">]; | ||
name: TableRef; | ||
name: Table; | ||
event: TriggerEvent; | ||
onKw: Keyword<"ON">; | ||
table: TableRef; | ||
table: Table; | ||
forEachRowKw?: [Keyword<"FOR">, Keyword<"EACH">, Keyword<"ROW">]; | ||
@@ -42,3 +42,3 @@ condition?: TriggerCondition; | ||
ifExistsKw?: [Keyword<"IF">, Keyword<"EXISTS">]; | ||
trigger: TableRef; | ||
trigger: Table; | ||
} |
import { Alias } from "./Alias"; | ||
import { BaseNode, Keyword } from "./Base"; | ||
import { Expr, Identifier, ListExpr, MemberExpr, ParenExpr, TableRef } from "./Expr"; | ||
import { Expr, Identifier, ListExpr, MemberExpr, ParenExpr, Table } from "./Expr"; | ||
import { Default, OrAlternateAction, UpsertOption } from "./Insert"; | ||
@@ -16,3 +16,3 @@ import { FromClause, LimitClause, OrderByClause, ReturningClause, WhereClause, WithClause } from "./Select"; | ||
orAction?: OrAlternateAction; | ||
tables: ListExpr<TableRef | Alias<TableRef>>; | ||
tables: ListExpr<Table | Alias<Table>>; | ||
} | ||
@@ -19,0 +19,0 @@ export interface SetClause extends BaseNode { |
import { BaseNode, Keyword } from "./Base"; | ||
import { Identifier, ListExpr, ParenExpr, TableRef } from "./Expr"; | ||
import { Identifier, ListExpr, ParenExpr, Table } from "./Expr"; | ||
import { SubSelect } from "./Select"; | ||
@@ -10,3 +10,3 @@ export interface CreateViewStmt extends BaseNode { | ||
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">]; | ||
name: TableRef; | ||
name: Table; | ||
columns?: ParenExpr<ListExpr<Identifier>>; | ||
@@ -20,4 +20,4 @@ asKw: Keyword<"AS">; | ||
ifExistsKw?: [Keyword<"IF">, Keyword<"EXISTS">]; | ||
views: ListExpr<TableRef>; | ||
views: ListExpr<Table>; | ||
behaviorKw?: Keyword<"CASCADE" | "RESTRICT">; | ||
} |
@@ -75,5 +75,2 @@ "use strict"; | ||
: [layout(node.object), ".", layout(node.property)], | ||
table_ref: (node) => node.schema | ||
? [layout(node.schema), ".", layout(node.table)] | ||
: layout(node.table), | ||
alias: (node) => node.asKw | ||
@@ -80,0 +77,0 @@ ? layout([node.expr, node.asKw, node.alias]) |
@@ -42,3 +42,11 @@ "use strict"; | ||
// SELECT | ||
select_clause: (node) => show([node.selectKw, node.options, node.columns]), | ||
select_clause: (node) => show([ | ||
node.selectKw, | ||
node.distinctKw, | ||
node.options, | ||
node.asStructOrValueKw, | ||
node.columns, | ||
]), | ||
except_columns: (node) => show([node.expr, node.exceptKw, node.columns]), | ||
replace_columns: (node) => show([node.expr, node.replaceKw, node.columns]), | ||
// FROM | ||
@@ -57,2 +65,12 @@ from_clause: (node) => show([node.fromKw, node.expr]), | ||
]), | ||
unpivot_expr: (node) => show([node.left, node.unpivotKw, node.nullHandlingKw, node.args]), | ||
unpivot_for_in: (node) => show([ | ||
node.valuesColumn, | ||
node.forKw, | ||
node.nameColumn, | ||
node.inKw, | ||
node.unpivotColumns, | ||
]), | ||
tablesample_expr: (node) => show([node.left, node.tablesampleKw, node.args]), | ||
tablesample_percent: (node) => show([node.percent, node.percentKw]), | ||
sort_specification: (node) => show([node.expr, node.orderKw, node.nullHandlingKw]), | ||
@@ -62,2 +80,3 @@ // WHERE .. GROUP BY .. HAVING .. QUALIFY ... ORDER BY .. PARTITION BY | ||
group_by_clause: (node) => show([node.groupByKw, node.columns]), | ||
group_by_rollup: (node) => show([node.rollupKw, node.columns]), | ||
having_clause: (node) => show([node.havingKw, node.expr]), | ||
@@ -271,6 +290,13 @@ qualify_clause: (node) => show([node.qualifyKw, node.expr]), | ||
func_call: (node) => show([node.name, node.args, node.filter, node.over]), | ||
table_func_call: (node) => show([node.name, node.args]), | ||
distinct_arg: (node) => show([node.distinctKw, node.value]), | ||
func_args: (node) => show([ | ||
node.distinctKw, | ||
node.args, | ||
node.nullHandlingKw, | ||
node.orderBy, | ||
node.limit, | ||
]), | ||
named_arg: (node) => show([node.name, "=>", node.value]), | ||
cast_expr: (node) => show([node.castKw, node.args]), | ||
cast_arg: (node) => show([node.expr, node.asKw, node.dataType]), | ||
cast_arg: (node) => show([node.expr, node.asKw, node.dataType, node.format]), | ||
cast_format: (node) => show([node.formatKw, node.string]), | ||
raise_expr: (node) => show([node.raiseKw, node.args]), | ||
@@ -283,4 +309,2 @@ extract_expr: (node) => show([node.extractKw, node.args]), | ||
between_expr: (node) => show([node.left, node.betweenKw, node.begin, node.andKw, node.end]), | ||
datetime: (node) => show([node.kw, node.string]), | ||
string_with_charset: (node) => "_" + node.charset + show(node.string), | ||
case_expr: (node) => show([node.caseKw, node.expr, node.clauses, node.endKw]), | ||
@@ -299,10 +323,16 @@ case_when: (node) => show([node.whenKw, node.condition, node.thenKw, node.result]), | ||
member_expr: (node) => show([node.object, node.property], node.property.type === "array_subscript" ? "" : "."), | ||
bigquery_quoted_member_expr: (node) => show(["`", node.expr, "`"]), | ||
array_subscript: (node) => show(["[", node.expr, "]"]), | ||
array_subscript_specifier: (node) => show([node.specifierKw, node.args]), | ||
table_ref: (node) => show([node.catalog, node.schema, node.table], "."), | ||
alias: (node) => show([node.expr, node.asKw, node.alias]), | ||
indexed_table_ref: (node) => show([node.table, node.indexedByKw, node.index]), | ||
not_indexed_table_ref: (node) => show([node.table, node.notIndexedKw]), | ||
indexed_table: (node) => show([node.table, node.indexedByKw, node.index]), | ||
not_indexed_table: (node) => show([node.table, node.notIndexedKw]), | ||
unnest_expr: (node) => show([node.unnestKw, node.expr]), | ||
unnest_with_offset_expr: (node) => show([node.unnest, node.withOffsetKw]), | ||
all_columns: () => "*", | ||
// special literals | ||
string_with_charset: (node) => "_" + node.charset + show(node.string), | ||
datetime: (node) => show([node.kw, node.string]), | ||
json: (node) => show([node.jsonKw, node.string]), | ||
numeric: (node) => show([node.numericKw, node.string]), | ||
// Basic language elements | ||
@@ -309,0 +339,0 @@ keyword: (node) => node.text, |
@@ -13,1 +13,5 @@ /** | ||
export declare const parseBitBlob: (data: string) => number[]; | ||
/** | ||
* Converts array of chars to decimal array | ||
*/ | ||
export declare const parseAsciiBlob: (data: string[]) => number[]; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseBitBlob = exports.parseHexBlob = void 0; | ||
exports.parseAsciiBlob = exports.parseBitBlob = exports.parseHexBlob = void 0; | ||
/** | ||
@@ -28,1 +28,8 @@ * Converts hex string to decimal array | ||
exports.parseBitBlob = parseBitBlob; | ||
/** | ||
* Converts array of chars to decimal array | ||
*/ | ||
const parseAsciiBlob = (data) => { | ||
return data.flatMap((c) => c.split("")).map((c) => c.charCodeAt(0)); | ||
}; | ||
exports.parseAsciiBlob = parseAsciiBlob; |
@@ -1,2 +0,2 @@ | ||
import { Alias, BinaryExpr, CompoundSelectStmt, Expr, ListExpr, Identifier, JoinExpr, Keyword, Node, ParenExpr, PostfixOpExpr, PrefixOpExpr, SubSelect, Whitespace, MemberExpr, PivotExpr } from "../cst/Node"; | ||
import { Alias, BinaryExpr, CompoundSelectStmt, Expr, ListExpr, Identifier, JoinExpr, Keyword, Node, ParenExpr, PostfixOpExpr, PrefixOpExpr, SubSelect, Whitespace, MemberExpr, PivotExpr, UnpivotExpr, TablesampleExpr, FuncCall } from "../cst/Node"; | ||
export declare function createBinaryExprChain(head: BinaryExpr["left"], tail: [ | ||
@@ -27,3 +27,24 @@ Whitespace[], | ||
} | ||
export declare function createJoinExprChain(head: JoinExpr["left"], tail: [Whitespace[], JoinExprRight | PivotExprRight][]): JoinExpr | PivotExpr | import("../cst/Select").TableOrSubquery; | ||
interface UnpivotExprRight { | ||
type: "unpivot_expr_right"; | ||
unpivotKw: UnpivotExpr["unpivotKw"]; | ||
nullHandlingKw: UnpivotExpr["nullHandlingKw"]; | ||
args: UnpivotExpr["args"]; | ||
} | ||
interface TablesampleExprRight { | ||
type: "tablesample_expr_right"; | ||
tablesampleKw: TablesampleExpr["tablesampleKw"]; | ||
args: TablesampleExpr["args"]; | ||
} | ||
export declare function createJoinExprChain(head: JoinExpr["left"], tail: [ | ||
Whitespace[], | ||
JoinExprRight | PivotExprRight | UnpivotExprRight | TablesampleExprRight | ||
][]): JoinExpr | PivotExpr | UnpivotExpr | TablesampleExpr | import("../cst/Select").TableOrSubquery; | ||
interface FuncCallRight { | ||
type: "func_call_right"; | ||
args: FuncCall["args"]; | ||
filter: FuncCall["filter"]; | ||
over: FuncCall["over"]; | ||
} | ||
declare type FuncCallTailPart = [Whitespace[], FuncCallRight]; | ||
declare type ArrayMemberExprTailPart = [Whitespace[], MemberExpr["property"]]; | ||
@@ -37,3 +58,4 @@ declare type ObjectMemberExprTailPart = [ | ||
declare type MemberExprTailPart = ArrayMemberExprTailPart | ObjectMemberExprTailPart; | ||
export declare function createMemberExprChain(head: MemberExpr["object"], tail: MemberExprTailPart[]): Expr; | ||
export declare function createMemberExprChain(head: MemberExpr["object"], tail: (MemberExprTailPart | FuncCallTailPart)[]): Expr; | ||
export declare function createFuncCall(name: FuncCall["name"], [c1, fn]: FuncCallTailPart): FuncCall; | ||
export declare function createPrefixOpExpr(op: PrefixOpExpr["operator"], expr: Expr): PrefixOpExpr; | ||
@@ -40,0 +62,0 @@ export declare function createPostfixOpExpr(op: PostfixOpExpr["operator"], expr: Expr): PostfixOpExpr; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createListExpr = exports.createParenExpr = exports.createAlias = exports.createIdentifier = exports.createKeyword = exports.createPostfixOpExpr = exports.createPrefixOpExpr = exports.createMemberExprChain = exports.createJoinExprChain = exports.createCompoundSelectStmt = exports.createCompoundSelectStmtChain = exports.createBinaryExpr = exports.createBinaryExprChain = void 0; | ||
exports.createListExpr = exports.createParenExpr = exports.createAlias = exports.createIdentifier = exports.createKeyword = exports.createPostfixOpExpr = exports.createPrefixOpExpr = exports.createFuncCall = exports.createMemberExprChain = exports.createJoinExprChain = exports.createCompoundSelectStmt = exports.createCompoundSelectStmtChain = exports.createBinaryExpr = exports.createBinaryExprChain = void 0; | ||
const whitespace_1 = require("./whitespace"); | ||
@@ -52,3 +52,3 @@ const list_1 = require("./list"); | ||
}; | ||
const derivePivotLoc = (pivot) => { | ||
const derivePivotlikeLoc = (pivot) => { | ||
if (!pivot.left.range || !pivot.args.range) { | ||
@@ -62,5 +62,14 @@ return pivot; | ||
function createJoinExprChain(head, tail) { | ||
return tail.reduce((left, [c1, right]) => right.type === "join_expr_right" | ||
? deriveJoinLoc(createJoinExpr(left, c1, right)) | ||
: derivePivotLoc(createPivotExpr(left, c1, right)), head); | ||
return tail.reduce((left, [c1, right]) => { | ||
switch (right.type) { | ||
case "join_expr_right": | ||
return deriveJoinLoc(createJoinExpr(left, c1, right)); | ||
case "pivot_expr_right": | ||
return derivePivotlikeLoc(createPivotExpr(left, c1, right)); | ||
case "unpivot_expr_right": | ||
return derivePivotlikeLoc(createUnpivotExpr(left, c1, right)); | ||
case "tablesample_expr_right": | ||
return derivePivotlikeLoc(createTablesampleExpr(left, c1, right)); | ||
} | ||
}, head); | ||
} | ||
@@ -85,7 +94,34 @@ exports.createJoinExprChain = createJoinExprChain; | ||
} | ||
function createUnpivotExpr(left, c1, right) { | ||
return { | ||
type: "unpivot_expr", | ||
left: (0, whitespace_1.trailing)(left, c1), | ||
unpivotKw: right.unpivotKw, | ||
nullHandlingKw: right.nullHandlingKw, | ||
args: right.args, | ||
}; | ||
} | ||
function createTablesampleExpr(left, c1, right) { | ||
return { | ||
type: "tablesample_expr", | ||
left: (0, whitespace_1.trailing)(left, c1), | ||
tablesampleKw: right.tablesampleKw, | ||
args: right.args, | ||
}; | ||
} | ||
function isObjectMemberExprTailPart(part) { | ||
return part[1] === "."; | ||
} | ||
function isFuncCallMemberExprTailPart(part) { | ||
return typeof part[1] === "object" && part[1].type === "func_call_right"; | ||
} | ||
function createMemberExprChain(head, tail) { | ||
return tail.reduce((obj, tailPart) => deriveMemberExprLoc(createMemberExpr(obj, tailPart)), head); | ||
return tail.reduce((obj, tailPart) => { | ||
if (isFuncCallMemberExprTailPart(tailPart)) { | ||
return deriveFuncCallLoc(createFuncCall(obj, tailPart)); | ||
} | ||
else { | ||
return deriveMemberExprLoc(createMemberExpr(obj, tailPart)); | ||
} | ||
}, head); | ||
} | ||
@@ -111,2 +147,12 @@ exports.createMemberExprChain = createMemberExprChain; | ||
} | ||
function createFuncCall(name, [c1, fn]) { | ||
return { | ||
type: "func_call", | ||
name: (0, whitespace_1.trailing)(name, c1), | ||
args: fn.args, | ||
filter: fn.filter, | ||
over: fn.over, | ||
}; | ||
} | ||
exports.createFuncCall = createFuncCall; | ||
const deriveMemberExprLoc = (expr) => { | ||
@@ -120,2 +166,14 @@ if (!expr.object.range || !expr.property.range) { | ||
}; | ||
const deriveFuncCallLoc = (fn) => { | ||
const right = fn.over || fn.filter || fn.args; | ||
if (!right) { | ||
throw new Error("Unexpected argument-less function call."); | ||
} | ||
if (!fn.name.range || !right.range) { | ||
return fn; | ||
} | ||
const start = fn.name.range[0]; | ||
const end = right.range[1]; | ||
return Object.assign(Object.assign({}, fn), { range: [start, end] }); | ||
}; | ||
function createPrefixOpExpr(op, expr) { | ||
@@ -122,0 +180,0 @@ return { |
@@ -5,3 +5,3 @@ { | ||
"license": "GPL-2.0-or-later", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"main": "lib/main.js", | ||
@@ -32,3 +32,4 @@ "types": "lib/main.d.ts", | ||
"test": "yarn generate && yarn test:bigquery && yarn test:mysql && yarn test:sqlite", | ||
"perf": "yarn ts-node perf/perf-test.ts" | ||
"perf:big": "yarn ts-node perf/perf-test.ts big", | ||
"perf:func": "yarn ts-node perf/perf-test.ts func" | ||
}, | ||
@@ -35,0 +36,0 @@ "devDependencies": { |
@@ -9,2 +9,4 @@ # SQL Parser CST [![npm version](https://img.shields.io/npm/v/sql-parser-cst)](https://www.npmjs.com/package/sql-parser-cst) ![example workflow](https://github.com/nene/sql-parser-cst/actions/workflows/build.yml/badge.svg) | ||
**Try it live in [AstExplorer][].** | ||
For now it supports the following SQL dialects: | ||
@@ -125,6 +127,3 @@ | ||
"fromKw": { "type": "keyword", "text": "FROM", "name": "FROM" }, | ||
"expr": { | ||
"type": "table_ref", | ||
"table": { "type": "identifier", "text": "persons", "name": "persons" } | ||
}, | ||
"expr": { "type": "identifier", "text": "persons", "name": "persons" }, | ||
"leading": [ | ||
@@ -208,1 +207,2 @@ { "type": "newline", "text": "\n" }, | ||
[nquery]: https://github.com/alibaba/nquery | ||
[astexplorer]: https://astexplorer.net/#/gist/9636e48608a7c89707c5b345100de5b2/9331a011294bd03acc56cbe2d9ae9e60fa7dc8e6 |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1691805
50786