@mlagie/sql-connector 2.1.0 → 2.1.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlagie/sql-connector",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "The sql-connector module allows you to manage connections to a MySQL database, define table schemas, and interact with data in a simple and efficient way.",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -26,7 +26,7 @@ function isSqlTemporalDefault(defaultValue) {
26
26
  if (typeof defaultValue !== "string") return false;
27
27
 
28
28
  const normalizedValue = defaultValue.trim().toUpperCase();
29
- return ["CURRENT_TIMESTAMP", "CURRENT_TIMESTAMP()", "NOW()"].includes(normalizedValue);
29
+ return ["CURRENT_TIMESTAMP", "CURRENT_TIMESTAMP()", "NOW", "NOW()"].includes(normalizedValue);
30
30
  }
31
31
 
32
32
  function formatDefaultSql(defaultValue, fieldType) {
@@ -144,13 +144,17 @@ class Model {
144
144
 
145
145
  const sorted = [];
146
146
  const visited = {};
147
- function visit(table) {
147
+ function visit(table, stack = []) {
148
148
  if (getSafe(visited, table) === true) return;
149
- if (getSafe(visited, table) === 'temp') throw new Error('Cyclic foreign key dependency detected');
149
+ const cycleStartIndex = stack.indexOf(table);
150
+ if (cycleStartIndex !== -1) {
151
+ const cyclePath = [...stack.slice(cycleStartIndex), table];
152
+ throw new Error(`Cyclic foreign key dependency detected: ${cyclePath.join(' -> ')}`);
153
+ }
150
154
  setSafe(visited, table, 'temp');
151
155
  const deps = getSafe(dependencies, table)
152
156
  for (const dep of deps) {
153
- if (getSafe(modelMap, dep)) visit(dep);
157
+ if (getSafe(modelMap, dep)) visit(dep, [...stack, table]);
154
158
  }
155
159
  setSafe(visited, table, true);
156
160
  sorted.push(table);