@cheetah.js/orm 0.1.120 → 0.1.121
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.
|
@@ -220,26 +220,29 @@ class BunDriverBase {
|
|
|
220
220
|
const columnName = row[columnNameField];
|
|
221
221
|
return constraints
|
|
222
222
|
.filter((c) => this.isForeignKeyConstraint(c, columnName))
|
|
223
|
-
.map((c) => this.parseForeignKeyDefinition(c.consDef))
|
|
223
|
+
.map((c) => this.parseForeignKeyDefinition(c.consDef))
|
|
224
|
+
.filter(Boolean);
|
|
224
225
|
}
|
|
225
226
|
isForeignKeyConstraint(constraint, columnName) {
|
|
226
227
|
return (constraint.type === 'FOREIGN KEY' &&
|
|
227
228
|
constraint.consDef.includes(columnName));
|
|
228
229
|
}
|
|
229
230
|
parseForeignKeyDefinition(consDef) {
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
const quote = this.getIdentifierQuote();
|
|
232
|
+
const escapedQuote = this.escapeRegex(quote);
|
|
233
|
+
const pattern = new RegExp(`REFERENCES\\s+(?:${escapedQuote}([^${escapedQuote}]+)${escapedQuote}|([\\w.]+))\\s*\\(([^)]+)\\)`, 'i');
|
|
234
|
+
const match = consDef.match(pattern);
|
|
235
|
+
if (!match)
|
|
236
|
+
return null;
|
|
237
|
+
const tableName = (match[1] || match[2]).trim();
|
|
238
|
+
const columnName = match[3].split(',')[0].trim().replace(new RegExp(escapedQuote, 'g'), '');
|
|
236
239
|
return {
|
|
237
|
-
referencedColumnName:
|
|
238
|
-
|
|
239
|
-
.trim()
|
|
240
|
-
.replace(new RegExp(q, 'g'), ''),
|
|
241
|
-
referencedTableName: filter[1],
|
|
240
|
+
referencedColumnName: columnName,
|
|
241
|
+
referencedTableName: tableName
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
+
escapeRegex(str) {
|
|
245
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
246
|
+
}
|
|
244
247
|
}
|
|
245
248
|
exports.BunDriverBase = BunDriverBase;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheetah.js/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.121",
|
|
4
4
|
"description": "A simple ORM for Cheetah.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"bun",
|
|
56
56
|
"value-object"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "04085d38962dd22e3967a52f00a7a9fa67746c6e"
|
|
59
59
|
}
|