New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dbml/core

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dbml/core - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

10

lib/export/DbmlExporter.js

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

"Enum ".concat("\"".concat(_enum.name, "\""), " {\n", _enum.values.map(function (value) {
return " \"".concat(value.name, "\"");
return " \"".concat(value.name, "\"").concat(value.note ? " [note: '".concat(value.note, "']") : '');
}).join('\n'), "\n}\n")

@@ -204,2 +204,6 @@ /* eslint-enable indent */

if (field.note) {
constraints.push("note: '".concat(field.note, "'"));
}
if (constraints.length > 0) {

@@ -233,2 +237,6 @@ line += " [".concat(constraints.join(', '), "]");

if (index.pk) {
indexSettings.push('pk');
}
if (index.type) {

@@ -235,0 +243,0 @@ indexSettings.push("type: ".concat(index.type.toLowerCase()));

@@ -43,3 +43,7 @@ "use strict";

if (!_lodash["default"].isEmpty(table.indexes)) {
indexes.push.apply(indexes, _toConsumableArray(table.indexes));
// primary composite key is not included here
var tableIndexes = table.indexes.filter(function (index) {
return !index.pk;
});
indexes.push.apply(indexes, _toConsumableArray(tableIndexes));
}

@@ -50,2 +54,19 @@ });

}, {
key: "getCommentsFromSchema",
value: function getCommentsFromSchema(schema) {
var comments = [];
schema.tables.forEach(function (table) {
table.fields.forEach(function (field) {
if (field.note) {
comments.push({
type: 'column',
table: table,
field: field
});
}
});
});
return comments;
}
}, {
key: "hasWhiteSpace",

@@ -52,0 +73,0 @@ value: function hasWhiteSpace(s) {

@@ -16,2 +16,10 @@ "use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -56,5 +64,7 @@

var fieldContents = MySQLExporter.getFieldLines(table);
var primaryCompositeKey = MySQLExporter.getPrimaryCompositeKey(table);
return {
name: name,
fieldContents: fieldContents
fieldContents: fieldContents,
primaryCompositeKey: primaryCompositeKey
};

@@ -69,4 +79,6 @@ });

var tableStrs = tableContentArr.map(function (table) {
var content = [].concat(_toConsumableArray(table.fieldContents), _toConsumableArray(table.primaryCompositeKey));
/* eslint-disable indent */
var tableStr = "CREATE TABLE `".concat(table.name, "` (\n").concat(table.fieldContents.map(function (line) {
var tableStr = "CREATE TABLE `".concat(table.name, "` (\n").concat(content.map(function (line) {
return " ".concat(line);

@@ -213,2 +225,6 @@ }).join(',\n') // format with tab

if (field.note) {
line += " COMMENT '".concat(field.note, "'");
}
return line;

@@ -218,2 +234,27 @@ });

}
}, {
key: "getPrimaryCompositeKey",
value: function getPrimaryCompositeKey(table) {
var primaryCompositeKey = table.indexes ? table.indexes.filter(function (index) {
return index.pk;
}) : [];
var lines = primaryCompositeKey.map(function (key) {
var line = 'PRIMARY KEY';
var columnArr = [];
key.columns.forEach(function (column) {
var columnStr = '';
if (column.type === 'expression') {
columnStr = "(".concat(column.value, ")");
} else {
columnStr = "`".concat(column.value, "`");
}
columnArr.push(columnStr);
});
line += " (".concat(columnArr.join(', '), ")");
return line;
});
return lines;
}
}]);

@@ -220,0 +261,0 @@

@@ -16,2 +16,10 @@ "use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -47,2 +55,3 @@

_this.indexes = _Exporter2["default"].getIndexesFromSchema(schema);
_this.comments = _Exporter2["default"].getCommentsFromSchema(schema);
return _this;

@@ -71,5 +80,7 @@ }

var fieldContents = PostgresExporter.getFieldLines(table);
var primaryCompositeKey = PostgresExporter.getPrimaryCompositeKey(table);
return {
name: name,
fieldContents: fieldContents
fieldContents: fieldContents,
primaryCompositeKey: primaryCompositeKey
};

@@ -84,4 +95,6 @@ });

var tableStrs = tableContentArr.map(function (table) {
var content = [].concat(_toConsumableArray(table.fieldContents), _toConsumableArray(table.primaryCompositeKey));
/* eslint-disable indent */
var tableStr = "CREATE TABLE \"".concat(table.name, "\" (\n").concat(table.fieldContents.map(function (line) {
var tableStr = "CREATE TABLE \"".concat(table.name, "\" (\n").concat(content.map(function (line) {
return " ".concat(line);

@@ -167,2 +180,17 @@ }).join(',\n'), "\n);\n");

}, {
key: "exportComments",
value: function exportComments() {
var commentArr = this.comments.map(function (comment) {
var line = 'COMMENT ON';
if (comment.type === 'column') {
line += " COLUMN \"".concat(comment.table.name, "\".\"").concat(comment.field.name, "\" IS '").concat(comment.field.note, "'");
}
line += ';\n';
return line;
});
return commentArr.length ? commentArr.join('\n') : '';
}
}, {
key: "export",

@@ -196,2 +224,8 @@ value: function _export() {

if (!_lodash["default"].isEmpty(this.comments)) {
if (hasBlockAbove) res += '\n';
res += this.exportComments();
hasBlockAbove = true;
}
return res;

@@ -239,2 +273,27 @@ }

}
}, {
key: "getPrimaryCompositeKey",
value: function getPrimaryCompositeKey(table) {
var primaryCompositeKey = table.indexes ? table.indexes.filter(function (index) {
return index.pk;
}) : [];
var lines = primaryCompositeKey.map(function (key) {
var line = 'PRIMARY KEY';
var columnArr = [];
key.columns.forEach(function (column) {
var columnStr = '';
if (column.type === 'expression') {
columnStr = "(".concat(column.value, ")");
} else {
columnStr = "\"".concat(column.value, "\"");
}
columnArr.push(columnStr);
});
line += " (".concat(columnArr.join(', '), ")");
return line;
});
return lines;
}
}]);

@@ -241,0 +300,0 @@

@@ -16,2 +16,10 @@ "use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -56,5 +64,7 @@

var fieldContents = SqlServerExporter.getFieldLines(table);
var primaryCompositeKey = SqlServerExporter.getPrimaryCompositeKey(table);
return {
name: name,
fieldContents: fieldContents
fieldContents: fieldContents,
primaryCompositeKey: primaryCompositeKey
};

@@ -69,4 +79,6 @@ });

var tableStrs = tableContentArr.map(function (table) {
var content = [].concat(_toConsumableArray(table.fieldContents), _toConsumableArray(table.primaryCompositeKey));
/* eslint-disable indent */
var tableStr = "CREATE TABLE [".concat(table.name, "] (\n").concat(table.fieldContents.map(function (line) {
var tableStr = "CREATE TABLE [".concat(table.name, "] (\n").concat(content.map(function (line) {
return " ".concat(line);

@@ -223,2 +235,27 @@ }).join(',\n') // format with tab

}
}, {
key: "getPrimaryCompositeKey",
value: function getPrimaryCompositeKey(table) {
var primaryCompositeKey = table.indexes ? table.indexes.filter(function (index) {
return index.pk;
}) : [];
var lines = primaryCompositeKey.map(function (key) {
var line = 'PRIMARY KEY';
var columnArr = [];
key.columns.forEach(function (column) {
var columnStr = '';
if (column.type === 'expression') {
columnStr = "(".concat(column.value, ")");
} else {
columnStr = "[".concat(column.value, "]");
}
columnArr.push(columnStr);
});
line += " (".concat(columnArr.join(', '), ")");
return line;
});
return lines;
}
}]);

@@ -225,0 +262,0 @@

5

lib/schema/indexes.js

@@ -42,2 +42,3 @@ "use strict";

unique = _ref.unique,
pk = _ref.pk,
token = _ref.token,

@@ -53,2 +54,3 @@ name = _ref.name;

_this.unique = unique;
_this.pk = pk;
return _this;

@@ -64,3 +66,4 @@ }

type: this.type,
unique: this.unique
unique: this.unique,
pk: this.pk
};

@@ -67,0 +70,0 @@ }

{
"name": "@dbml/core",
"version": "1.1.3",
"version": "1.2.0",
"description": "> TODO: description",

@@ -56,3 +56,3 @@ "author": "Holistics <dev@holistics.io>",

},
"gitHead": "b06097208fd36be1a316d94b0494587436548a44"
"gitHead": "d17325aca50647f695cb1ed660b21c242c4a075e"
}

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

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

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

Sorry, the diff of this file is not supported yet

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