@dbml/core 3.6.1 → 3.7.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/lib/connectors/ utils.js +11 -0
- package/lib/connectors/connector.js +40 -0
- package/lib/connectors/dbml.js +170 -0
- package/lib/connectors/mssqlConnector.js +391 -0
- package/lib/connectors/mysqlConnector.js +490 -0
- package/lib/connectors/postgresConnector.js +400 -0
- package/lib/export/DbmlExporter.js +5 -2
- package/lib/import/index.js +32 -1
- package/lib/model_structure/endpoint.js +2 -2
- package/lib/model_structure/enum.js +2 -2
- package/lib/model_structure/enumValue.js +2 -2
- package/lib/model_structure/field.js +2 -2
- package/lib/model_structure/indexColumn.js +2 -2
- package/lib/model_structure/indexes.js +2 -2
- package/lib/model_structure/ref.js +2 -2
- package/lib/model_structure/schema.js +2 -2
- package/lib/model_structure/stickyNote.js +2 -2
- package/lib/model_structure/table.js +2 -2
- package/lib/model_structure/tableGroup.js +2 -2
- package/lib/parse/ANTLR/ASTGeneration/AST.js +1 -0
- package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +1 -1
- package/lib/parse/DatabaseGenerator.js +118 -0
- package/package.json +7 -3
- package/types/import/index.d.ts +2 -0
|
@@ -183,9 +183,9 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
183
183
|
}, {
|
|
184
184
|
key: "normalize",
|
|
185
185
|
value: function normalize(model) {
|
|
186
|
-
model.tables
|
|
186
|
+
model.tables[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
187
187
|
id: this.id
|
|
188
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
188
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
189
189
|
this.fields.forEach(function (field) {
|
|
190
190
|
return field.normalize(model);
|
|
191
191
|
});
|
|
@@ -123,9 +123,9 @@ var TableGroup = /*#__PURE__*/function (_Element) {
|
|
|
123
123
|
}, {
|
|
124
124
|
key: "normalize",
|
|
125
125
|
value: function normalize(model) {
|
|
126
|
-
model.tableGroups
|
|
126
|
+
model.tableGroups[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
127
127
|
id: this.id
|
|
128
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
128
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
129
129
|
}
|
|
130
130
|
}]);
|
|
131
131
|
return TableGroup;
|
|
@@ -10,6 +10,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
10
10
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
11
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
12
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
/* eslint-disable camelcase */
|
|
13
14
|
/* eslint-disable max-classes-per-file */
|
|
14
15
|
var Index = /*#__PURE__*/function () {
|
|
15
16
|
/**
|
|
@@ -711,7 +711,7 @@ var SnowflakeASTGen = /*#__PURE__*/function (_SnowflakeParserVisit) {
|
|
|
711
711
|
key: "visitLiteral",
|
|
712
712
|
value: function visitLiteral(ctx) {
|
|
713
713
|
if (ctx.STRING()) return {
|
|
714
|
-
value: (
|
|
714
|
+
value: sanitizeComment(ctx),
|
|
715
715
|
type: 'string'
|
|
716
716
|
};
|
|
717
717
|
if (ctx.DECIMAL() || ctx.REAL || ctx.FLOAT) return {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateDatabase = void 0;
|
|
7
|
+
var _database = _interopRequireDefault(require("../model_structure/database"));
|
|
8
|
+
var _AST = require("./ANTLR/ASTGeneration/AST");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
var parseJSONToDatabase = function parseJSONToDatabase(rawDatabase) {
|
|
11
|
+
return new _database["default"](rawDatabase);
|
|
12
|
+
};
|
|
13
|
+
var createRefs = function createRefs(rawRefs) {
|
|
14
|
+
return rawRefs.map(function (rawRef) {
|
|
15
|
+
var name = rawRef.name,
|
|
16
|
+
endpoints = rawRef.endpoints,
|
|
17
|
+
onDelete = rawRef.onDelete,
|
|
18
|
+
onUpdate = rawRef.onUpdate;
|
|
19
|
+
var eps = endpoints.map(function (ep) {
|
|
20
|
+
return new _AST.Endpoint(ep);
|
|
21
|
+
});
|
|
22
|
+
return new _AST.Ref({
|
|
23
|
+
name: name,
|
|
24
|
+
endpoints: eps,
|
|
25
|
+
onDelete: onDelete,
|
|
26
|
+
onUpdate: onUpdate
|
|
27
|
+
}).toJSON();
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var createEnums = function createEnums(rawEnums) {
|
|
31
|
+
return rawEnums.map(function (rawEnum) {
|
|
32
|
+
var name = rawEnum.name,
|
|
33
|
+
schemaName = rawEnum.schemaName,
|
|
34
|
+
values = rawEnum.values;
|
|
35
|
+
return new _AST.Enum({
|
|
36
|
+
name: name,
|
|
37
|
+
schemaName: schemaName,
|
|
38
|
+
values: values
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
var createFields = function createFields(rawFields, fieldsConstraints) {
|
|
43
|
+
return rawFields.map(function (field) {
|
|
44
|
+
var constraints = fieldsConstraints[field.name] || {};
|
|
45
|
+
var f = new _AST.Field({
|
|
46
|
+
name: field.name,
|
|
47
|
+
type: field.type,
|
|
48
|
+
dbdefault: field.dbdefault,
|
|
49
|
+
not_null: field.not_null,
|
|
50
|
+
increment: field.increment,
|
|
51
|
+
pk: constraints.pk,
|
|
52
|
+
unique: constraints.unique,
|
|
53
|
+
note: field.note
|
|
54
|
+
});
|
|
55
|
+
return f;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
var createIndexes = function createIndexes(rawIndexes) {
|
|
59
|
+
return rawIndexes.map(function (rawIndex) {
|
|
60
|
+
var name = rawIndex.name,
|
|
61
|
+
unique = rawIndex.unique,
|
|
62
|
+
primary = rawIndex.primary,
|
|
63
|
+
type = rawIndex.type,
|
|
64
|
+
columns = rawIndex.columns;
|
|
65
|
+
var index = new _AST.Index({
|
|
66
|
+
name: name,
|
|
67
|
+
unique: unique,
|
|
68
|
+
pk: primary,
|
|
69
|
+
type: type,
|
|
70
|
+
columns: columns
|
|
71
|
+
});
|
|
72
|
+
return index;
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var createTables = function createTables(rawTables, rawFields, rawIndexes, tableConstraints) {
|
|
76
|
+
return rawTables.map(function (rawTable) {
|
|
77
|
+
var name = rawTable.name,
|
|
78
|
+
schemaName = rawTable.schemaName,
|
|
79
|
+
note = rawTable.note;
|
|
80
|
+
var key = schemaName ? "".concat(schemaName, ".").concat(name) : "".concat(name);
|
|
81
|
+
var constraints = tableConstraints[key] || {};
|
|
82
|
+
var fields = createFields(rawFields[key], constraints);
|
|
83
|
+
var indexes = createIndexes(rawIndexes[key] || []);
|
|
84
|
+
return new _AST.Table({
|
|
85
|
+
name: name,
|
|
86
|
+
schemaName: schemaName,
|
|
87
|
+
fields: fields,
|
|
88
|
+
indexes: indexes,
|
|
89
|
+
note: note
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
var generateDatabase = function generateDatabase(schemaJson) {
|
|
94
|
+
var rawTables = schemaJson.tables,
|
|
95
|
+
rawFields = schemaJson.fields,
|
|
96
|
+
rawIndexes = schemaJson.indexes,
|
|
97
|
+
rawRefs = schemaJson.refs,
|
|
98
|
+
rawEnums = schemaJson.enums,
|
|
99
|
+
tableConstraints = schemaJson.tableConstraints;
|
|
100
|
+
try {
|
|
101
|
+
var tables = createTables(rawTables, rawFields, rawIndexes, tableConstraints);
|
|
102
|
+
var enums = createEnums(rawEnums);
|
|
103
|
+
var refs = createRefs(rawRefs);
|
|
104
|
+
var rawDatabase = {
|
|
105
|
+
schemas: [],
|
|
106
|
+
tables: tables,
|
|
107
|
+
refs: refs,
|
|
108
|
+
enums: enums,
|
|
109
|
+
tableGroups: [],
|
|
110
|
+
aliases: [],
|
|
111
|
+
project: {}
|
|
112
|
+
};
|
|
113
|
+
return parseJSONToDatabase(rawDatabase);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
throw new Error(err);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.generateDatabase = generateDatabase;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Holistics <dev@holistics.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,10 +32,14 @@
|
|
|
32
32
|
"prepublish": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@dbml/parse": "^3.
|
|
35
|
+
"@dbml/parse": "^3.7.0",
|
|
36
|
+
"@tediousjs/connection-string": "^0.5.0",
|
|
36
37
|
"antlr4": "^4.13.1",
|
|
37
38
|
"lodash": "^4.17.15",
|
|
39
|
+
"mssql": "^11.0.1",
|
|
40
|
+
"mysql2": "^3.11.0",
|
|
38
41
|
"parsimmon": "^1.13.0",
|
|
42
|
+
"pg": "^8.12.0",
|
|
39
43
|
"pluralize": "^8.0.0"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
@@ -59,5 +63,5 @@
|
|
|
59
63
|
"\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
|
|
60
64
|
}
|
|
61
65
|
},
|
|
62
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "3222baa4bf45b9ff74711a63d376505cf4bd9ac0"
|
|
63
67
|
}
|
package/types/import/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy'): string;
|
|
2
|
+
declare async function generateDbml(connection: any, format: 'mysql' | 'postgres' | 'mssql'): string;
|
|
2
3
|
declare const _default: {
|
|
3
4
|
import: typeof _import;
|
|
5
|
+
generateDbml: typeof generateDbml;
|
|
4
6
|
};
|
|
5
7
|
export default _default;
|