prettier-plugin-sql-cst 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CstToDocMap.d.ts → src/CstToDocMap.d.ts} +2 -2
- package/dist/src/CstToDocMap.js +1 -0
- package/dist/src/PrintFn.js +1 -0
- package/dist/src/embed.js +6 -0
- package/dist/src/embedJs.js +43 -0
- package/dist/src/embedJson.js +34 -0
- package/dist/src/embedSql.js +39 -0
- package/dist/src/index.js +64 -0
- package/dist/{node_utils.d.ts → src/node_utils.d.ts} +1 -0
- package/dist/src/node_utils.js +44 -0
- package/dist/{options.js → src/options.js} +1 -4
- package/dist/{printComment.js → src/printComment.js} +2 -6
- package/dist/src/printSql.js +61 -0
- package/dist/src/print_utils.js +49 -0
- package/dist/src/syntax/alias.js +3 -0
- package/dist/src/syntax/alter_action.js +120 -0
- package/dist/src/syntax/alter_table.js +19 -0
- package/dist/src/syntax/analyze.js +4 -0
- package/dist/{syntax → src/syntax}/base.js +6 -9
- package/dist/src/syntax/cast.js +4 -0
- package/dist/src/syntax/comment.js +54 -0
- package/dist/{syntax → src/syntax}/constraint.d.ts +1 -1
- package/dist/src/syntax/constraint.js +80 -0
- package/dist/src/syntax/create_table.js +69 -0
- package/dist/src/syntax/data_type.js +29 -0
- package/dist/src/syntax/dcl.js +83 -0
- package/dist/src/syntax/delete.js +5 -0
- package/dist/src/syntax/dialects/bigquery.js +84 -0
- package/dist/src/syntax/dialects/mysql.js +3 -0
- package/dist/src/syntax/dialects/postgresql.js +9 -0
- package/dist/src/syntax/dialects/sqlite.js +9 -0
- package/dist/src/syntax/do.js +4 -0
- package/dist/src/syntax/domain.js +11 -0
- package/dist/src/syntax/drop_table.js +11 -0
- package/dist/src/syntax/explain.js +7 -0
- package/dist/src/syntax/expr.js +224 -0
- package/dist/src/syntax/extension.js +13 -0
- package/dist/src/syntax/frame.js +13 -0
- package/dist/src/syntax/function.js +55 -0
- package/dist/src/syntax/index.js +60 -0
- package/dist/src/syntax/insert.js +33 -0
- package/dist/src/syntax/merge.js +30 -0
- package/dist/src/syntax/other_clauses.js +9 -0
- package/dist/src/syntax/parameter.js +18 -0
- package/dist/src/syntax/policy.js +27 -0
- package/dist/src/syntax/prepared_statements.js +31 -0
- package/dist/src/syntax/proc_clause.js +14 -0
- package/dist/src/syntax/procedural_language.js +104 -0
- package/dist/src/syntax/procedure.js +38 -0
- package/dist/src/syntax/program.js +39 -0
- package/dist/src/syntax/publication.js +27 -0
- package/dist/src/syntax/rename_table.js +8 -0
- package/dist/src/syntax/role.js +31 -0
- package/dist/src/syntax/schema.js +18 -0
- package/dist/src/syntax/select.js +226 -0
- package/dist/src/syntax/sequence.js +36 -0
- package/dist/src/syntax/subscription.js +10 -0
- package/dist/src/syntax/transaction.js +19 -0
- package/dist/src/syntax/transformMap.js +100 -0
- package/dist/src/syntax/trigger.js +52 -0
- package/dist/src/syntax/truncate.js +10 -0
- package/dist/src/syntax/type.js +12 -0
- package/dist/src/syntax/unsupported_grammar.js +4 -0
- package/dist/src/syntax/update.js +14 -0
- package/dist/src/syntax/view.js +48 -0
- package/dist/src/transform/addFinalSemicolon.js +9 -0
- package/dist/src/transform/aliasAs.js +10 -0
- package/dist/{transform → src/transform}/canonicKeywords.js +16 -20
- package/dist/{transform → src/transform}/canonicOperators.js +8 -12
- package/dist/src/transform/comments.js +22 -0
- package/dist/src/transform/stripTrailingCommas.js +15 -0
- package/dist/src/transform/transformCst.js +21 -0
- package/dist/src/transform/transformUtils.js +3 -0
- package/dist/src/utils.js +9 -0
- package/dist/src/visitAllNodes.js +16 -0
- package/dist/tsconfig.json +14 -0
- package/package.json +9 -8
- package/dist/CstToDocMap.js +0 -2
- package/dist/PrintFn.js +0 -2
- package/dist/embed.js +0 -14
- package/dist/embedJs.js +0 -99
- package/dist/embedJson.js +0 -90
- package/dist/embedSql.js +0 -89
- package/dist/index.js +0 -70
- package/dist/node_utils.js +0 -54
- package/dist/printSql.js +0 -71
- package/dist/print_utils.js +0 -68
- package/dist/syntax/alias.js +0 -6
- package/dist/syntax/alter_action.js +0 -213
- package/dist/syntax/alter_table.js +0 -28
- package/dist/syntax/analyze.js +0 -9
- package/dist/syntax/cast.js +0 -7
- package/dist/syntax/comment.js +0 -123
- package/dist/syntax/constraint.js +0 -116
- package/dist/syntax/create_table.js +0 -107
- package/dist/syntax/data_type.js +0 -48
- package/dist/syntax/dcl.js +0 -141
- package/dist/syntax/delete.js +0 -10
- package/dist/syntax/dialects/bigquery.js +0 -130
- package/dist/syntax/dialects/mysql.js +0 -6
- package/dist/syntax/dialects/postgresql.js +0 -14
- package/dist/syntax/dialects/sqlite.js +0 -18
- package/dist/syntax/do.js +0 -7
- package/dist/syntax/domain.js +0 -20
- package/dist/syntax/drop_table.js +0 -16
- package/dist/syntax/explain.js +0 -12
- package/dist/syntax/expr.js +0 -273
- package/dist/syntax/extension.js +0 -22
- package/dist/syntax/frame.js +0 -18
- package/dist/syntax/function.js +0 -65
- package/dist/syntax/index.js +0 -87
- package/dist/syntax/insert.js +0 -50
- package/dist/syntax/merge.js +0 -35
- package/dist/syntax/other_clauses.js +0 -18
- package/dist/syntax/parameter.js +0 -31
- package/dist/syntax/policy.js +0 -42
- package/dist/syntax/prepared_statements.js +0 -51
- package/dist/syntax/proc_clause.js +0 -19
- package/dist/syntax/procedural_language.js +0 -135
- package/dist/syntax/procedure.js +0 -42
- package/dist/syntax/program.js +0 -46
- package/dist/syntax/publication.js +0 -48
- package/dist/syntax/rename_table.js +0 -13
- package/dist/syntax/role.js +0 -56
- package/dist/syntax/schema.js +0 -36
- package/dist/syntax/select.js +0 -295
- package/dist/syntax/sequence.js +0 -53
- package/dist/syntax/subscription.js +0 -25
- package/dist/syntax/transaction.js +0 -34
- package/dist/syntax/transformMap.js +0 -64
- package/dist/syntax/trigger.js +0 -76
- package/dist/syntax/truncate.js +0 -15
- package/dist/syntax/type.js +0 -23
- package/dist/syntax/unsupported_grammar.js +0 -7
- package/dist/syntax/update.js +0 -21
- package/dist/syntax/view.js +0 -59
- package/dist/transform/addFinalSemicolon.js +0 -13
- package/dist/transform/aliasAs.js +0 -14
- package/dist/transform/comments.js +0 -43
- package/dist/transform/stripTrailingCommas.js +0 -19
- package/dist/transform/transformCst.js +0 -25
- package/dist/transform/transformUtils.js +0 -7
- package/dist/utils.js +0 -30
- package/dist/visitAllNodes.js +0 -21
- /package/dist/{PrintFn.d.ts → src/PrintFn.d.ts} +0 -0
- /package/dist/{embed.d.ts → src/embed.d.ts} +0 -0
- /package/dist/{embedJs.d.ts → src/embedJs.d.ts} +0 -0
- /package/dist/{embedJson.d.ts → src/embedJson.d.ts} +0 -0
- /package/dist/{embedSql.d.ts → src/embedSql.d.ts} +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{options.d.ts → src/options.d.ts} +0 -0
- /package/dist/{printComment.d.ts → src/printComment.d.ts} +0 -0
- /package/dist/{printSql.d.ts → src/printSql.d.ts} +0 -0
- /package/dist/{print_utils.d.ts → src/print_utils.d.ts} +0 -0
- /package/dist/{syntax → src/syntax}/alias.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/alter_action.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/alter_table.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/analyze.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/base.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/cast.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/comment.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/create_table.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/data_type.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/dcl.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/delete.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/dialects/bigquery.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/dialects/mysql.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/dialects/postgresql.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/dialects/sqlite.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/do.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/domain.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/drop_table.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/explain.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/expr.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/extension.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/frame.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/function.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/index.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/insert.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/merge.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/other_clauses.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/parameter.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/policy.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/prepared_statements.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/proc_clause.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/procedural_language.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/procedure.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/program.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/publication.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/rename_table.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/role.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/schema.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/select.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/sequence.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/subscription.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/transaction.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/transformMap.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/trigger.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/truncate.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/type.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/unsupported_grammar.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/update.d.ts +0 -0
- /package/dist/{syntax → src/syntax}/view.d.ts +0 -0
- /package/dist/{transform → src/transform}/addFinalSemicolon.d.ts +0 -0
- /package/dist/{transform → src/transform}/aliasAs.d.ts +0 -0
- /package/dist/{transform → src/transform}/canonicKeywords.d.ts +0 -0
- /package/dist/{transform → src/transform}/canonicOperators.d.ts +0 -0
- /package/dist/{transform → src/transform}/comments.d.ts +0 -0
- /package/dist/{transform → src/transform}/stripTrailingCommas.d.ts +0 -0
- /package/dist/{transform → src/transform}/transformCst.d.ts +0 -0
- /package/dist/{transform → src/transform}/transformUtils.d.ts +0 -0
- /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
- /package/dist/{visitAllNodes.d.ts → src/visitAllNodes.d.ts} +0 -0
|
@@ -3,4 +3,4 @@ import { AllConstraintNodes, AlterActionAddConstraint, Constraint } from "sql-pa
|
|
|
3
3
|
import { CstToDocMap } from "../CstToDocMap";
|
|
4
4
|
import { PrintFn } from "../PrintFn";
|
|
5
5
|
export declare const constraintMap: CstToDocMap<AllConstraintNodes>;
|
|
6
|
-
export declare const printUnnamedConstraint: <T>(print: PrintFn<Constraint<T
|
|
6
|
+
export declare const printUnnamedConstraint: <T>(print: PrintFn<Constraint<T>> | PrintFn<AlterActionAddConstraint>, node: Constraint<T> | AlterActionAddConstraint) => Doc;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { group, indent, line, hardline, join } from "../print_utils";
|
|
2
|
+
export const constraintMap = {
|
|
3
|
+
/** cst-ignore: constraint, modifiers */
|
|
4
|
+
constraint: (print, node) => {
|
|
5
|
+
if (node.name) {
|
|
6
|
+
return group([
|
|
7
|
+
print("name"),
|
|
8
|
+
indent([line, printUnnamedConstraint(print, node)]),
|
|
9
|
+
]);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return printUnnamedConstraint(print, node);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
constraint_name: (print) => print.spaced(["constraintKw", "name"]),
|
|
16
|
+
constraint_modifier: (print) => print.spaced("kw"),
|
|
17
|
+
constraint_null: (print) => print("nullKw"),
|
|
18
|
+
constraint_not_null: (print) => group(print.spaced(["notNullKw", "clauses"])),
|
|
19
|
+
constraint_default: (print) => group(print.spaced(["defaultKw", "expr"])),
|
|
20
|
+
constraint_primary_key: (print) => group(print.spaced(["primaryKeyKw", "direction", "columns", "clauses"])),
|
|
21
|
+
constraint_unique: (print) => group(print.spaced(["uniqueKw", "columns", "nullsKw", "clauses"])),
|
|
22
|
+
existing_index: (print) => print.spaced(["usingIndexKw", "index"]),
|
|
23
|
+
constraint_check: (print) => group(print.spaced(["checkKw", "expr", "clauses"])),
|
|
24
|
+
constraint_collate: (print) => group(print.spaced(["collateKw", "collation"])),
|
|
25
|
+
constraint_foreign_key: (print) => group(print.spaced(["foreignKeyKw", "indexName", "columns", "references"])),
|
|
26
|
+
references_specification: (print, node) => {
|
|
27
|
+
const baseDoc = print.spaced(["referencesKw", "table", "columns"]);
|
|
28
|
+
if (node.options.length > 0) {
|
|
29
|
+
return group([
|
|
30
|
+
baseDoc,
|
|
31
|
+
indent([hardline, join(hardline, print("options"))]),
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return baseDoc;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
referential_action: (print) => print.spaced(["onKw", "eventKw", "actionKw", "columns"]),
|
|
39
|
+
referential_match: (print) => print.spaced(["matchKw", "typeKw"]),
|
|
40
|
+
constraint_generated: (print) => print.spaced([
|
|
41
|
+
"generatedKw",
|
|
42
|
+
"asKw",
|
|
43
|
+
"expr",
|
|
44
|
+
"storageKw",
|
|
45
|
+
"sequenceOptions",
|
|
46
|
+
]),
|
|
47
|
+
identity_column: (print) => print("identityKw"),
|
|
48
|
+
constraint_auto_increment: (print) => print("autoIncrementKw"),
|
|
49
|
+
on_conflict_clause: (print) => print.spaced(["onConflictKw", "resolutionKw"]),
|
|
50
|
+
constraint_comment: (print) => print.spaced(["commentKw", "value"]),
|
|
51
|
+
constraint_index: (print) => print.spaced(["indexTypeKw", "indexKw", "columns"]),
|
|
52
|
+
constraint_visible: (print) => print.spaced(["visibleKw"]),
|
|
53
|
+
constraint_column_format: (print) => print.spaced(["columnFormatKw", "formatKw"]),
|
|
54
|
+
constraint_storage: (print) => print.spaced(["storageKw", "typeKw"]),
|
|
55
|
+
constraint_engine_attribute: (print, node) => join(node.hasEq ? " = " : " ", print(["engineAttributeKw", "value"])),
|
|
56
|
+
constraint_compression: (print) => print.spaced(["compressionKw", "method"]),
|
|
57
|
+
constraint_exclude: (print, node) => group([
|
|
58
|
+
print("excludeKw"),
|
|
59
|
+
indent([
|
|
60
|
+
line,
|
|
61
|
+
join(line, [
|
|
62
|
+
print.separated(line, ["using", "params"]),
|
|
63
|
+
...print("clauses"),
|
|
64
|
+
]),
|
|
65
|
+
]),
|
|
66
|
+
]),
|
|
67
|
+
exclusion_param: (print) => print.spaced(["index", "withKw", "operator"]),
|
|
68
|
+
index_tablespace_clause: (print) => print.spaced(["usingIndexTablespaceKw", "name"]),
|
|
69
|
+
};
|
|
70
|
+
export const printUnnamedConstraint = (print, node) => {
|
|
71
|
+
if (node.modifiers.length > 0) {
|
|
72
|
+
return group([
|
|
73
|
+
print("constraint"),
|
|
74
|
+
indent([line, print.spaced("modifiers")]),
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return print("constraint");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isAsClause } from "../node_utils";
|
|
2
|
+
import { group, join, line } from "../print_utils";
|
|
3
|
+
export const createTableMap = {
|
|
4
|
+
/** cst-ignore: clauses */
|
|
5
|
+
create_table_stmt: (print, node, ...rest) => group([
|
|
6
|
+
print.spaced([
|
|
7
|
+
"createKw",
|
|
8
|
+
"orReplaceKw",
|
|
9
|
+
"kind",
|
|
10
|
+
"tableKw",
|
|
11
|
+
"ifNotExistsKw",
|
|
12
|
+
"name",
|
|
13
|
+
"partitionOf",
|
|
14
|
+
"ofType",
|
|
15
|
+
"columns",
|
|
16
|
+
]),
|
|
17
|
+
printClauses(print, node, ...rest),
|
|
18
|
+
node.options ? [line, group(print("options"))] : [],
|
|
19
|
+
]),
|
|
20
|
+
relation_kind: (print) => print.spaced("kindKw"),
|
|
21
|
+
column_definition: (print) => print.spaced(["name", "dataType", "withOptionsKw", "constraints"]),
|
|
22
|
+
table_option: (print, node) => {
|
|
23
|
+
if (node.value && node.hasEq) {
|
|
24
|
+
return [print.spaced("name"), " = ", print.spaced("value")];
|
|
25
|
+
}
|
|
26
|
+
else if (node.value) {
|
|
27
|
+
return [print.spaced("name"), " ", print.spaced("value")];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return print.spaced("name");
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
create_table_like_clause: (print) => print.spaced(["likeKw", "name", "options"]),
|
|
34
|
+
table_like_option: (print) => print.spaced(["includingOrExcludingKw", "optionKw"]),
|
|
35
|
+
create_table_copy_clause: (print) => print.spaced(["copyKw", "name"]),
|
|
36
|
+
create_table_clone_clause: (print) => print.spaced(["cloneKw", "table"]),
|
|
37
|
+
with_partition_columns_clause: (print) => print.spaced(["withPartitionColumnsKw", "columns"]),
|
|
38
|
+
create_table_using_clause: (print) => print.spaced(["usingKw", "module"]),
|
|
39
|
+
create_table_inherits_clause: (print) => print.spaced(["inheritsKw", "tables"]),
|
|
40
|
+
create_table_partition_by_clause: (print) => print.spaced(["partitionByKw", "strategyKw", "columns"]),
|
|
41
|
+
create_table_partition_of_clause: (print) => print.spaced(["partitionOfKw", "table"]),
|
|
42
|
+
create_table_partition_bound_clause: (print) => print.spaced(["forValuesKw", "bound"]),
|
|
43
|
+
partition_bound_in: (print) => print.spaced(["inKw", "values"]),
|
|
44
|
+
partition_bound_from_to: (print) => print.spaced(["fromKw", "from", "toKw", "to"]),
|
|
45
|
+
partition_bound_minvalue: (print) => print.spaced("minvalueKw"),
|
|
46
|
+
partition_bound_maxvalue: (print) => print.spaced("maxvalueKw"),
|
|
47
|
+
partition_bound_with: (print) => print.spaced(["withKw", "values"]),
|
|
48
|
+
partition_bound_modulus: (print) => print.spaced(["modulusKw", "value"]),
|
|
49
|
+
partition_bound_remainder: (print) => print.spaced(["remainderKw", "value"]),
|
|
50
|
+
create_table_default_partition_clause: (print) => print.spaced("defaultKw"),
|
|
51
|
+
create_table_of_type_clause: (print) => print.spaced(["ofKw", "typeName"]),
|
|
52
|
+
using_access_method_clause: (print) => print.spaced(["usingKw", "method"]),
|
|
53
|
+
tablespace_clause: (print) => print.spaced(["tablespaceKw", "name"]),
|
|
54
|
+
create_table_without_oids_clause: (print) => print.spaced("withoutOidsKw"),
|
|
55
|
+
create_table_on_commit_clause: (print) => print.spaced(["onCommitKw", "actionKw"]),
|
|
56
|
+
with_data_clause: (print) => print.spaced("withDataKw"),
|
|
57
|
+
create_table_server_clause: (print) => print.spaced(["serverKw", "name"]),
|
|
58
|
+
};
|
|
59
|
+
const printClauses = (print, node) => {
|
|
60
|
+
if (node.clauses.length === 1 && isAsClause(node.clauses[0])) {
|
|
61
|
+
return [" ", print("clauses")];
|
|
62
|
+
}
|
|
63
|
+
else if (node.clauses.length > 0) {
|
|
64
|
+
return [line, join(line, print("clauses"))];
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isArray } from "../utils";
|
|
2
|
+
import { group, indent, join, softline } from "../print_utils";
|
|
3
|
+
import { isDataTypeName } from "../node_utils";
|
|
4
|
+
export const dataTypeMap = {
|
|
5
|
+
data_type_name: (print) => print.spaced("name"),
|
|
6
|
+
// print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
|
|
7
|
+
modified_data_type: (print, node) => (isMultiWordTypeName(node.dataType) ? print.spaced : print)([
|
|
8
|
+
"dataType",
|
|
9
|
+
"modifiers",
|
|
10
|
+
]),
|
|
11
|
+
setof_data_type: (print) => print.spaced(["setofKw", "dataType"]),
|
|
12
|
+
array_data_type: (print) => print(["dataType", "bounds"]),
|
|
13
|
+
array_bounds: (print) => ["[", print("bounds"), "]"],
|
|
14
|
+
time_data_type: (print, node) => group(join(" ", [
|
|
15
|
+
print(["timeKw", "precision"]),
|
|
16
|
+
...(node.timeZoneKw ? [print.spaced("timeZoneKw")] : []),
|
|
17
|
+
])),
|
|
18
|
+
interval_data_type: (print) => print.spaced(["intervalKw", "unit"]),
|
|
19
|
+
interval_unit_range: (print) => print.spaced(["fromUnit", "toKw", "toUnit"]),
|
|
20
|
+
interval_unit: (print) => print.spaced(["unitKw", "precision"]),
|
|
21
|
+
parametric_data_type: (print) => print(["typeKw", "params"]),
|
|
22
|
+
generic_type_params: (print) => group(["<", indent([softline, print("params")]), softline, ">"]),
|
|
23
|
+
array_type_param: (print) => print.spaced(["dataType", "constraints"]),
|
|
24
|
+
struct_type_param: (print) => print.spaced(["name", "dataType", "constraints"]),
|
|
25
|
+
table_data_type: (print) => print.spaced(["tableKw", "columns"]),
|
|
26
|
+
};
|
|
27
|
+
function isMultiWordTypeName(node) {
|
|
28
|
+
return isDataTypeName(node) && isArray(node.name) && node.name.length > 1;
|
|
29
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { group, indent, join, line } from "../print_utils";
|
|
2
|
+
export const dclMap = {
|
|
3
|
+
grant_privilege_stmt: (print) => group(join(print.dynamicLine(), [
|
|
4
|
+
group([print("grantKw"), indent([line, print("privileges")])]),
|
|
5
|
+
group(print.spaced(["onKw", "resource"])),
|
|
6
|
+
group([print("toKw"), indent([line, print("roles")])]),
|
|
7
|
+
...print("clauses"),
|
|
8
|
+
])),
|
|
9
|
+
grant_role_stmt: (print) => group(join(print.dynamicLine(), [
|
|
10
|
+
group(join(line, [
|
|
11
|
+
group([print("grantKw"), indent([line, print("grantedRoles")])]),
|
|
12
|
+
group([print("toKw"), indent([line, print("granteeRoles")])]),
|
|
13
|
+
])),
|
|
14
|
+
...print("clauses"),
|
|
15
|
+
])),
|
|
16
|
+
revoke_privilege_stmt: (print) => group(join(print.dynamicLine(), [
|
|
17
|
+
group([
|
|
18
|
+
print.spaced(["revokeKw", "option"]),
|
|
19
|
+
indent([line, print("privileges")]),
|
|
20
|
+
]),
|
|
21
|
+
group(print.spaced(["onKw", "resource"])),
|
|
22
|
+
group([print("fromKw"), indent([line, print("roles")])]),
|
|
23
|
+
...print(["grantedBy", "behaviorKw"]),
|
|
24
|
+
])),
|
|
25
|
+
revoke_role_stmt: (print) => group(join(print.dynamicLine(), [
|
|
26
|
+
group(join(line, [
|
|
27
|
+
group([
|
|
28
|
+
print.spaced(["revokeKw", "option"]),
|
|
29
|
+
indent([line, print("grantedRoles")]),
|
|
30
|
+
]),
|
|
31
|
+
group([print("fromKw"), indent([line, print("granteeRoles")])]),
|
|
32
|
+
])),
|
|
33
|
+
...print(["grantedBy", "behaviorKw"]),
|
|
34
|
+
])),
|
|
35
|
+
privilege: (print) => print.spaced(["privilegeKw", "columns"]),
|
|
36
|
+
all_privileges: (print) => print.spaced(["allKw", "privilegesKw", "columns"]),
|
|
37
|
+
grant_resource_table: (print) => group(print.spaced(["tableKw", "tables"])),
|
|
38
|
+
grant_resource_view: (print) => group(print.spaced(["viewKw", "views"])),
|
|
39
|
+
grant_resource_schema: (print) => group(print.spaced(["schemaKw", "schemas"])),
|
|
40
|
+
grant_resource_sequence: (print) => group(print.spaced(["sequenceKw", "sequences"])),
|
|
41
|
+
grant_resource_database: (print) => group(print.spaced(["databaseKw", "databases"])),
|
|
42
|
+
grant_resource_domain: (print) => group(print.spaced(["domainKw", "domains"])),
|
|
43
|
+
grant_resource_foreign_data_wrapper: (print) => group(print.spaced(["foreignDataWrapperKw", "dataWrappers"])),
|
|
44
|
+
grant_resource_foreign_server: (print) => group(print.spaced(["foreignServerKw", "servers"])),
|
|
45
|
+
grant_resource_function: (print) => group(print.spaced(["functionKw", "functions"])),
|
|
46
|
+
grant_resource_language: (print) => group(print.spaced(["languageKw", "languages"])),
|
|
47
|
+
grant_resource_large_object: (print) => group(print.spaced(["largeObjectKw", "oids"])),
|
|
48
|
+
grant_resource_postgresql_option: (print) => group(print.spaced(["parameterKw", "options"])),
|
|
49
|
+
grant_resource_tablespace: (print) => group(print.spaced(["tablespaceKw", "tablespaces"])),
|
|
50
|
+
grant_resource_type: (print) => group(print.spaced(["typeKw", "types"])),
|
|
51
|
+
grant_resource_all_tables_in_schema: (print) => group(print.spaced(["allTablesInSchemaKw", "schemas"])),
|
|
52
|
+
grant_resource_all_sequences_in_schema: (print) => group(print.spaced(["allSequencesInSchemaKw", "schemas"])),
|
|
53
|
+
grant_resource_all_functions_in_schema: (print) => group(print.spaced(["allFunctionsInSchemaKw", "schemas"])),
|
|
54
|
+
with_grant_option_clause: (print) => group(print.spaced(["withKw", "nameKw", "value"])),
|
|
55
|
+
grant_option_for_clause: (print) => group(print.spaced(["nameKw", "optionForKw"])),
|
|
56
|
+
granted_by_clause: (print) => group(print.spaced(["grantedByKw", "role"])),
|
|
57
|
+
grantee_public: (print) => print("publicKw"),
|
|
58
|
+
grantee_group: (print) => group(print.spaced(["groupKw", "name"])),
|
|
59
|
+
alter_default_privileges_stmt: (print) => group(join(print.dynamicLine(), [
|
|
60
|
+
print.spaced("alterDefaultPrivilegesKw"),
|
|
61
|
+
...print("clauses"),
|
|
62
|
+
print("action"),
|
|
63
|
+
])),
|
|
64
|
+
default_acl_for_role_clause: (print) => group(print.spaced(["forKw", "roleKw", "roles"])),
|
|
65
|
+
default_acl_in_schema_clause: (print) => group(print.spaced(["inKw", "schemaKw", "schemas"])),
|
|
66
|
+
grant_default_privileges_action: (print) => group(join(line, [
|
|
67
|
+
group(print.spaced(["grantKw", "privileges", "onKw", "resourcesKw"])),
|
|
68
|
+
group(print.spaced(["toKw", "roles", "withGrantOption"])),
|
|
69
|
+
])),
|
|
70
|
+
revoke_default_privileges_action: (print) => group(join(line, [
|
|
71
|
+
group([
|
|
72
|
+
print.spaced(["revokeKw", "grantOptionFor"]),
|
|
73
|
+
indent([
|
|
74
|
+
line,
|
|
75
|
+
join(line, [
|
|
76
|
+
group(print("privileges")),
|
|
77
|
+
print.spaced(["onKw", "resourcesKw"]),
|
|
78
|
+
]),
|
|
79
|
+
]),
|
|
80
|
+
]),
|
|
81
|
+
group(print.spaced(["fromKw", "roles", "behaviorKw"])),
|
|
82
|
+
])),
|
|
83
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { group, hardline, join } from "../../print_utils";
|
|
2
|
+
export const bigqueryMap = {
|
|
3
|
+
bigquery_options: (print) => print.spaced(["optionsKw", "options"]),
|
|
4
|
+
bigquery_option_default_collate: (print) => print.spaced(["defaultCollateKw", "collation"]),
|
|
5
|
+
// ROW ACCESS POLICY
|
|
6
|
+
create_row_access_policy_stmt: (print) => group(join(hardline, [
|
|
7
|
+
print.spaced([
|
|
8
|
+
"createKw",
|
|
9
|
+
"orReplaceKw",
|
|
10
|
+
"rowAccessPolicyKw",
|
|
11
|
+
"ifNotExistsKw",
|
|
12
|
+
"name",
|
|
13
|
+
"onKw",
|
|
14
|
+
"table",
|
|
15
|
+
]),
|
|
16
|
+
...print("clauses"),
|
|
17
|
+
])),
|
|
18
|
+
row_access_policy_grant_clause: (print) => print.spaced(["grantToKw", "grantees"]),
|
|
19
|
+
row_access_policy_filter_clause: (print) => print.spaced(["filterUsingKw", "expr"]),
|
|
20
|
+
drop_row_access_policy_stmt: (print) => group(print.spaced([
|
|
21
|
+
"dropKw",
|
|
22
|
+
"allKw",
|
|
23
|
+
"rowAccessPolicyKw",
|
|
24
|
+
"ifExistsKw",
|
|
25
|
+
"name",
|
|
26
|
+
"onKw",
|
|
27
|
+
"table",
|
|
28
|
+
])),
|
|
29
|
+
// CAPACITY
|
|
30
|
+
create_capacity_stmt: (print) => group([
|
|
31
|
+
print.spaced(["createKw", "capacityKw", "name"]),
|
|
32
|
+
hardline,
|
|
33
|
+
print("options"),
|
|
34
|
+
]),
|
|
35
|
+
drop_capacity_stmt: (print) => group(print.spaced(["dropKw", "capacityKw", "ifExistsKw", "name"])),
|
|
36
|
+
// RESERVATION
|
|
37
|
+
create_reservation_stmt: (print) => group([
|
|
38
|
+
print.spaced(["createKw", "reservationKw", "name"]),
|
|
39
|
+
hardline,
|
|
40
|
+
print("options"),
|
|
41
|
+
]),
|
|
42
|
+
drop_reservation_stmt: (print) => group(print.spaced(["dropKw", "reservationKw", "ifExistsKw", "name"])),
|
|
43
|
+
// ASSIGNMENT
|
|
44
|
+
create_assignment_stmt: (print) => group([
|
|
45
|
+
print.spaced(["createKw", "assignmentKw", "name"]),
|
|
46
|
+
hardline,
|
|
47
|
+
print("options"),
|
|
48
|
+
]),
|
|
49
|
+
drop_assignment_stmt: (print) => group(print.spaced(["dropKw", "assignmentKw", "ifExistsKw", "name"])),
|
|
50
|
+
// ALTER ORGANIZATION
|
|
51
|
+
alter_organization_stmt: (print) => group(join(hardline, [print.spaced("alterOrganizationKw"), print("actions")])),
|
|
52
|
+
// ALTER PROJECT
|
|
53
|
+
alter_project_stmt: (print) => group(join(hardline, [
|
|
54
|
+
print.spaced(["alterProjectKw", "name"]),
|
|
55
|
+
print("actions"),
|
|
56
|
+
])),
|
|
57
|
+
alter_bi_capacity_stmt: (print) => group(join(hardline, [
|
|
58
|
+
print.spaced(["alterBiCapacityKw", "name"]),
|
|
59
|
+
print("actions"),
|
|
60
|
+
])),
|
|
61
|
+
alter_capacity_stmt: (print) => group(join(hardline, [
|
|
62
|
+
print.spaced(["alterCapacityKw", "name"]),
|
|
63
|
+
print("actions"),
|
|
64
|
+
])),
|
|
65
|
+
alter_reservation_stmt: (print) => group(join(hardline, [
|
|
66
|
+
print.spaced(["alterReservationKw", "name"]),
|
|
67
|
+
print("actions"),
|
|
68
|
+
])),
|
|
69
|
+
// ASSERT
|
|
70
|
+
assert_stmt: (print) => group(print.spaced(["assertKw", "expr", "as"])),
|
|
71
|
+
// EXPORT
|
|
72
|
+
export_data_stmt: (print) => group(join(hardline, [
|
|
73
|
+
print.spaced("exportDataKw"),
|
|
74
|
+
...print.spaced(["withConnection"]),
|
|
75
|
+
print.spaced("options"),
|
|
76
|
+
print.spaced("as"),
|
|
77
|
+
])),
|
|
78
|
+
// LOAD
|
|
79
|
+
load_data_stmt: (print) => group(join(hardline, [
|
|
80
|
+
print.spaced(["loadDataKw", "intoKw", "table", "columns"]),
|
|
81
|
+
...print("clauses"),
|
|
82
|
+
])),
|
|
83
|
+
from_files_options: (print) => print.spaced(["fromFilesKw", "options"]),
|
|
84
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { group } from "../../print_utils";
|
|
2
|
+
export const postgresqlMap = {
|
|
3
|
+
postgresql_operator_expr: (print) => print(["operatorKw", "expr"]),
|
|
4
|
+
postgresql_operator: (print) => print("operator"),
|
|
5
|
+
postgresql_operator_class: (print) => print.spaced(["name", "options"]),
|
|
6
|
+
postgresql_with_options: (print) => group(print.spaced(["withKw", "options"])),
|
|
7
|
+
postgresql_options: (print) => print.spaced(["optionsKw", "options"]),
|
|
8
|
+
postgresql_option_element: (print) => print.spaced(["name", "value"]),
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { group, join } from "../../print_utils";
|
|
2
|
+
export const sqliteMap = {
|
|
3
|
+
attach_database_stmt: (print) => group(print.spaced(["attachKw", "databaseKw", "file", "asKw", "schema"])),
|
|
4
|
+
detach_database_stmt: (print) => group(print.spaced(["detachKw", "databaseKw", "schema"])),
|
|
5
|
+
vacuum_stmt: (print) => group(print.spaced(["vacuumKw", "schema", "intoKw", "file"])),
|
|
6
|
+
pragma_stmt: (print) => group(print.spaced(["pragmaKw", "pragma"])),
|
|
7
|
+
pragma_assignment: (print) => join(" = ", print(["name", "value"])),
|
|
8
|
+
pragma_func_call: (print) => print(["name", "args"]),
|
|
9
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { group, line, indent, join } from "../print_utils";
|
|
2
|
+
export const domainMap = {
|
|
3
|
+
create_domain_stmt: (print, node) => group([
|
|
4
|
+
print.spaced(["createDomainKw", "name", "asKw", "dataType"]),
|
|
5
|
+
node.constraints.length > 0
|
|
6
|
+
? indent([print.dynamicLine(), join(line, print("constraints"))])
|
|
7
|
+
: [],
|
|
8
|
+
]),
|
|
9
|
+
alter_domain_stmt: (print) => group(print.spaced(["alterDomainKw", "name", "action"])),
|
|
10
|
+
drop_domain_stmt: (print) => group(print.spaced(["dropDomainKw", "ifExistsKw", "domains", "behaviorKw"])),
|
|
11
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { join, line, softline, hardline, indent, group, stripTrailingHardline, } from "../print_utils";
|
|
2
|
+
import { isCreateTableStmt, isKeyword, isValuesClause, isEmpty, isArraySubscript, isParenExpr, isFuncArgs, isListExpr, isProgram, isSelectStmt, isCompoundSelectStmt, isBigqueryQuotedMemberExpr, isFuncCall, isMemberExpr, isCreateFunctionStmt, isAlterFunctionStmt, isAlterActionRename, isCreateProcedureStmt, isAlterProcedureStmt, isCreateTriggerStmt, isExecuteClause, isFunctionSignature, } from "../node_utils";
|
|
3
|
+
import { isString, last } from "../utils";
|
|
4
|
+
export const exprMap = {
|
|
5
|
+
list_expr: (print, node, path) => {
|
|
6
|
+
const parent = path.getParentNode();
|
|
7
|
+
const children = print("items").map((it) => group(it));
|
|
8
|
+
const lineType = isValuesClause(parent) ? hardline : line;
|
|
9
|
+
// When last item is type:empty, we're dealing with a trailing comma.
|
|
10
|
+
// Don't add a space (or newline) after it.
|
|
11
|
+
// We still want to print it though, as it might have comments attached.
|
|
12
|
+
if (isEmpty(last(node.items))) {
|
|
13
|
+
return [
|
|
14
|
+
join([",", lineType], children.slice(0, -1)),
|
|
15
|
+
",",
|
|
16
|
+
last(children),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return join([",", lineType], children);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
paren_expr: (print, node, path) => {
|
|
24
|
+
// discard unnecessary nested ((parentheses))
|
|
25
|
+
if (isParenExpr(node.expr)) {
|
|
26
|
+
return print("expr");
|
|
27
|
+
}
|
|
28
|
+
// Discard unnecessary parenthesis around function arguments
|
|
29
|
+
if (isListExpr(path.getParentNode(0)) &&
|
|
30
|
+
isFuncArgs(path.getParentNode(1)) &&
|
|
31
|
+
!isSelectStmt(node.expr) &&
|
|
32
|
+
!isCompoundSelectStmt(node.expr)) {
|
|
33
|
+
return print("expr");
|
|
34
|
+
}
|
|
35
|
+
const parent = path.getParentNode();
|
|
36
|
+
const lineStyle = isCreateTableStmt(parent) && print.dynamicLine() === hardline
|
|
37
|
+
? hardline
|
|
38
|
+
: softline;
|
|
39
|
+
return group(["(", indent([lineStyle, print("expr")]), lineStyle, ")"]);
|
|
40
|
+
},
|
|
41
|
+
binary_expr: (print, node) => {
|
|
42
|
+
if (isKeyword(node.operator) && isBooleanOp(node.operator)) {
|
|
43
|
+
return join(line, [print("left"), print.spaced(["operator", "right"])]);
|
|
44
|
+
}
|
|
45
|
+
if (node.operator === "") {
|
|
46
|
+
// String concatenation with whitespace (MySQL / MariaDB)
|
|
47
|
+
return print.spaced(["left", "right"]);
|
|
48
|
+
}
|
|
49
|
+
return print.spaced(["left", "operator", "right"]);
|
|
50
|
+
},
|
|
51
|
+
prefix_op_expr: (print, node) => (isString(node.operator) ? print : print.spaced)(["operator", "expr"]),
|
|
52
|
+
postfix_op_expr: (print) => print.spaced(["expr", "operator"]),
|
|
53
|
+
between_expr: (print) => print.spaced(["left", "betweenKw", "begin", "andKw", "end"]),
|
|
54
|
+
case_expr: (print) => [
|
|
55
|
+
print.spaced(["caseKw", "expr"]),
|
|
56
|
+
indent([hardline, join(hardline, print("clauses"))]),
|
|
57
|
+
hardline,
|
|
58
|
+
print("endKw"),
|
|
59
|
+
],
|
|
60
|
+
case_when: (print, node) => {
|
|
61
|
+
if (isProgram(node.result)) {
|
|
62
|
+
return [
|
|
63
|
+
print.spaced(["whenKw", "condition", "thenKw"]),
|
|
64
|
+
indent([hardline, stripTrailingHardline(print("result"))]),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
return print.spaced(["whenKw", "condition", "thenKw", "result"]);
|
|
68
|
+
},
|
|
69
|
+
case_else: (print, node) => {
|
|
70
|
+
if (isProgram(node.result)) {
|
|
71
|
+
return [
|
|
72
|
+
print("elseKw"),
|
|
73
|
+
indent([hardline, stripTrailingHardline(print("result"))]),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
return print.spaced(["elseKw", "result"]);
|
|
77
|
+
},
|
|
78
|
+
member_expr: (print, node) => isArraySubscript(node.property)
|
|
79
|
+
? print(["object", "property"])
|
|
80
|
+
: [print("object"), ".", print("property")],
|
|
81
|
+
bigquery_quoted_member_expr: (print) => ["`", print("expr"), "`"],
|
|
82
|
+
array_subscript: (print) => group(["[", indent([softline, print("expr")]), softline, "]"]),
|
|
83
|
+
array_subscript_specifier: (print) => print(["specifierKw", "args"]),
|
|
84
|
+
array_slice_specifier: (print) => [print("from"), ":", print("to")],
|
|
85
|
+
func_call: (print) => {
|
|
86
|
+
const fnCall = print(["name", "args"]);
|
|
87
|
+
const extras = print(["filter", "over"]);
|
|
88
|
+
if (extras.length > 1) {
|
|
89
|
+
return group([fnCall, indent([line, join(line, extras)])]);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return group(join(" ", [fnCall, ...extras]));
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
func_args: (print, node) => join(line, [
|
|
96
|
+
...print(["distinctKw", "args"]),
|
|
97
|
+
...(node.nullHandlingKw ? print.spaced("nullHandlingKw") : []),
|
|
98
|
+
...print(["orderBy", "limit", "having"]),
|
|
99
|
+
]),
|
|
100
|
+
filter_arg: (print) => print.spaced(["filterKw", "where"]),
|
|
101
|
+
over_arg: (print) => print.spaced(["overKw", "window"]),
|
|
102
|
+
having_arg: (print) => print.spaced(["havingKw", "minMaxKw", "expr"]),
|
|
103
|
+
named_arg: (print) => group([
|
|
104
|
+
print("name"),
|
|
105
|
+
" ",
|
|
106
|
+
print("operator"),
|
|
107
|
+
indent([line, print("value")]),
|
|
108
|
+
]),
|
|
109
|
+
cast_expr: (print) => print(["castKw", "args"]),
|
|
110
|
+
cast_arg: (print) => print.spaced(["expr", "asKw", "dataType", "format"]),
|
|
111
|
+
cast_format: (print) => print.spaced(["formatKw", "string", "timezone"]),
|
|
112
|
+
cast_format_timezone: (print) => print.spaced(["atTimeZoneKw", "timezone"]),
|
|
113
|
+
cast_operator_expr: (print) => [
|
|
114
|
+
print("left"),
|
|
115
|
+
print("operator"),
|
|
116
|
+
print("right"),
|
|
117
|
+
],
|
|
118
|
+
string_with_charset: (print) => ["_", print(["charset", "string"])],
|
|
119
|
+
raise_expr: (print) => print(["raiseKw", "args"]),
|
|
120
|
+
raise_expr_type: (print) => print("typeKw"),
|
|
121
|
+
extract_expr: (print) => print(["extractKw", "args"]),
|
|
122
|
+
extract_from: (print) => print.spaced(["unit", "fromKw", "expr"]),
|
|
123
|
+
week_expr: (print) => print(["weekKw", "args"]),
|
|
124
|
+
interval_literal: (print) => print.spaced(["intervalKw", "precision", "value", "unit"]),
|
|
125
|
+
array_literal_expr: (print) => print(["arrayKw", "expr"]),
|
|
126
|
+
array_expr: (print) => group(["[", indent([softline, print("expr")]), softline, "]"]),
|
|
127
|
+
struct_expr: (print) => group(["(", indent([softline, print("expr")]), softline, ")"]),
|
|
128
|
+
typed_expr: (print) => print(["dataType", "expr"]),
|
|
129
|
+
row_constructor: (print) => print(["rowKw", "row"]),
|
|
130
|
+
array_constructor: (print) => print(["arrayKw", "expr"]),
|
|
131
|
+
quantifier_expr: (print) => print.spaced(["quantifierKw", "expr"]),
|
|
132
|
+
full_text_match_expr: (print) => print.spaced(["matchKw", "columns", "againstKw", "args"]),
|
|
133
|
+
full_text_match_args: (print) => print.spaced(["expr", "modifier"]),
|
|
134
|
+
/** cst-ignore: value */
|
|
135
|
+
number_literal: (print) => print("text"),
|
|
136
|
+
/** cst-ignore: value */
|
|
137
|
+
boolean_literal: (print, node, path, options) => printLiteral(node.valueKw, options),
|
|
138
|
+
/** cst-ignore: value */
|
|
139
|
+
string_literal: (print) => print("text"),
|
|
140
|
+
/** cst-ignore: value */
|
|
141
|
+
blob_literal: (print) => print("text"),
|
|
142
|
+
/** cst-ignore: value */
|
|
143
|
+
null_literal: (print, node, path, options) => printLiteral(node.nullKw, options),
|
|
144
|
+
numeric_literal: (print) => print.spaced(["numericKw", "string"]),
|
|
145
|
+
bignumeric_literal: (print) => print.spaced(["bignumericKw", "string"]),
|
|
146
|
+
date_literal: (print) => print.spaced(["dateKw", "string"]),
|
|
147
|
+
time_literal: (print) => print.spaced(["timeKw", "string"]),
|
|
148
|
+
datetime_literal: (print) => print.spaced(["datetimeKw", "string"]),
|
|
149
|
+
timestamp_literal: (print) => print.spaced(["timestampKw", "string"]),
|
|
150
|
+
json_literal: (print) => print.spaced(["jsonKw", "string"]),
|
|
151
|
+
jsonb_literal: (print) => print.spaced(["jsonbKw", "string"]),
|
|
152
|
+
/** cst-ignore: name */
|
|
153
|
+
identifier: (print, node, path, options) => {
|
|
154
|
+
if (isQuotedIdentifier(node) || isInsideBigqueryQuotedMemberExpr(path)) {
|
|
155
|
+
return print("text");
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
if (isFunctionName(node, path)) {
|
|
159
|
+
return printFunctionName(node, options);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return printIdentifier(node, options);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
/** cst-ignore: name */
|
|
167
|
+
variable: (print, node, path, options) => isQuotedVariable(node) ? print("text") : printIdentifier(node, options),
|
|
168
|
+
parameter: (print, node, path, options) => isQuotedParameter(node) ? print("text") : printIdentifier(node, options),
|
|
169
|
+
};
|
|
170
|
+
export const printLiteral = (node, options) => {
|
|
171
|
+
switch (options.sqlLiteralCase) {
|
|
172
|
+
case "preserve":
|
|
173
|
+
return node.text;
|
|
174
|
+
case "upper":
|
|
175
|
+
return node.text.toUpperCase();
|
|
176
|
+
case "lower":
|
|
177
|
+
return node.text.toLowerCase();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const printIdentifier = (node, options) => {
|
|
181
|
+
switch (options.sqlIdentifierCase) {
|
|
182
|
+
case "preserve":
|
|
183
|
+
return node.text;
|
|
184
|
+
case "upper":
|
|
185
|
+
return node.text.toUpperCase();
|
|
186
|
+
case "lower":
|
|
187
|
+
return node.text.toLowerCase();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const printFunctionName = (node, options) => {
|
|
191
|
+
switch (options.sqlFunctionCase) {
|
|
192
|
+
case "preserve":
|
|
193
|
+
return node.text;
|
|
194
|
+
case "upper":
|
|
195
|
+
return node.text.toUpperCase();
|
|
196
|
+
case "lower":
|
|
197
|
+
return node.text.toLowerCase();
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const isQuotedIdentifier = (node) => node.name !== node.text;
|
|
201
|
+
const isQuotedVariable = (node) => !(node.text === "@" + node.name || node.text === "@@" + node.name);
|
|
202
|
+
const isQuotedParameter = (node) => /`$/.test(node.text);
|
|
203
|
+
const isInsideBigqueryQuotedMemberExpr = (path) => path.ancestors.some(isBigqueryQuotedMemberExpr);
|
|
204
|
+
const isFunctionName = (node, path) => {
|
|
205
|
+
const parent = path.parent;
|
|
206
|
+
if (isFunctionContext(parent, path.grandparent)) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
if (isMemberExpr(parent) && parent.property === node) {
|
|
210
|
+
const [_, gp, ggp] = path.ancestors;
|
|
211
|
+
return isFunctionContext(gp, ggp);
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
};
|
|
215
|
+
const isFunctionContext = (node, parent) => {
|
|
216
|
+
return (isFuncCall(node) ||
|
|
217
|
+
isFunctionSignature(node) ||
|
|
218
|
+
isCreateFunctionStmt(node) ||
|
|
219
|
+
isCreateProcedureStmt(node) ||
|
|
220
|
+
(isAlterActionRename(node) &&
|
|
221
|
+
(isAlterFunctionStmt(parent) || isAlterProcedureStmt(parent))) ||
|
|
222
|
+
(isExecuteClause(node) && isCreateTriggerStmt(parent)));
|
|
223
|
+
};
|
|
224
|
+
const isBooleanOp = ({ name }) => name === "AND" || name === "OR";
|