@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.
@@ -79,7 +79,7 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
79
79
  tableGroups: [],
80
80
  aliases: [],
81
81
  project: {},
82
- records: {}
82
+ records: []
83
83
  };
84
84
  return _this;
85
85
  }
@@ -1175,7 +1175,6 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
1175
1175
  }, {
1176
1176
  key: "visitInsertStatement",
1177
1177
  value: function visitInsertStatement(ctx) {
1178
- var _this$data$records$fu;
1179
1178
  var names = ctx.tableName().accept(this);
1180
1179
  var tableName = (0, _lodash.last)(names);
1181
1180
  var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
@@ -1184,18 +1183,13 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
1184
1183
  // insert without specified columns
1185
1184
  var columns = ctx.fullColumnNameList() ? ctx.fullColumnNameList().accept(this) : [];
1186
1185
  var values = ctx.insertStatementValue().accept(this);
1187
- if (columns.length === 0 || values.length === 0) {
1188
- return;
1189
- }
1190
- if (!this.data.records[fullTableName]) {
1191
- this.data.records[fullTableName] = {
1192
- schemaName: schemaName,
1193
- tableName: tableName,
1194
- columns: columns,
1195
- values: []
1196
- };
1197
- }
1198
- (_this$data$records$fu = this.data.records[fullTableName].values).push.apply(_this$data$records$fu, _toConsumableArray(values));
1186
+ var record = {
1187
+ schemaName: schemaName,
1188
+ tableName: tableName,
1189
+ columns: columns,
1190
+ values: values
1191
+ };
1192
+ this.data.records.push(record);
1199
1193
  }
1200
1194
 
1201
1195
  // fullColumnNameList
@@ -71,7 +71,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
71
71
  tableGroups: [],
72
72
  aliases: [],
73
73
  project: {},
74
- records: {}
74
+ records: []
75
75
  };
76
76
  return _this;
77
77
  }
@@ -1174,7 +1174,6 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
1174
1174
  }, {
1175
1175
  key: "visitInsertstmt",
1176
1176
  value: function visitInsertstmt(ctx) {
1177
- var _this$data$records$fu;
1178
1177
  var names = ctx.insert_target().accept(this);
1179
1178
  var tableName = (0, _lodash.last)(names);
1180
1179
  var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
@@ -1182,23 +1181,13 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
1182
1181
  var _ctx$insert_rest$acce = ctx.insert_rest().accept(this),
1183
1182
  columns = _ctx$insert_rest$acce.columns,
1184
1183
  values = _ctx$insert_rest$acce.values;
1185
-
1186
- // handle insert into all columns
1187
- if (columns.length === 0 || values.length === 0) {
1188
- // temporarily ignore
1189
- return;
1190
- }
1191
- if (!this.data.records[fullTableName]) {
1192
- this.data.records[fullTableName] = {
1193
- schemaName: schemaName,
1194
- tableName: tableName,
1195
- columns: columns,
1196
- values: []
1197
- };
1198
- }
1199
-
1200
- // TODO: should handle case the number of columns is not equal
1201
- (_this$data$records$fu = this.data.records[fullTableName].values).push.apply(_this$data$records$fu, _toConsumableArray(values));
1184
+ var record = {
1185
+ schemaName: schemaName,
1186
+ tableName: tableName,
1187
+ columns: columns,
1188
+ values: values
1189
+ };
1190
+ this.data.records.push(record);
1202
1191
  }
1203
1192
  }, {
1204
1193
  key: "visitInsert_target",
@@ -14,7 +14,12 @@
14
14
  - https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md
15
15
  ## Setup a new parser
16
16
  1. Create a new folder inside the `packages/dbml-core/src/parse/ANTLR/parsers` folder (e.g. `postgresql`)
17
- 2. Go to https://github.com/antlr/grammars-v4/tree/master/sql and clone the `<lang>Lexer.G4` and `<lang>Parser.G4` to the newly created folder.
17
+ 2. Get the grammar:
18
+
19
+ - Go to https://github.com/antlr/grammars-v4/tree/master/sql and clone the `<lang>Lexer.G4` and `<lang>Parser.G4` to the newly created folder.
20
+
21
+ - **Remember to add the original link to `<lang>Lexer.G4` and `<lang>Parser.G4`**
22
+
18
23
  3. Go to the folder:
19
24
  ```
20
25
  cd packages/dbml-core/src/parse/ANTLR/parsers/postgresql
@@ -1,3 +1,9 @@
1
+ /*
2
+ Original: https://github.com/antlr/grammars-v4/blob/master/sql/tsql/TSqlLexer.g4
3
+ Last updated: 2024-05-01
4
+ */
5
+
6
+
1
7
  /*
2
8
  T-SQL (Transact-SQL, MSSQL) grammar.
3
9
  The MIT License (MIT).
@@ -1,3 +1,9 @@
1
+ /*
2
+ Original: https://github.com/antlr/grammars-v4/blob/master/sql/tsql/TSqlParser.g4
3
+ Last updated: 2024-04-14
4
+ References: https://infocenter.sybase.com/help/topic/com.sybase.dc36272_1251/pdf/commands.pdf
5
+ */
6
+
1
7
  /*
2
8
  T-SQL (Transact-SQL, MSSQL) grammar.
3
9
  The MIT License (MIT).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/core",
3
- "version": "3.11.0-alpha-0",
3
+ "version": "3.12.0-alpha-0",
4
4
  "description": "> TODO: description",
5
5
  "author": "Holistics <dev@holistics.io>",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  "prepublish": "npm run build"
33
33
  },
34
34
  "dependencies": {
35
- "@dbml/parse": "^3.11.0-alpha-0",
35
+ "@dbml/parse": "^3.12.0-alpha-0",
36
36
  "antlr4": "^4.13.1",
37
37
  "lodash": "^4.17.15",
38
38
  "parsimmon": "^1.13.0",
@@ -59,7 +59,7 @@
59
59
  "\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
60
60
  }
61
61
  },
62
- "gitHead": "b090782ba29b03837d87d4d6478bd3f2ca403efc",
62
+ "gitHead": "da2bec56f10f32db65a06856105f08b522556661",
63
63
  "engines": {
64
64
  "node": ">=16"
65
65
  }
@@ -17,16 +17,22 @@ export interface Project {
17
17
  name: string;
18
18
  }
19
19
 
20
- export interface Records {
21
- [tableSchemaName: string]: {
22
- schemaName: string | undefined;
23
- tableName: string;
24
- columns: string[];
25
- values: {
26
- value: any;
27
- type: string;
28
- }[];
29
- }
20
+ interface RawRecord {
21
+ schemaName: string | undefined;
22
+ tableName: string;
23
+ columns: string[];
24
+ values: {
25
+ value: any;
26
+ type: string;
27
+ }[][];
28
+ }
29
+
30
+ export interface Record extends RawRecord {
31
+ id: number;
32
+ }
33
+
34
+ export interface NormalizedRecord {
35
+ [_id: number]: Record;
30
36
  }
31
37
 
32
38
  export interface RawDatabase {
@@ -37,7 +43,7 @@ export interface RawDatabase {
37
43
  refs: Ref[];
38
44
  tableGroups: TableGroup[];
39
45
  project: Project;
40
- records: Records;
46
+ records: RawRecord[];
41
47
  }
42
48
  declare class Database extends Element {
43
49
  dbState: DbState;
@@ -48,9 +54,11 @@ declare class Database extends Element {
48
54
  noteToken: Token;
49
55
  databaseType: string;
50
56
  name: string;
57
+ records: Record[];
51
58
  id: number;
52
59
  constructor({ schemas, tables, enums, refs, tableGroups, project, records }: RawDatabase);
53
60
  generateId(): void;
61
+ processRecords(rawRecords: RawRecord[]): void;
54
62
  processSchemas(rawSchemas: RawSchema[]): void;
55
63
  pushSchema(schema: Schema): void;
56
64
  checkSchema(schema: Schema): void;
@@ -122,6 +130,16 @@ declare class Database extends Element {
122
130
  content: string;
123
131
  headerColor: string;
124
132
  }[];
133
+ records: {
134
+ id: number;
135
+ schemaName: string;
136
+ tableName: string;
137
+ columns: string[];
138
+ values: {
139
+ value: any;
140
+ type: string;
141
+ }[][];
142
+ }[];
125
143
  };
126
144
  shallowExport(): {
127
145
  hasDefaultSchema: boolean;
@@ -224,6 +242,6 @@ export interface NormalizedDatabase {
224
242
  indexes: NormalizedIndex;
225
243
  indexColumns: NormalizedIndexColumn;
226
244
  fields: NormalizedField;
227
- records: Records;
245
+ records: NormalizedRecord;
228
246
  }
229
247
  export default Database;
@@ -18,7 +18,7 @@ declare class Parser {
18
18
  static parsePostgresToJSON(str: string): RawDatabase;
19
19
  static parsePostgresToJSONv2(str: string): RawDatabase;
20
20
  static parseDBMLToJSON(str: string): RawDatabase;
21
- static parseDBMLToJSONv2(str: string, dbmlCompiler: Compiler): RawDatabase;
21
+ static parseDBMLToJSONv2(str: string, dbmlCompiler?: Compiler): RawDatabase;
22
22
  static parseSchemaRbToJSON(str: string): RawDatabase;
23
23
  static parseMSSQLToJSON(str: string): RawDatabase;
24
24
  static parseMSSQLToJSONv2(str: string): RawDatabase;