@carbonorm/carbonnode 1.2.4 → 1.2.5
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/package.json
CHANGED
|
@@ -140,17 +140,23 @@ var parseSQLToTypeScript = function (sql) {
|
|
|
140
140
|
var tableName = tableMatch[1];
|
|
141
141
|
var columnDefinitions = tableMatch[2];
|
|
142
142
|
var columns = {};
|
|
143
|
-
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
143
|
+
// Improved regular expression to match column definitions
|
|
144
|
+
var columnRegex = /\s*`([^`]*)`\s+(\w+)(?:\(([^)]+)\))?\s*(NOT NULL)?\s*(AUTO_INCREMENT)?\s*(DEFAULT\s+'.*?'|DEFAULT\s+\S+)?/gm;
|
|
145
|
+
var columnMatch;
|
|
146
|
+
var columnDefinitionsLines = columnDefinitions.split('\n');
|
|
147
|
+
columnDefinitionsLines.forEach(function (line) {
|
|
148
|
+
if (!line.match(/(PRIMARY KEY|UNIQUE KEY|CONSTRAINT)/)) {
|
|
149
|
+
while ((columnMatch = columnRegex.exec(line))) {
|
|
150
|
+
columns[columnMatch[1]] = {
|
|
151
|
+
type: columnMatch[2],
|
|
152
|
+
length: columnMatch[3] || '',
|
|
153
|
+
notNull: !!columnMatch[4],
|
|
154
|
+
autoIncrement: !!columnMatch[5],
|
|
155
|
+
defaultValue: columnMatch[6] ? columnMatch[6].replace(/^DEFAULT\s+/i, '') : ''
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
154
160
|
// Extract primary keys
|
|
155
161
|
var primaryKeyMatch = columnDefinitions.match(/PRIMARY KEY \(([^)]+)\)/i);
|
|
156
162
|
var primaryKeys = primaryKeyMatch
|
|
@@ -211,19 +211,30 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
211
211
|
const tableName = tableMatch[1];
|
|
212
212
|
const columnDefinitions = tableMatch[2];
|
|
213
213
|
|
|
214
|
-
let columns
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
214
|
+
let columns = {};
|
|
215
|
+
|
|
216
|
+
// Improved regular expression to match column definitions
|
|
217
|
+
const columnRegex = /\s*`([^`]*)`\s+(\w+)(?:\(([^)]+)\))?\s*(NOT NULL)?\s*(AUTO_INCREMENT)?\s*(DEFAULT\s+'.*?'|DEFAULT\s+\S+)?/gm;
|
|
218
|
+
|
|
219
|
+
let columnMatch;
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
const columnDefinitionsLines = columnDefinitions.split('\n');
|
|
224
|
+
|
|
225
|
+
columnDefinitionsLines.forEach(line => {
|
|
226
|
+
if (!line.match(/(PRIMARY KEY|UNIQUE KEY|CONSTRAINT)/)) {
|
|
227
|
+
while ((columnMatch = columnRegex.exec(line))) {
|
|
228
|
+
columns[columnMatch[1]] = {
|
|
229
|
+
type: columnMatch[2],
|
|
230
|
+
length: columnMatch[3] || '',
|
|
231
|
+
notNull: !!columnMatch[4],
|
|
232
|
+
autoIncrement: !!columnMatch[5],
|
|
233
|
+
defaultValue: columnMatch[6] ? columnMatch[6].replace(/^DEFAULT\s+/i, '') : ''
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
227
238
|
|
|
228
239
|
// Extract primary keys
|
|
229
240
|
const primaryKeyMatch = columnDefinitions.match(/PRIMARY KEY \(([^)]+)\)/i);
|
|
@@ -235,6 +246,7 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
235
246
|
const foreignKeyRegex: RegExp = /CONSTRAINT `([^`]+)` FOREIGN KEY \(`([^`]+)`\) REFERENCES `([^`]+)` \(`([^`]+)`\)( ON DELETE (\w+))?( ON UPDATE (\w+))?/g;
|
|
236
247
|
let foreignKeyMatch: RegExpExecArray | null;
|
|
237
248
|
|
|
249
|
+
|
|
238
250
|
while ((foreignKeyMatch = foreignKeyRegex.exec(columnDefinitions))) {
|
|
239
251
|
const constraintName = foreignKeyMatch[1];
|
|
240
252
|
const localColumn = foreignKeyMatch[2];
|