@dbml/core 3.11.0-alpha-0 → 3.12.0-alpha-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.
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _lodash = _interopRequireWildcard(require("lodash"));
9
9
  var _schema = _interopRequireDefault(require("./schema"));
10
- var _ref2 = _interopRequireDefault(require("./ref"));
10
+ var _ref3 = _interopRequireDefault(require("./ref"));
11
11
  var _enum2 = _interopRequireDefault(require("./enum"));
12
12
  var _tableGroup = _interopRequireDefault(require("./tableGroup"));
13
13
  var _table = _interopRequireDefault(require("./table"));
@@ -55,7 +55,7 @@ var Database = /*#__PURE__*/function (_Element) {
55
55
  _ref$aliases = _ref.aliases,
56
56
  aliases = _ref$aliases === void 0 ? [] : _ref$aliases,
57
57
  _ref$records = _ref.records,
58
- records = _ref$records === void 0 ? {} : _ref$records;
58
+ records = _ref$records === void 0 ? [] : _ref$records;
59
59
  _classCallCheck(this, Database);
60
60
  _this = _super.call(this);
61
61
  _this.dbState = new _dbState["default"]();
@@ -69,8 +69,9 @@ var Database = /*#__PURE__*/function (_Element) {
69
69
  _this.name = project.name;
70
70
  _this.token = project.token;
71
71
  _this.aliases = aliases;
72
- _this.records = records;
72
+ _this.records = [];
73
73
  _this.processNotes(notes);
74
+ _this.processRecords(records);
74
75
  // The process order is important. Do not change !
75
76
  _this.processSchemas(schemas);
76
77
  _this.processSchemaElements(enums, _config.ENUM);
@@ -95,6 +96,24 @@ var Database = /*#__PURE__*/function (_Element) {
95
96
  })));
96
97
  });
97
98
  }
99
+ }, {
100
+ key: "processRecords",
101
+ value: function processRecords(rawRecords) {
102
+ var _this3 = this;
103
+ rawRecords.forEach(function (_ref2) {
104
+ var schemaName = _ref2.schemaName,
105
+ tableName = _ref2.tableName,
106
+ columns = _ref2.columns,
107
+ values = _ref2.values;
108
+ _this3.records.push({
109
+ id: _this3.dbState.generateId('recordId'),
110
+ schemaName: schemaName,
111
+ tableName: tableName,
112
+ columns: columns,
113
+ values: values
114
+ });
115
+ });
116
+ }
98
117
  }, {
99
118
  key: "pushNote",
100
119
  value: function pushNote(note) {
@@ -113,10 +132,10 @@ var Database = /*#__PURE__*/function (_Element) {
113
132
  }, {
114
133
  key: "processSchemas",
115
134
  value: function processSchemas(rawSchemas) {
116
- var _this3 = this;
135
+ var _this4 = this;
117
136
  rawSchemas.forEach(function (schema) {
118
- _this3.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, {
119
- database: _this3
137
+ _this4.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, {
138
+ database: _this4
120
139
  })));
121
140
  });
122
141
  }
@@ -138,16 +157,16 @@ var Database = /*#__PURE__*/function (_Element) {
138
157
  }, {
139
158
  key: "processSchemaElements",
140
159
  value: function processSchemaElements(elements, elementType) {
141
- var _this4 = this;
160
+ var _this5 = this;
142
161
  var schema;
143
162
  elements.forEach(function (element) {
144
163
  if (element.schemaName) {
145
- schema = _this4.findOrCreateSchema(element.schemaName);
164
+ schema = _this5.findOrCreateSchema(element.schemaName);
146
165
  if (element.schemaName === _config.DEFAULT_SCHEMA_NAME) {
147
166
  // this.hasDefaultSchema = true;
148
167
  }
149
168
  } else {
150
- schema = _this4.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
169
+ schema = _this5.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
151
170
  }
152
171
  switch (elementType) {
153
172
  case _config.TABLE:
@@ -166,7 +185,7 @@ var Database = /*#__PURE__*/function (_Element) {
166
185
  })));
167
186
  break;
168
187
  case _config.REF:
169
- schema.pushRef(new _ref2["default"](_objectSpread(_objectSpread({}, element), {}, {
188
+ schema.pushRef(new _ref3["default"](_objectSpread(_objectSpread({}, element), {}, {
170
189
  schema: schema
171
190
  })));
172
191
  break;
@@ -262,6 +281,9 @@ var Database = /*#__PURE__*/function (_Element) {
262
281
  }),
263
282
  notes: this.notes.map(function (n) {
264
283
  return n["export"]();
284
+ }),
285
+ records: this.records.map(function (r) {
286
+ return _objectSpread({}, r);
265
287
  })
266
288
  };
267
289
  }
@@ -295,7 +317,7 @@ var Database = /*#__PURE__*/function (_Element) {
295
317
  indexes: {},
296
318
  indexColumns: {},
297
319
  fields: {},
298
- records: this.records
320
+ records: {}
299
321
  };
300
322
  this.schemas.forEach(function (schema) {
301
323
  return schema.normalize(normalizedModel);
@@ -303,6 +325,9 @@ var Database = /*#__PURE__*/function (_Element) {
303
325
  this.notes.forEach(function (note) {
304
326
  return note.normalize(normalizedModel);
305
327
  });
328
+ this.records.forEach(function (record) {
329
+ return normalizedModel.records[record.id] = _objectSpread({}, record);
330
+ });
306
331
  return normalizedModel;
307
332
  }
308
333
  }]);
@@ -25,6 +25,7 @@ var DbState = /*#__PURE__*/function () {
25
25
  this.indexId = 1;
26
26
  this.fieldId = 1;
27
27
  this.indexColumnId = 1;
28
+ this.recordId = 1;
28
29
  }
29
30
  _createClass(DbState, [{
30
31
  key: "generateId",
@@ -9,7 +9,8 @@ var TABLE_CONSTRAINT_KIND = {
9
9
  INDEX: 'index',
10
10
  FK: 'fk',
11
11
  UNIQUE: 'unique',
12
- PK: 'pk'
12
+ PK: 'pk',
13
+ DEFAULT: 'default'
13
14
  };
14
15
  exports.TABLE_CONSTRAINT_KIND = TABLE_CONSTRAINT_KIND;
15
16
  var COLUMN_CONSTRAINT_KIND = {
@@ -19,7 +20,8 @@ var COLUMN_CONSTRAINT_KIND = {
19
20
  DEFAULT: 'dbdefault',
20
21
  INCREMENT: 'increment',
21
22
  INLINE_REF: 'inline_ref',
22
- NOTE: 'note'
23
+ NOTE: 'note',
24
+ CHECK: 'check'
23
25
  };
24
26
  exports.COLUMN_CONSTRAINT_KIND = COLUMN_CONSTRAINT_KIND;
25
27
  var DATA_TYPE = {