prettier-plugin-sql-cst 0.18.0 → 0.19.1
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 +2 -2
- package/dist/CstToDocMap.js +1 -2
- package/dist/PrintFn.js +1 -2
- package/dist/embed.js +5 -13
- package/dist/embedJs.js +28 -84
- package/dist/embedJson.js +29 -85
- package/dist/embedSql.js +26 -76
- package/dist/index.js +28 -34
- package/dist/node_utils.d.ts +1 -0
- package/dist/node_utils.js +44 -54
- package/dist/options.js +1 -4
- package/dist/printComment.js +2 -6
- package/dist/printSql.js +29 -39
- package/dist/print_utils.js +19 -38
- package/dist/syntax/alias.js +2 -5
- package/dist/syntax/alter_action.js +115 -208
- package/dist/syntax/alter_table.js +18 -27
- package/dist/syntax/analyze.js +3 -8
- package/dist/syntax/base.js +6 -9
- package/dist/syntax/cast.js +3 -6
- package/dist/syntax/comment.js +53 -122
- package/dist/syntax/constraint.d.ts +1 -1
- package/dist/syntax/constraint.js +54 -90
- package/dist/syntax/create_table.js +49 -87
- package/dist/syntax/data_type.js +25 -44
- package/dist/syntax/dcl.js +78 -136
- package/dist/syntax/delete.js +4 -9
- package/dist/syntax/dialects/bigquery.js +70 -116
- package/dist/syntax/dialects/mysql.js +2 -5
- package/dist/syntax/dialects/postgresql.js +8 -13
- package/dist/syntax/dialects/sqlite.js +8 -17
- package/dist/syntax/do.js +3 -6
- package/dist/syntax/domain.js +10 -19
- package/dist/syntax/drop_table.js +10 -15
- package/dist/syntax/explain.js +6 -11
- package/dist/syntax/expr.js +124 -173
- package/dist/syntax/extension.js +12 -21
- package/dist/syntax/frame.js +11 -16
- package/dist/syntax/function.js +53 -63
- package/dist/syntax/index.js +54 -81
- package/dist/syntax/insert.js +32 -49
- package/dist/syntax/merge.js +25 -30
- package/dist/syntax/other_clauses.js +5 -14
- package/dist/syntax/parameter.js +13 -26
- package/dist/syntax/policy.js +26 -41
- package/dist/syntax/prepared_statements.js +23 -43
- package/dist/syntax/proc_clause.js +10 -15
- package/dist/syntax/procedural_language.js +80 -111
- package/dist/syntax/procedure.js +36 -40
- package/dist/syntax/program.js +15 -22
- package/dist/syntax/publication.js +26 -47
- package/dist/syntax/rename_table.js +7 -12
- package/dist/syntax/role.js +30 -55
- package/dist/syntax/schema.js +17 -35
- package/dist/syntax/select.js +157 -226
- package/dist/syntax/sequence.js +35 -52
- package/dist/syntax/subscription.js +9 -24
- package/dist/syntax/transaction.js +18 -33
- package/dist/syntax/transformMap.js +99 -63
- package/dist/syntax/trigger.js +48 -72
- package/dist/syntax/truncate.js +9 -14
- package/dist/syntax/type.js +11 -22
- package/dist/syntax/unsupported_grammar.js +3 -6
- package/dist/syntax/update.js +7 -14
- package/dist/syntax/view.js +32 -43
- package/dist/transform/addFinalSemicolon.js +5 -9
- package/dist/transform/aliasAs.js +4 -8
- package/dist/transform/canonicKeywords.js +16 -20
- package/dist/transform/canonicOperators.js +8 -12
- package/dist/transform/comments.js +10 -31
- package/dist/transform/stripTrailingCommas.js +7 -11
- package/dist/transform/transformCst.js +13 -17
- package/dist/transform/transformUtils.js +2 -6
- package/dist/utils.js +9 -30
- package/dist/visitAllNodes.js +8 -13
- package/package.json +9 -8
package/dist/printSql.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var transformMap_1 = require("./syntax/transformMap");
|
|
6
|
-
var print_utils_1 = require("./print_utils");
|
|
7
|
-
function printSql(path, options, oldPrint) {
|
|
1
|
+
import { arrayWrap, isArray, isDefined, isEmptyArray, isString } from "./utils";
|
|
2
|
+
import { transformMap } from "./syntax/transformMap";
|
|
3
|
+
import { containsNewline, hardline, join, line } from "./print_utils";
|
|
4
|
+
export function printSql(path, options, oldPrint) {
|
|
8
5
|
return printNode(path, options, createPrintFn(path, oldPrint, options));
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var cachedPath;
|
|
7
|
+
let cachedPrintFn;
|
|
8
|
+
let cachedPath;
|
|
13
9
|
function createPrintFn(path, oldPrint, opts) {
|
|
14
10
|
// The path parameter will reference the same AstPath instance
|
|
15
11
|
// during the whole printing cycle.
|
|
@@ -19,53 +15,47 @@ function createPrintFn(path, oldPrint, opts) {
|
|
|
19
15
|
return cachedPrintFn;
|
|
20
16
|
}
|
|
21
17
|
cachedPath = path;
|
|
22
|
-
cachedPrintFn = (
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
return selector.filter(
|
|
18
|
+
cachedPrintFn = ((selector) => {
|
|
19
|
+
if (isArray(selector)) {
|
|
20
|
+
const node = path.node;
|
|
21
|
+
return selector.filter((sel) => isDefined(node[sel])).map(oldPrint);
|
|
26
22
|
}
|
|
27
23
|
else {
|
|
28
24
|
return oldPrint(selector);
|
|
29
25
|
}
|
|
30
26
|
});
|
|
31
|
-
cachedPrintFn.separated =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.filter(
|
|
35
|
-
.map(
|
|
27
|
+
cachedPrintFn.separated = (separator, selector) => {
|
|
28
|
+
const node = path.node;
|
|
29
|
+
const docs = arrayWrap(selector)
|
|
30
|
+
.filter((sel) => isDefined(node[sel]))
|
|
31
|
+
.map((sel) => [sel, oldPrint(sel)])
|
|
36
32
|
// skip empty arrays
|
|
37
|
-
.filter(
|
|
38
|
-
var sel = _a[0], doc = _a[1];
|
|
39
|
-
return !(0, utils_1.isEmptyArray)(doc);
|
|
40
|
-
})
|
|
33
|
+
.filter(([sel, doc]) => !isEmptyArray(doc))
|
|
41
34
|
// only join with spaces when input to print was Node[]
|
|
42
|
-
.map(
|
|
43
|
-
|
|
44
|
-
return ((0, utils_1.isArray)(node[sel]) ? (0, print_utils_1.join)(" ", doc) : doc);
|
|
45
|
-
});
|
|
46
|
-
return docs.length > 0 ? [(0, print_utils_1.join)(separator, docs)] : [];
|
|
35
|
+
.map(([sel, doc]) => (isArray(node[sel]) ? join(" ", doc) : doc));
|
|
36
|
+
return docs.length > 0 ? [join(separator, docs)] : [];
|
|
47
37
|
};
|
|
48
|
-
cachedPrintFn.spaced =
|
|
49
|
-
cachedPrintFn.dynamicLine =
|
|
50
|
-
|
|
51
|
-
return
|
|
38
|
+
cachedPrintFn.spaced = (selector) => cachedPrintFn.separated(" ", selector);
|
|
39
|
+
cachedPrintFn.dynamicLine = () => {
|
|
40
|
+
const node = path.node;
|
|
41
|
+
return containsNewline(node, opts) ? hardline : line;
|
|
52
42
|
};
|
|
53
43
|
return cachedPrintFn;
|
|
54
44
|
}
|
|
55
45
|
function printNode(path, options, print) {
|
|
56
|
-
|
|
57
|
-
if (
|
|
46
|
+
const node = path.node;
|
|
47
|
+
if (isArray(node)) {
|
|
58
48
|
return path.map(print);
|
|
59
49
|
}
|
|
60
|
-
if (
|
|
50
|
+
if (isString(node)) {
|
|
61
51
|
return node;
|
|
62
52
|
}
|
|
63
|
-
if (!
|
|
64
|
-
throw new Error(
|
|
53
|
+
if (!node?.type) {
|
|
54
|
+
throw new Error(`No type field on node: ${JSON.stringify(node)}`);
|
|
65
55
|
}
|
|
66
|
-
|
|
56
|
+
const fn = transformMap[node.type];
|
|
67
57
|
if (!fn) {
|
|
68
|
-
throw new Error(
|
|
58
|
+
throw new Error(`Unexpected node type: ${node.type}`);
|
|
69
59
|
}
|
|
70
60
|
return fn(print, node, path, options);
|
|
71
61
|
}
|
package/dist/print_utils.js
CHANGED
|
@@ -1,57 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
var _a;
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.hasEmptyLineBetweenNodes = exports.containsNewline = exports.join = exports.stripTrailingHardline = exports.breakParent = exports.ifBreak = exports.lineSuffix = exports.group = exports.indent = exports.softline = exports.hardline = exports.line = void 0;
|
|
14
|
-
var prettier_1 = require("prettier");
|
|
15
|
-
var utils_1 = require("./utils");
|
|
16
|
-
exports.line = (_a = prettier_1.doc.builders, _a.line), exports.hardline = _a.hardline, exports.softline = _a.softline, exports.indent = _a.indent, exports.group = _a.group, exports.lineSuffix = _a.lineSuffix, exports.ifBreak = _a.ifBreak, exports.breakParent = _a.breakParent;
|
|
17
|
-
var origJoin = prettier_1.doc.builders.join;
|
|
18
|
-
exports.stripTrailingHardline = prettier_1.doc.utils.stripTrailingHardline;
|
|
1
|
+
import { doc, util } from "prettier";
|
|
2
|
+
import { isArray } from "./utils";
|
|
3
|
+
export const { line, hardline, softline, indent, group, lineSuffix, ifBreak, breakParent, } = doc.builders;
|
|
4
|
+
const { join: origJoin } = doc.builders;
|
|
5
|
+
export const { stripTrailingHardline } = doc.utils;
|
|
19
6
|
/** Improved join() that also accepts a non-array docs parameter */
|
|
20
|
-
|
|
21
|
-
return (0, utils_1.isArray)(docs) ? origJoin(sep, docs) : docs;
|
|
22
|
-
};
|
|
23
|
-
exports.join = join;
|
|
7
|
+
export const join = (sep, docs) => isArray(docs) ? origJoin(sep, docs) : docs;
|
|
24
8
|
/** True when the Node contains a newline in original source code */
|
|
25
|
-
|
|
9
|
+
export const containsNewline = (node, opts) => {
|
|
26
10
|
if (!node.range) {
|
|
27
11
|
throw new Error("containsNewline() expected a Node with range info");
|
|
28
12
|
}
|
|
29
|
-
return
|
|
13
|
+
return util.hasNewlineInRange(opts.originalText, node.range[0], node.range[1]);
|
|
30
14
|
};
|
|
31
|
-
|
|
32
|
-
var hasEmptyLineBetweenNodes = function (node1, node2, opts) {
|
|
33
|
-
var _a, _b;
|
|
15
|
+
export const hasEmptyLineBetweenNodes = (node1, node2, opts) => {
|
|
34
16
|
if (!node1.range || !node2.range) {
|
|
35
17
|
throw new Error("emptyLineBetweenNodes() expects Nodes with range info");
|
|
36
18
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
const start = node1.range[1];
|
|
20
|
+
const end = node2.range[0];
|
|
21
|
+
const indexes = emptyLineIndexes(opts.originalText.slice(start, end)).map((i) => start + i);
|
|
40
22
|
// when no empty lines between nodes, we can return early
|
|
41
23
|
if (indexes.length === 0) {
|
|
42
24
|
return false;
|
|
43
25
|
}
|
|
44
26
|
// otherwise we need to check whether the empty line happens to be
|
|
45
27
|
// inside a comment or between comments
|
|
46
|
-
|
|
47
|
-
return (indexes.filter(
|
|
28
|
+
const comments = [...(node1.trailing ?? []), ...(node2.leading ?? [])];
|
|
29
|
+
return (indexes.filter((index) => !isIndexInsideOrBetweenComments(index, comments))
|
|
48
30
|
.length > 0);
|
|
49
31
|
};
|
|
50
|
-
exports.hasEmptyLineBetweenNodes = hasEmptyLineBetweenNodes;
|
|
51
32
|
function emptyLineIndexes(text) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
33
|
+
const indexes = [];
|
|
34
|
+
const re = /\n[ \t]*\r?\n/g;
|
|
35
|
+
let match;
|
|
55
36
|
while ((match = re.exec(text))) {
|
|
56
37
|
indexes.push(match.index);
|
|
57
38
|
}
|
|
@@ -62,7 +43,7 @@ function isIndexInsideOrBetweenComments(index, comments) {
|
|
|
62
43
|
return false;
|
|
63
44
|
}
|
|
64
45
|
// Assume all nodes have range info
|
|
65
|
-
|
|
66
|
-
|
|
46
|
+
const start = comments[0].range[0];
|
|
47
|
+
const end = comments[comments.length - 1].range[1];
|
|
67
48
|
return start <= index && index <= end;
|
|
68
49
|
}
|
package/dist/syntax/alias.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.aliasMap = void 0;
|
|
4
|
-
exports.aliasMap = {
|
|
5
|
-
alias: function (print) { return print.spaced(["expr", "asKw", "alias", "columnAliases"]); },
|
|
1
|
+
export const aliasMap = {
|
|
2
|
+
alias: (print) => print.spaced(["expr", "asKw", "alias", "columnAliases"]),
|
|
6
3
|
};
|
|
@@ -1,213 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
alter_action_add_column: function (print) {
|
|
12
|
-
return print.spaced(["addKw", "ifNotExistsKw", "column"]);
|
|
13
|
-
},
|
|
14
|
-
alter_action_drop_column: function (print) {
|
|
15
|
-
return print.spaced(["dropKw", "ifExistsKw", "column", "behaviorKw"]);
|
|
16
|
-
},
|
|
17
|
-
alter_action_set_bigquery_options: function (print) {
|
|
18
|
-
return print.spaced(["setKw", "options"]);
|
|
19
|
-
},
|
|
20
|
-
alter_action_set_default_collate: function (print) {
|
|
21
|
-
return print.spaced(["setDefaultCollateKw", "collation"]);
|
|
22
|
-
},
|
|
1
|
+
import { group, indent, join, line } from "../print_utils";
|
|
2
|
+
import { printUnnamedConstraint } from "./constraint";
|
|
3
|
+
export const alterActionMap = {
|
|
4
|
+
alter_action_rename: (print) => print.spaced(["renameKw", "newName"]),
|
|
5
|
+
alter_action_rename_column: (print) => print.spaced(["renameKw", "ifExistsKw", "oldName", "toKw", "newName"]),
|
|
6
|
+
alter_action_add_column: (print) => print.spaced(["addKw", "ifNotExistsKw", "column"]),
|
|
7
|
+
alter_action_drop_column: (print) => print.spaced(["dropKw", "ifExistsKw", "column", "behaviorKw"]),
|
|
8
|
+
alter_action_set_bigquery_options: (print) => print.spaced(["setKw", "options"]),
|
|
9
|
+
alter_action_set_default_collate: (print) => print.spaced(["setDefaultCollateKw", "collation"]),
|
|
23
10
|
/** cst-ignore: constraint, modifiers */
|
|
24
|
-
alter_action_add_constraint:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return print.spaced(["dependsOnExtensionKw", "extension"]);
|
|
92
|
-
},
|
|
93
|
-
alter_action_no_depends_on_extension: function (print) {
|
|
94
|
-
return print.spaced(["noDependsOnExtensionKw", "extension"]);
|
|
95
|
-
},
|
|
96
|
-
alter_action_attach_partition: function (print) {
|
|
97
|
-
return print.spaced(["attachPartitionKw", "index"]);
|
|
98
|
-
},
|
|
99
|
-
alter_action_add_enum_value: function (print) {
|
|
100
|
-
return print.spaced(["addValueKw", "ifNotExistsKw", "value", "position"]);
|
|
101
|
-
},
|
|
102
|
-
alter_action_add_enum_value_position: function (print) {
|
|
103
|
-
return print.spaced(["positionKw", "value"]);
|
|
104
|
-
},
|
|
105
|
-
alter_action_rename_enum_value: function (print) {
|
|
106
|
-
return print.spaced(["renameValueKw", "oldValue", "toKw", "newValue"]);
|
|
107
|
-
},
|
|
108
|
-
alter_action_add_attribute: function (print) {
|
|
109
|
-
return print.spaced([
|
|
110
|
-
"addAttributeKw",
|
|
111
|
-
"name",
|
|
112
|
-
"dataType",
|
|
113
|
-
"constraint",
|
|
114
|
-
"behaviorKw",
|
|
115
|
-
]);
|
|
116
|
-
},
|
|
117
|
-
alter_action_drop_attribute: function (print) {
|
|
118
|
-
return print.spaced(["dropAttributeKw", "ifExistsKw", "name", "behaviorKw"]);
|
|
119
|
-
},
|
|
120
|
-
alter_action_alter_attribute: function (print) {
|
|
121
|
-
return print.spaced([
|
|
122
|
-
"alterAttributeKw",
|
|
123
|
-
"name",
|
|
124
|
-
"setDataTypeKw",
|
|
125
|
-
"dataType",
|
|
126
|
-
"constraint",
|
|
127
|
-
"behaviorKw",
|
|
128
|
-
]);
|
|
129
|
-
},
|
|
130
|
-
alter_action_rename_attribute: function (print) {
|
|
131
|
-
return print.spaced([
|
|
132
|
-
"renameAttributeKw",
|
|
133
|
-
"oldName",
|
|
134
|
-
"toKw",
|
|
135
|
-
"newName",
|
|
136
|
-
"behaviorKw",
|
|
137
|
-
]);
|
|
138
|
-
},
|
|
11
|
+
alter_action_add_constraint: (print, node) => group([
|
|
12
|
+
print.spaced(["addKw", "name"]),
|
|
13
|
+
indent([line, printUnnamedConstraint(print, node)]),
|
|
14
|
+
]),
|
|
15
|
+
alter_action_add_constraint_constraint_name: (print) => print.spaced(["constraintKw", "ifNotExistsKw", "name"]),
|
|
16
|
+
alter_action_drop_constraint: (print) => print.spaced([
|
|
17
|
+
"dropConstraintKw",
|
|
18
|
+
"ifExistsKw",
|
|
19
|
+
"constraint",
|
|
20
|
+
"behaviorKw",
|
|
21
|
+
]),
|
|
22
|
+
alter_action_drop_primary_key: (print) => print.spaced(["dropPrimaryKeyKw", "ifExistsKw"]),
|
|
23
|
+
alter_action_alter_constraint: (print) => print.spaced(["alterConstraintKw", "constraint", "modifiers"]),
|
|
24
|
+
alter_action_rename_constraint: (print) => print.spaced(["renameConstraintKw", "oldName", "toKw", "newName"]),
|
|
25
|
+
alter_action_validate_constraint: (print) => print.spaced(["validateConstraintKw", "constraint"]),
|
|
26
|
+
alter_action_set_visible: (print) => print.spaced("setVisibleKw"),
|
|
27
|
+
alter_action_set_invisible: (print) => print.spaced("setInvisibleKw"),
|
|
28
|
+
alter_action_set_tablespace: (print) => print.spaced(["setTablespaceKw", "tablespace", "nowaitKw"]),
|
|
29
|
+
alter_action_set_schema: (print) => print.spaced(["setSchemaKw", "schema"]),
|
|
30
|
+
alter_action_enable: (print) => print.spaced(["enableKw", "modeKw", "item"]),
|
|
31
|
+
alter_action_disable: (print) => print.spaced(["disableKw", "item"]),
|
|
32
|
+
alter_action_force: (print) => print.spaced(["forceKw", "item"]),
|
|
33
|
+
alter_action_no_force: (print) => print.spaced(["noForceKw", "item"]),
|
|
34
|
+
alter_action_cluster_on: (print) => print.spaced(["clusterOnKw", "index"]),
|
|
35
|
+
alter_action_set_without_cluster: (print) => print.spaced("setWithoutClusterKw"),
|
|
36
|
+
alter_action_set_without_oids: (print) => print.spaced("setWithoutOidsKw"),
|
|
37
|
+
alter_action_set_access_method: (print) => print.spaced(["setAccessMethodKw", "method"]),
|
|
38
|
+
alter_action_set_logged: (print) => print.spaced("setLoggedKw"),
|
|
39
|
+
alter_action_set_unlogged: (print) => print.spaced("setUnloggedKw"),
|
|
40
|
+
alter_action_inherit: (print) => print.spaced(["inheritKw", "table"]),
|
|
41
|
+
alter_action_no_inherit: (print) => print.spaced(["noInheritKw", "table"]),
|
|
42
|
+
alter_action_of_type: (print) => print.spaced(["ofKw", "typeName"]),
|
|
43
|
+
alter_action_not_of_type: (print) => print.spaced("notOfKw"),
|
|
44
|
+
alter_action_owner_to: (print) => print.spaced(["ownerToKw", "owner"]),
|
|
45
|
+
alter_action_replica_identity: (print) => print.spaced(["replicaIdentityKw", "identity"]),
|
|
46
|
+
replica_identity_using_index: (print) => print.spaced(["usingIndexKw", "index"]),
|
|
47
|
+
alter_action_set_postgresql_options: (print) => print.spaced(["setKw", "options"]),
|
|
48
|
+
alter_action_reset_postgresql_options: (print) => print.spaced(["resetKw", "options"]),
|
|
49
|
+
alter_action_depends_on_extension: (print) => print.spaced(["dependsOnExtensionKw", "extension"]),
|
|
50
|
+
alter_action_no_depends_on_extension: (print) => print.spaced(["noDependsOnExtensionKw", "extension"]),
|
|
51
|
+
alter_action_attach_partition: (print) => print.spaced(["attachPartitionKw", "index"]),
|
|
52
|
+
alter_action_add_enum_value: (print) => print.spaced(["addValueKw", "ifNotExistsKw", "value", "position"]),
|
|
53
|
+
alter_action_add_enum_value_position: (print) => print.spaced(["positionKw", "value"]),
|
|
54
|
+
alter_action_rename_enum_value: (print) => print.spaced(["renameValueKw", "oldValue", "toKw", "newValue"]),
|
|
55
|
+
alter_action_add_attribute: (print) => print.spaced([
|
|
56
|
+
"addAttributeKw",
|
|
57
|
+
"name",
|
|
58
|
+
"dataType",
|
|
59
|
+
"constraint",
|
|
60
|
+
"behaviorKw",
|
|
61
|
+
]),
|
|
62
|
+
alter_action_drop_attribute: (print) => print.spaced(["dropAttributeKw", "ifExistsKw", "name", "behaviorKw"]),
|
|
63
|
+
alter_action_alter_attribute: (print) => print.spaced([
|
|
64
|
+
"alterAttributeKw",
|
|
65
|
+
"name",
|
|
66
|
+
"setDataTypeKw",
|
|
67
|
+
"dataType",
|
|
68
|
+
"constraint",
|
|
69
|
+
"behaviorKw",
|
|
70
|
+
]),
|
|
71
|
+
alter_action_rename_attribute: (print) => print.spaced([
|
|
72
|
+
"renameAttributeKw",
|
|
73
|
+
"oldName",
|
|
74
|
+
"toKw",
|
|
75
|
+
"newName",
|
|
76
|
+
"behaviorKw",
|
|
77
|
+
]),
|
|
139
78
|
// ALTER COLUMN
|
|
140
|
-
alter_action_alter_column:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
alter_action_alter_identity: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.line, print("actions"))); },
|
|
176
|
-
alter_action_set_generated: function (print) {
|
|
177
|
-
return print.spaced(["setGeneratedKw", "whenKw"]);
|
|
178
|
-
},
|
|
179
|
-
alter_action_restart: function (print) {
|
|
180
|
-
return print.spaced(["restartKw", "withKw", "value"]);
|
|
181
|
-
},
|
|
182
|
-
alter_action_set_sequence_option: function (print) {
|
|
183
|
-
return print.spaced(["setKw", "option"]);
|
|
184
|
-
},
|
|
185
|
-
alter_action_with_role_options: function (print, node) {
|
|
186
|
-
return node.withKw
|
|
187
|
-
? (0, print_utils_1.group)([print("withKw"), (0, print_utils_1.indent)([print_utils_1.line, (0, print_utils_1.join)(print_utils_1.line, print("options"))])])
|
|
188
|
-
: // This works in tandem with the logic inside alter_role_stmt
|
|
189
|
-
(0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.line, print("options")));
|
|
190
|
-
},
|
|
191
|
-
alter_action_set_postgresql_option: function (print) {
|
|
192
|
-
return print.spaced(["setKw", "name", "operator", "value"]);
|
|
193
|
-
},
|
|
194
|
-
alter_action_set_postgresql_option_from_current: function (print) {
|
|
195
|
-
return print.spaced(["setKw", "name", "fromCurrentKw"]);
|
|
196
|
-
},
|
|
197
|
-
alter_action_reset_postgresql_option: function (print) {
|
|
198
|
-
return print.spaced(["resetKw", "name"]);
|
|
199
|
-
},
|
|
200
|
-
alter_action_add_user: function (print) { return (0, print_utils_1.group)(print.spaced(["addUserKw", "users"])); },
|
|
201
|
-
alter_action_drop_user: function (print) {
|
|
202
|
-
return (0, print_utils_1.group)(print.spaced(["dropUserKw", "users"]));
|
|
203
|
-
},
|
|
79
|
+
alter_action_alter_column: (print) => group([
|
|
80
|
+
print.spaced(["alterKw", "ifExistsKw", "column"]),
|
|
81
|
+
print.dynamicLine(),
|
|
82
|
+
print("action"),
|
|
83
|
+
]),
|
|
84
|
+
alter_action_set_default: (print) => print.spaced(["setDefaultKw", "expr"]),
|
|
85
|
+
alter_action_drop_default: (print) => print.spaced("dropDefaultKw"),
|
|
86
|
+
alter_action_set_not_null: (print) => print.spaced("setNotNullKw"),
|
|
87
|
+
alter_action_drop_not_null: (print) => print.spaced("dropNotNullKw"),
|
|
88
|
+
alter_action_set_data_type: (print) => print.spaced(["setDataTypeKw", "dataType", "clauses"]),
|
|
89
|
+
alter_action_set_statistics: (print) => print.spaced(["setStatisticsKw", "value"]),
|
|
90
|
+
alter_action_set_compression: (print) => print.spaced(["setCompressionKw", "method"]),
|
|
91
|
+
alter_action_set_storage: (print) => print.spaced(["setStorageKw", "typeKw"]),
|
|
92
|
+
alter_action_drop_expression: (print) => print.spaced(["dropExpressionKw", "ifExistsKw"]),
|
|
93
|
+
alter_action_drop_identity: (print) => print.spaced(["dropIdentityKw", "ifExistsKw"]),
|
|
94
|
+
alter_action_add_identity: (print) => print.spaced([
|
|
95
|
+
"addGeneratedKw",
|
|
96
|
+
"whenKw",
|
|
97
|
+
"asIdentityKw",
|
|
98
|
+
"sequenceOptions",
|
|
99
|
+
]),
|
|
100
|
+
alter_action_alter_identity: (print) => group(join(line, print("actions"))),
|
|
101
|
+
alter_action_set_generated: (print) => print.spaced(["setGeneratedKw", "whenKw"]),
|
|
102
|
+
alter_action_restart: (print) => print.spaced(["restartKw", "withKw", "value"]),
|
|
103
|
+
alter_action_set_sequence_option: (print) => print.spaced(["setKw", "option"]),
|
|
104
|
+
alter_action_with_role_options: (print, node) => node.withKw
|
|
105
|
+
? group([print("withKw"), indent([line, join(line, print("options"))])])
|
|
106
|
+
: // This works in tandem with the logic inside alter_role_stmt
|
|
107
|
+
group(join(line, print("options"))),
|
|
108
|
+
alter_action_set_postgresql_option: (print) => print.spaced(["setKw", "name", "operator", "value"]),
|
|
109
|
+
alter_action_set_postgresql_option_from_current: (print) => print.spaced(["setKw", "name", "fromCurrentKw"]),
|
|
110
|
+
alter_action_reset_postgresql_option: (print) => print.spaced(["resetKw", "name"]),
|
|
111
|
+
alter_action_add_user: (print) => group(print.spaced(["addUserKw", "users"])),
|
|
112
|
+
alter_action_drop_user: (print) => group(print.spaced(["dropUserKw", "users"])),
|
|
204
113
|
// ENABLE/DISABLE ..
|
|
205
|
-
toggle_trigger:
|
|
206
|
-
toggle_rule:
|
|
207
|
-
toggle_row_level_security:
|
|
114
|
+
toggle_trigger: (print) => print.spaced(["triggerKw", "name"]),
|
|
115
|
+
toggle_rule: (print) => print.spaced(["ruleKw", "name"]),
|
|
116
|
+
toggle_row_level_security: (print) => print.spaced("rowLevelSecurityKw"),
|
|
208
117
|
// SET DATA TYPE ...
|
|
209
|
-
set_data_type_collate_clause:
|
|
210
|
-
|
|
211
|
-
},
|
|
212
|
-
set_data_type_using_clause: function (print) { return print.spaced(["usingKw", "expr"]); },
|
|
118
|
+
set_data_type_collate_clause: (print) => print.spaced(["collateKw", "collation"]),
|
|
119
|
+
set_data_type_using_clause: (print) => print.spaced(["usingKw", "expr"]),
|
|
213
120
|
};
|
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"ownedBy",
|
|
20
|
-
]),
|
|
21
|
-
print.dynamicLine(),
|
|
22
|
-
print("action"),
|
|
23
|
-
]);
|
|
24
|
-
},
|
|
25
|
-
owned_by_clause: function (print) {
|
|
26
|
-
return (0, print_utils_1.group)([print.spaced("ownedByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("owners")])]);
|
|
27
|
-
},
|
|
1
|
+
import { group, indent, line } from "../print_utils";
|
|
2
|
+
export const alterTableMap = {
|
|
3
|
+
alter_table_stmt: (print) => group([
|
|
4
|
+
print.spaced(["alterTableKw", "ifExistsKw", "table"]),
|
|
5
|
+
print.dynamicLine(),
|
|
6
|
+
print("actions"),
|
|
7
|
+
]),
|
|
8
|
+
alter_table_all_in_tablespace_stmt: (print) => group([
|
|
9
|
+
print.spaced([
|
|
10
|
+
"alterTableKw",
|
|
11
|
+
"allInTablespaceKw",
|
|
12
|
+
"tablespace",
|
|
13
|
+
"ownedBy",
|
|
14
|
+
]),
|
|
15
|
+
print.dynamicLine(),
|
|
16
|
+
print("action"),
|
|
17
|
+
]),
|
|
18
|
+
owned_by_clause: (print) => group([print.spaced("ownedByKw"), indent([line, print("owners")])]),
|
|
28
19
|
};
|
package/dist/syntax/analyze.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var print_utils_1 = require("../print_utils");
|
|
5
|
-
exports.analyzeMap = {
|
|
6
|
-
analyze_stmt: function (print) {
|
|
7
|
-
return (0, print_utils_1.group)(print.spaced(["analyzeKw", "tableKw", "tables"]));
|
|
8
|
-
},
|
|
1
|
+
import { group } from "../print_utils";
|
|
2
|
+
export const analyzeMap = {
|
|
3
|
+
analyze_stmt: (print) => group(print.spaced(["analyzeKw", "tableKw", "tables"])),
|
|
9
4
|
};
|
package/dist/syntax/base.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.baseMap = void 0;
|
|
4
|
-
var node_utils_1 = require("../node_utils");
|
|
5
|
-
exports.baseMap = {
|
|
1
|
+
import { isDataType } from "../node_utils";
|
|
2
|
+
export const baseMap = {
|
|
6
3
|
/** cst-ignore: name */
|
|
7
|
-
keyword:
|
|
8
|
-
|
|
4
|
+
keyword: (print, node, path, options) => {
|
|
5
|
+
const keywordCase = isDataType(path.ancestors)
|
|
9
6
|
? options.sqlTypeCase
|
|
10
7
|
: options.sqlKeywordCase;
|
|
11
8
|
switch (keywordCase) {
|
|
@@ -17,6 +14,6 @@ exports.baseMap = {
|
|
|
17
14
|
return path.node.text.toLowerCase();
|
|
18
15
|
}
|
|
19
16
|
},
|
|
20
|
-
all_columns:
|
|
21
|
-
empty:
|
|
17
|
+
all_columns: () => "*",
|
|
18
|
+
empty: () => [],
|
|
22
19
|
};
|