Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sql-parser-cst

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-parser-cst - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

8

lib/cst/AlterTable.d.ts
import { BaseNode, Keyword } from "./Base";
import { ColumnDefinition } from "./CreateTable";
import { ColumnRef, ListExpr, TableRef } from "./Expr";
import { Identifier, ListExpr, TableRef } from "./Expr";
export interface AlterTableStmt extends BaseNode {

@@ -19,5 +19,5 @@ type: "alter_table_stmt";

renameKw: Keyword<"RENAME"> | [Keyword<"RENAME">, Keyword<"COLUMN">];
oldName: ColumnRef;
oldName: Identifier;
toKw: Keyword<"TO" | "AS">;
newName: ColumnRef;
newName: Identifier;
}

@@ -32,3 +32,3 @@ export interface AlterAddColumn extends BaseNode {

dropKw: Keyword<"DROP"> | [Keyword<"DROP">, Keyword<"COLUMN">];
column: ColumnRef;
column: Identifier;
}

@@ -18,1 +18,4 @@ export interface BaseNode {

}
export interface Empty extends BaseNode {
type: "empty";
}
import { BaseNode, Keyword } from "./Base";
import { StringLiteral } from "./Literal";
import { ColumnRef, Expr, Identifier, ListExpr, ParenExpr, TableRef } from "./Expr";
import { Expr, Identifier, ListExpr, ParenExpr, TableRef } from "./Expr";
import { SortSpecification } from "./Select";

@@ -27,3 +27,3 @@ export declare type AllConstraintNodes = Constraint<ColumnConstraint | TableConstraint> | ColumnConstraint | TableConstraint | ConstraintName | ConstraintDeferrable | ReferencesSpecification | ReferentialAction | ReferentialMatch | OnConflictClause;

primaryKeyKw: [Keyword<"PRIMARY">, Keyword<"KEY">];
columns?: ParenExpr<ListExpr<SortSpecification | ColumnRef>>;
columns?: ParenExpr<ListExpr<SortSpecification | Identifier>>;
onConflict?: OnConflictClause;

@@ -34,3 +34,3 @@ }

foreignKeyKw: [Keyword<"FOREIGN">, Keyword<"KEY">];
columns: ParenExpr<ListExpr<ColumnRef>>;
columns: ParenExpr<ListExpr<Identifier>>;
references: ReferencesSpecification;

@@ -42,3 +42,3 @@ }

table: TableRef;
columns?: ParenExpr<ListExpr<ColumnRef>>;
columns?: ParenExpr<ListExpr<Identifier>>;
options: (ReferentialAction | ReferentialMatch)[];

@@ -60,3 +60,3 @@ }

uniqueKw: Keyword<"UNIQUE"> | [Keyword<"UNIQUE">, Keyword<"KEY" | "INDEX">];
columns?: ParenExpr<ListExpr<ColumnRef>>;
columns?: ParenExpr<ListExpr<Identifier>>;
onConflict?: OnConflictClause;

@@ -74,3 +74,3 @@ }

indexKw: Keyword<"INDEX" | "KEY">;
columns?: ParenExpr<ListExpr<ColumnRef>>;
columns?: ParenExpr<ListExpr<Identifier>>;
}

@@ -77,0 +77,0 @@ export interface ConstraintNull extends BaseNode {

import { BaseNode, Keyword } from "./Base";
import { ColumnConstraint, Constraint, TableConstraint } from "./Constraint";
import { ColumnRef, Identifier, ListExpr, ParenExpr, TableRef } from "./Expr";
import { Identifier, ListExpr, PairExpr, ParenExpr, TableRef } from "./Expr";
import { Literal, NumberLiteral, StringLiteral } from "./Literal";
import { SubSelect } from "./Select";
export declare type AllCreateTableNodes = CreateTableStmt | CreateTableAs | ColumnDefinition | DataType | TableOption;
export declare type AllCreateTableNodes = CreateTableStmt | CreateTableAs | ColumnDefinition | DataType | GenericTypeParams | TableOption;
export interface CreateTableStmt extends BaseNode {

@@ -25,3 +25,3 @@ type: "create_table_stmt";

type: "column_definition";
name: ColumnRef;
name: Identifier;
dataType?: DataType;

@@ -33,4 +33,8 @@ constraints: (ColumnConstraint | Constraint<ColumnConstraint>)[];

nameKw: Keyword | Keyword[];
params?: ParenExpr<ListExpr<Literal>>;
params?: ParenExpr<ListExpr<Literal>> | GenericTypeParams;
}
export interface GenericTypeParams extends BaseNode {
type: "generic_type_params";
params: ListExpr<DataType | PairExpr<Identifier, DataType>>;
}
export interface TableOption extends BaseNode {

@@ -37,0 +41,0 @@ type: "table_option";

@@ -5,5 +5,5 @@ import { AllColumns, BaseNode, Keyword } from "./Base";

import { Node } from "./Node";
import { WhereClause, WindowDefinition } from "./Select";
export declare type AllExprNodes = Expr | DistinctArg | CastArg | FilterArg | OverArg | CaseWhen | CaseElse;
export declare type Expr = ListExpr | ParenExpr | BinaryExpr | PrefixOpExpr | PostfixOpExpr | FuncCall | TableFuncCall | CastExpr | RaiseExpr | BetweenExpr | CaseExpr | IntervalExpr | StringWithCharset | Literal | ColumnRef | TableRef | Identifier | Parameter;
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;
export interface ListExpr<T = Node> extends BaseNode {

@@ -17,2 +17,7 @@ type: "list_expr";

}
export interface PairExpr<T1 = Node, T2 = Node> extends BaseNode {
type: "pair_expr";
expr1: T1;
expr2: T2;
}
export interface BinaryExpr extends BaseNode {

@@ -37,3 +42,3 @@ type: "binary_expr";

name: Identifier;
args?: ParenExpr<ListExpr<Expr | AllColumns | DistinctArg>>;
args?: ParenExpr<ListExpr<Expr | AllColumns | DistinctArg | SubSelect>>;
filter?: FilterArg;

@@ -64,3 +69,3 @@ over?: OverArg;

type: "cast_expr";
castKw: Keyword<"CAST">;
castKw: Keyword<"CAST" | "SAFE_CAST">;
args: ParenExpr<CastArg>;

@@ -79,2 +84,18 @@ }

}
export interface ExtractExpr extends BaseNode {
type: "extract_expr";
extractKw: Keyword<"EXTRACT">;
args: ParenExpr<ExtractFrom>;
}
export interface ExtractFrom extends BaseNode {
type: "extract_from";
unit: IntervalUnitKeyword | WeekExpr;
fromKw: Keyword<"FROM">;
expr: Expr;
}
export interface WeekExpr extends BaseNode {
type: "week_expr";
weekKw: Keyword<"WEEK">;
args: ParenExpr<Keyword<"SUNDAY" | "MONDAY" | "TUESDAY" | "WEDNESDAY" | "THURSDAY" | "FRIDAY" | "SATURDAY">>;
}
export interface BetweenExpr extends BaseNode {

@@ -111,4 +132,11 @@ type: "between_expr";

expr: Expr;
unitKw: Keyword<"YEAR" | "QUARTER" | "MONTH" | "WEEK" | "DAY" | "HOUR" | "MINUTE" | "SECOND" | "MICROSECOND">;
unit: IntervalUnitKeyword | IntervalUnitRange;
}
export interface IntervalUnitRange extends BaseNode {
type: "interval_unit_range";
fromUnitKw: IntervalUnitKeyword;
toKw: Keyword<"TO">;
toUnitKw: IntervalUnitKeyword;
}
declare type IntervalUnitKeyword = Keyword<"YEAR" | "QUARTER" | "MONTH" | "WEEK" | "DAY" | "HOUR" | "MINUTE" | "SECOND" | "MICROSECOND" | "SECOND_MICROSECOND" | "MINUTE_MICROSECOND" | "MINUTE_SECOND" | "HOUR_MICROSECOND" | "HOUR_SECOND" | "HOUR_MINUTE" | "DAY_MICROSECOND" | "DAY_SECOND" | "DAY_MINUTE" | "DAY_HOUR" | "YEAR_MONTH">;
export interface StringWithCharset extends BaseNode {

@@ -119,9 +147,19 @@ type: "string_with_charset";

}
export interface ColumnRef extends BaseNode {
type: "column_ref";
table?: Identifier;
column: Identifier | AllColumns;
export interface MemberExpr extends BaseNode {
type: "member_expr";
object: Expr;
property: ArraySubscript | Identifier | AllColumns;
}
export interface ArraySubscript extends BaseNode {
type: "array_subscript";
expr: Expr | ArraySubscriptSpecifier;
}
export interface ArraySubscriptSpecifier extends BaseNode {
type: "array_subscript_specifier";
specifierKw: Keyword<"OFFSET" | "SAFE_OFFSET" | "ORDINAL" | "SAFE_ORDINAL">;
args: ParenExpr<Expr>;
}
export interface TableRef extends BaseNode {
type: "table_ref";
catalog?: Identifier;
schema?: Identifier;

@@ -139,1 +177,15 @@ table: Identifier;

}
export interface TypedExpr extends BaseNode {
type: "typed_expr";
dataType: DataType;
expr: ArrayExpr | StructExpr;
}
export interface ArrayExpr extends BaseNode {
type: "array_expr";
expr: ListExpr<Expr>;
}
export interface StructExpr extends BaseNode {
type: "struct_expr";
expr: ListExpr<Expr>;
}
export {};
import { BaseNode, Keyword } from "./Base";
import { ColumnRef, ListExpr, ParenExpr, TableRef } from "./Expr";
import { Identifier, ListExpr, ParenExpr, TableRef } from "./Expr";
import { SortSpecification, WhereClause } from "./Select";

@@ -13,3 +13,3 @@ export interface CreateIndexStmt extends BaseNode {

table: TableRef;
columns: ParenExpr<ListExpr<SortSpecification | ColumnRef>>;
columns: ParenExpr<ListExpr<SortSpecification | Identifier>>;
where?: WhereClause;

@@ -16,0 +16,0 @@ }

import { BaseNode, Keyword } from "./Base";
import { ColumnRef, Expr, ListExpr, ParenExpr, TableRef } from "./Expr";
import { Expr, Identifier, ListExpr, ParenExpr, TableRef } from "./Expr";
import { Alias } from "./Alias";

@@ -18,3 +18,3 @@ import { ReturningClause, SortSpecification, SubSelect, WhereClause, WithClause } from "./Select";

table: TableRef | Alias<TableRef>;
columns?: ParenExpr<ListExpr<ColumnRef>>;
columns?: ParenExpr<ListExpr<Identifier>>;
}

@@ -51,3 +51,3 @@ export interface UpsertOption extends BaseNode {

onConflictKw: [Keyword<"ON">, Keyword<"CONFLICT">];
columns?: ParenExpr<ListExpr<SortSpecification | ColumnRef>>;
columns?: ParenExpr<ListExpr<SortSpecification | Identifier>>;
where?: WhereClause;

@@ -54,0 +54,0 @@ doKw: Keyword<"DOR">;

@@ -1,6 +0,6 @@

import { BaseNode, Keyword } from "./Base";
import { ColumnRef, Expr, Identifier, ListExpr, ParenExpr, TableFuncCall, TableRef } from "./Expr";
import { BaseNode, Empty, Keyword } from "./Base";
import { Expr, FuncCall, Identifier, ListExpr, ParenExpr, TableFuncCall, TableRef } from "./Expr";
import { Alias } from "./Alias";
import { FrameClause } from "./WindowFrame";
export declare type AllSelectNodes = CompoundSelectStmt | SelectStmt | WithClause | CommonTableExpression | SelectClause | FromClause | WhereClause | GroupByClause | HavingClause | WindowClause | NamedWindow | WindowDefinition | OrderByClause | PartitionByClause | LimitClause | JoinExpr | IndexedTableRef | NotIndexedTableRef | JoinOnSpecification | JoinUsingSpecification | SortSpecification | ReturningClause;
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 interface CompoundSelectStmt extends BaseNode {

@@ -15,3 +15,3 @@ type: "compound_select_stmt";

type: "select_stmt";
clauses: (WithClause | SelectClause | FromClause | WhereClause | GroupByClause | HavingClause | WindowClause | OrderByClause | LimitClause)[];
clauses: (WithClause | SelectClause | FromClause | WhereClause | GroupByClause | HavingClause | WindowClause | QualifyClause | OrderByClause | LimitClause)[];
}

@@ -27,3 +27,3 @@ export interface WithClause extends BaseNode {

table: Identifier;
columns?: ParenExpr<ListExpr<ColumnRef>>;
columns?: ParenExpr<ListExpr<Identifier>>;
asKw: Keyword<"AS">;

@@ -37,3 +37,3 @@ optionKw?: Keyword<"MATERIALIZED"> | [Keyword<"NOT">, Keyword<"MATERIALIZED">];

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>>;
columns: ListExpr<Expr | Alias<Expr> | Empty>;
}

@@ -43,3 +43,3 @@ export interface FromClause extends BaseNode {

fromKw: Keyword<"FROM">;
expr: TableOrSubquery | JoinExpr;
expr: JoinExprLeft;
}

@@ -82,3 +82,3 @@ export interface WhereClause extends BaseNode {

orderByKw: [Keyword<"ORDER">, Keyword<"BY">];
specifications: ListExpr<SortSpecification | ColumnRef>;
specifications: ListExpr<SortSpecification | Identifier>;
withRollupKw?: [Keyword<"WITH">, Keyword<"ROLLUP">];

@@ -98,5 +98,6 @@ }

}
declare type JoinExprLeft = JoinExpr | PivotExpr | TableOrSubquery;
export interface JoinExpr extends BaseNode {
type: "join_expr";
left: JoinExpr | TableOrSubquery;
left: JoinExprLeft;
operator: JoinOp | ",";

@@ -107,3 +108,3 @@ 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 | TableOrSubquery | JoinExpr> | Alias<TableOrSubquery>;
export declare type TableOrSubquery = TableRef | TableFuncCall | IndexedTableRef | NotIndexedTableRef | ParenExpr<SubSelect | JoinExprLeft> | UnnestExpr | Alias<TableOrSubquery>;
export interface IndexedTableRef extends BaseNode {

@@ -120,2 +121,21 @@ type: "indexed_table_ref";

}
export interface UnnestExpr extends BaseNode {
type: "unnest_expr";
unnestKw: Keyword<"UNNEST">;
expr: ParenExpr<Expr>;
}
export interface PivotExpr extends BaseNode {
type: "pivot_expr";
left: JoinExprLeft;
pivotKw: Keyword<"PIVOT">;
args: ParenExpr<PivotForIn>;
}
export interface PivotForIn extends BaseNode {
type: "pivot_for_in";
aggregations: ListExpr<FuncCall | Alias<FuncCall>>;
forKw: Keyword<"FOR">;
inputColumn: Identifier;
inKw: Keyword<"IN">;
pivotColumns: ParenExpr<ListExpr<Expr | Alias<Expr>>>;
}
export interface JoinOnSpecification extends BaseNode {

@@ -129,3 +149,3 @@ type: "join_on_specification";

usingKw: Keyword<"USING">;
expr: ParenExpr<ListExpr<ColumnRef>>;
expr: ParenExpr<ListExpr<Identifier>>;
}

@@ -138,2 +158,7 @@ export interface SortSpecification extends BaseNode {

}
export interface QualifyClause extends BaseNode {
type: "qualify_clause";
qualifyKw: Keyword<"QUALIFY">;
expr: Expr;
}
export interface ReturningClause extends BaseNode {

@@ -140,0 +165,0 @@ type: "returning_clause";

import { AlterTableStmt } from "./AlterTable";
import { AnalyzeStmt } from "./Analyze";
import { BaseNode } from "./Base";
import { Empty } from "./Base";
import { CreateTableStmt } from "./CreateTable";

@@ -16,5 +16,2 @@ import { DeleteStmt } from "./Delete";

import { CreateViewStmt, DropViewStmt } from "./View";
export declare type Statement = EmptyStmt | CompoundSelectStmt | SelectStmt | CreateTableStmt | AlterTableStmt | DropTableStmt | InsertStmt | DeleteStmt | UpdateStmt | CreateViewStmt | DropViewStmt | CreateIndexStmt | DropIndexStmt | CreateTriggerStmt | DropTriggerStmt | AnalyzeStmt | ExplainStmt | TransactionStmt | SqliteStmt;
export interface EmptyStmt extends BaseNode {
type: "empty_stmt";
}
export declare type Statement = Empty | CompoundSelectStmt | SelectStmt | CreateTableStmt | AlterTableStmt | DropTableStmt | InsertStmt | DeleteStmt | UpdateStmt | CreateViewStmt | DropViewStmt | CreateIndexStmt | DropIndexStmt | CreateTriggerStmt | DropTriggerStmt | AnalyzeStmt | ExplainStmt | TransactionStmt | SqliteStmt;
import { BaseNode, Keyword } from "./Base";
import { ColumnRef, Expr, ListExpr, TableRef } from "./Expr";
import { Expr, Identifier, ListExpr, TableRef } from "./Expr";
import { Program } from "./Program";

@@ -24,3 +24,3 @@ export declare type AllTriggerNodes = CreateTriggerStmt | DropTriggerStmt | TriggerEvent | TriggerCondition | TriggerBody | TriggerCondition | TriggerBody;

ofKw?: Keyword<"OF">;
columns?: ListExpr<ColumnRef>;
columns?: ListExpr<Identifier>;
}

@@ -27,0 +27,0 @@ export interface TriggerCondition extends BaseNode {

import { Alias } from "./Alias";
import { BaseNode, Keyword } from "./Base";
import { ColumnRef, Expr, ListExpr, ParenExpr, TableRef } from "./Expr";
import { Expr, Identifier, ListExpr, MemberExpr, ParenExpr, TableRef } from "./Expr";
import { Default, OrAlternateAction, UpsertOption } from "./Insert";

@@ -25,4 +25,4 @@ import { FromClause, LimitClause, OrderByClause, ReturningClause, WhereClause, WithClause } from "./Select";

type: "column_assignment";
column: ColumnRef | ParenExpr<ListExpr<ColumnRef>>;
column: Identifier | MemberExpr | ParenExpr<ListExpr<Identifier>>;
expr: Expr | Default;
}
import { BaseNode, Keyword } from "./Base";
import { ColumnRef, ListExpr, ParenExpr, TableRef } from "./Expr";
import { Identifier, ListExpr, ParenExpr, TableRef } from "./Expr";
import { SubSelect } from "./Select";

@@ -11,3 +11,3 @@ export interface CreateViewStmt extends BaseNode {

name: TableRef;
columns?: ParenExpr<ListExpr<ColumnRef>>;
columns?: ParenExpr<ListExpr<Identifier>>;
asKw: Keyword<"AS">;

@@ -14,0 +14,0 @@ expr: SubSelect;

@@ -57,3 +57,3 @@ "use strict";

program: (node) => node.statements.map(layout),
empty_stmt: () => "",
empty: () => "",
// SELECT statement

@@ -73,5 +73,5 @@ select_stmt: (node) => node.clauses.map(layout),

// Tables & columns
column_ref: (node) => node.table
? [layout(node.table), ".", layout(node.column)]
: layout(node.column),
member_expr: (node) => node.property.type === "array_subscript"
? layout([node.object, node.property])
: [layout(node.object), ".", layout(node.property)],
table_ref: (node) => node.schema

@@ -78,0 +78,0 @@ ? [layout(node.schema), ".", layout(node.table)]

@@ -1,1 +0,1 @@

export declare const __RESERVED_KEYWORDS__: Record<string, boolean>;
export declare const bigqueryKeywords: Record<string, boolean>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__RESERVED_KEYWORDS__ = void 0;
exports.bigqueryKeywords = void 0;
// All keywords listed in:
// https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#reserved_keywords
exports.__RESERVED_KEYWORDS__ = {
exports.bigqueryKeywords = {
ALL: true,

@@ -8,0 +8,0 @@ AND: true,

@@ -1,1 +0,1 @@

export declare const __RESERVED_KEYWORDS__: Record<string, boolean>;
export declare const mysqlKeywords: Record<string, boolean>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__RESERVED_KEYWORDS__ = void 0;
exports.mysqlKeywords = void 0;
// All keywords marked as reserved (R) from:
// https://dev.mysql.com/doc/refman/8.0/en/keywords.html
exports.__RESERVED_KEYWORDS__ = {
exports.mysqlKeywords = {
ACCESSIBLE: true,

@@ -8,0 +8,0 @@ ADD: true,

@@ -1,1 +0,1 @@

export declare const __RESERVED_KEYWORDS__: Record<string, boolean>;
export declare const sqliteKeywords: Record<string, boolean>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__RESERVED_KEYWORDS__ = void 0;
exports.sqliteKeywords = void 0;
// All keywords listed in:
// https://www.sqlite.org/lang_keywords.html
exports.__RESERVED_KEYWORDS__ = {
exports.sqliteKeywords = {
ABORT: true,

@@ -8,0 +8,0 @@ ACTION: true,

@@ -34,3 +34,3 @@ "use strict";

program: (node) => show(node.statements, ";"),
empty_stmt: () => "",
empty: () => "",
// SELECT statement

@@ -49,7 +49,16 @@ compound_select_stmt: (node) => show([node.left, node.operator, node.right]),

join_using_specification: (node) => show([node.usingKw, node.expr]),
pivot_expr: (node) => show([node.left, node.pivotKw, node.args]),
pivot_for_in: (node) => show([
node.aggregations,
node.forKw,
node.inputColumn,
node.inKw,
node.pivotColumns,
]),
sort_specification: (node) => show([node.expr, node.orderKw, node.nullHandlingKw]),
// WHERE .. GROUP BY .. HAVING .. ORDER BY .. PARTITION BY
// WHERE .. GROUP BY .. HAVING .. QUALIFY ... ORDER BY .. PARTITION BY
where_clause: (node) => show([node.whereKw, node.expr]),
group_by_clause: (node) => show([node.groupByKw, node.columns]),
having_clause: (node) => show([node.havingKw, node.expr]),
qualify_clause: (node) => show([node.qualifyKw, node.expr]),
order_by_clause: (node) => show([node.orderByKw, node.specifications, node.withRollupKw]),

@@ -256,2 +265,3 @@ partition_by_clause: (node) => show([node.partitionByKw, node.specifications]),

paren_expr: (node) => "(" + show(node.expr) + ")",
pair_expr: (node) => show([node.expr1, node.expr2]),
binary_expr: (node) => show([node.left, node.operator, node.right]),

@@ -266,2 +276,5 @@ prefix_op_expr: (node) => show([node.operator, node.expr]),

raise_expr: (node) => show([node.raiseKw, node.args]),
extract_expr: (node) => show([node.extractKw, node.args]),
extract_from: (node) => show([node.unit, node.fromKw, node.expr]),
week_expr: (node) => show([node.weekKw, node.args]),
filter_arg: (node) => show([node.filterKw, node.where]),

@@ -275,11 +288,19 @@ over_arg: (node) => show([node.overKw, node.window]),

case_else: (node) => show([node.elseKw, node.result]),
interval_expr: (node) => show([node.intervalKw, node.expr, node.unitKw]),
interval_expr: (node) => show([node.intervalKw, node.expr, node.unit]),
interval_unit_range: (node) => show([node.fromUnitKw, node.toKw, node.toUnitKw]),
typed_expr: (node) => show([node.dataType, node.expr]),
array_expr: (node) => show(["[", node.expr, "]"]),
struct_expr: (node) => show(["(", node.expr, ")"]),
// Data types
data_type: (node) => show([node.nameKw, node.params]),
generic_type_params: (node) => show(["<", node.params, ">"]),
// Tables & columns
column_ref: (node) => show([node.table, node.column], "."),
table_ref: (node) => show([node.schema, node.table], "."),
member_expr: (node) => show([node.object, node.property], node.property.type === "array_subscript" ? "" : "."),
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]),
unnest_expr: (node) => show([node.unnestKw, node.expr]),
all_columns: () => "*",

@@ -286,0 +307,0 @@ // Basic language elements

@@ -9,5 +9,5 @@ "use strict";

const keywordMap = {
bigquery: bigquery_keywords_1.__RESERVED_KEYWORDS__,
mysql: mysql_keywords_1.__RESERVED_KEYWORDS__,
sqlite: sqlite_keywords_1.__RESERVED_KEYWORDS__,
bigquery: bigquery_keywords_1.bigqueryKeywords,
mysql: mysql_keywords_1.mysqlKeywords,
sqlite: sqlite_keywords_1.sqliteKeywords,
};

@@ -14,0 +14,0 @@ const isReservedKeyword = (name) => {

@@ -1,2 +0,2 @@

import { Alias, BinaryExpr, CompoundSelectStmt, Expr, ListExpr, Identifier, JoinExpr, Keyword, Node, ParenExpr, PostfixOpExpr, PrefixOpExpr, SubSelect, Whitespace } from "../cst/Node";
import { Alias, BinaryExpr, CompoundSelectStmt, Expr, ListExpr, Identifier, JoinExpr, Keyword, Node, ParenExpr, PostfixOpExpr, PrefixOpExpr, SubSelect, Whitespace, MemberExpr, PivotExpr } from "../cst/Node";
export declare function createBinaryExprChain(head: BinaryExpr["left"], tail: [

@@ -16,9 +16,23 @@ Whitespace[],

export declare function createCompoundSelectStmt(left: CompoundSelectStmt["left"], c1: Whitespace[], op: CompoundSelectStmt["operator"], c2: Whitespace[], right: CompoundSelectStmt["right"]): CompoundSelectStmt;
export declare function createJoinExprChain(head: JoinExpr["left"], tail: [
interface JoinExprRight {
type: "join_expr_right";
operator: JoinExpr["operator"];
right: JoinExpr["right"];
specification: JoinExpr["specification"];
}
interface PivotExprRight {
type: "pivot_expr_right";
pivotKw: PivotExpr["pivotKw"];
args: PivotExpr["args"];
}
export declare function createJoinExprChain(head: JoinExpr["left"], tail: [Whitespace[], JoinExprRight | PivotExprRight][]): JoinExpr | PivotExpr | import("../cst/Select").TableOrSubquery;
declare type ArrayMemberExprTailPart = [Whitespace[], MemberExpr["property"]];
declare type ObjectMemberExprTailPart = [
Whitespace[],
JoinExpr["operator"],
".",
Whitespace[],
JoinExpr["right"],
JoinExpr["specification"] | null
][]): JoinExpr | import("../cst/Select").TableOrSubquery;
MemberExpr["property"]
];
declare type MemberExprTailPart = ArrayMemberExprTailPart | ObjectMemberExprTailPart;
export declare function createMemberExprChain(head: MemberExpr["object"], tail: MemberExprTailPart[]): Expr;
export declare function createPrefixOpExpr(op: PrefixOpExpr["operator"], expr: Expr): PrefixOpExpr;

@@ -25,0 +39,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.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.createMemberExprChain = exports.createJoinExprChain = exports.createCompoundSelectStmt = exports.createCompoundSelectStmtChain = exports.createBinaryExpr = exports.createBinaryExprChain = void 0;
const whitespace_1 = require("./whitespace");
const read_1 = require("./read");
const list_1 = require("./list");

@@ -53,15 +52,66 @@ //

};
const derivePivotLoc = (pivot) => {
if (!pivot.left.range || !pivot.args.range) {
return pivot;
}
const start = pivot.left.range[0];
const end = pivot.args.range[1];
return Object.assign(Object.assign({}, pivot), { range: [start, end] });
};
function createJoinExprChain(head, tail) {
return tail.reduce((left, [c1, op, c2, right, spec]) => deriveJoinLoc(createJoinExpr(left, c1, op, c2, right, spec)), head);
return tail.reduce((left, [c1, right]) => right.type === "join_expr_right"
? deriveJoinLoc(createJoinExpr(left, c1, right))
: derivePivotLoc(createPivotExpr(left, c1, right)), head);
}
exports.createJoinExprChain = createJoinExprChain;
function createJoinExpr(left, c1, op, c2, right, spec) {
function createJoinExpr(left, c1, right) {
return {
type: "join_expr",
left: (0, whitespace_1.trailing)(left, c1),
operator: op,
right: (0, whitespace_1.leading)(right, c2),
specification: (0, read_1.read)(spec),
operator: right.operator,
right: right.right,
specification: right.specification,
};
}
function createPivotExpr(left, c1, right) {
return {
type: "pivot_expr",
left: (0, whitespace_1.trailing)(left, c1),
pivotKw: right.pivotKw,
args: right.args,
};
}
function isObjectMemberExprTailPart(part) {
return part[1] === ".";
}
function createMemberExprChain(head, tail) {
return tail.reduce((obj, tailPart) => deriveMemberExprLoc(createMemberExpr(obj, tailPart)), head);
}
exports.createMemberExprChain = createMemberExprChain;
function createMemberExpr(obj, tailPart) {
if (isObjectMemberExprTailPart(tailPart)) {
const [c1, _, c2, prop] = tailPart;
return {
type: "member_expr",
object: (0, whitespace_1.trailing)(obj, c1),
property: (0, whitespace_1.leading)(prop, c2),
};
}
else {
const [c1, prop] = tailPart;
return {
type: "member_expr",
object: obj,
property: (0, whitespace_1.leading)(prop, c1),
};
}
}
const deriveMemberExprLoc = (expr) => {
if (!expr.object.range || !expr.property.range) {
return expr;
}
const start = expr.object.range[0];
const end = expr.property.range[1];
return Object.assign(Object.assign({}, expr), { range: [start, end] });
};
function createPrefixOpExpr(op, expr) {

@@ -68,0 +118,0 @@ return {

@@ -5,3 +5,3 @@ {

"license": "GPL-2.0-or-later",
"version": "0.6.0",
"version": "0.7.0",
"main": "lib/main.js",

@@ -8,0 +8,0 @@ "types": "lib/main.d.ts",

@@ -12,4 +12,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)

- **SQLite** - full support.
- **MySQL** - basic support for the most common SQL statements.
- **BigQuery** - experimental.
- **BigQuery** - experimental (see [#2](https://github.com/nene/sql-parser-cst/issues/2) for list of unsupported syntax).
- **MySQL** - experimental (see [#5](https://github.com/nene/sql-parser-cst/issues/5) for list of unsupported syntax).

@@ -111,6 +111,3 @@ **Note:** This software is still in very active development.

"type": "binary_expr",
"left": {
"type": "column_ref",
"column": { "type": "identifier", "text": "\"first_name\"", "name": "first_name" }
},
"left": { "type": "identifier", "text": "\"first_name\"", "name": "first_name" },
"operator": "||",

@@ -117,0 +114,0 @@ "right": { "type": "string", "text": "' jr.'", "value": " jr." }

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc