@dbcube/core 5.1.15 → 5.2.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/dist/index.js CHANGED
@@ -345,7 +345,7 @@ var Downloader = class {
345
345
  }
346
346
  this.mainSpinner.text = chalk.blue(`Updating ${binariesToDownload.length} binary(ies)...`);
347
347
  try {
348
- await Promise.all(binariesToDownload.map(async (binary) => {
348
+ const results = await Promise.allSettled(binariesToDownload.map(async (binary) => {
349
349
  const maxRetries = 3;
350
350
  let attempt = 0;
351
351
  while (attempt <= maxRetries) {
@@ -373,6 +373,11 @@ var Downloader = class {
373
373
  }
374
374
  }
375
375
  }));
376
+ const failures = results.filter((r) => r.status === "rejected");
377
+ if (failures.length > 0) {
378
+ const messages = failures.map((f) => f.reason instanceof Error ? f.reason.message : String(f.reason));
379
+ throw new Error(messages.join(" | "));
380
+ }
376
381
  this.mainSpinner.succeed(chalk.green("Binaries updated successfully"));
377
382
  } catch (error) {
378
383
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
@@ -437,8 +442,7 @@ var Downloader = class {
437
442
  }
438
443
  });
439
444
  response.on("end", () => {
440
- file.end();
441
- resolve5();
445
+ file.end(() => resolve5());
442
446
  });
443
447
  response.on("error", (err) => {
444
448
  file.close();
@@ -664,7 +668,6 @@ var Config = class {
664
668
  /**
665
669
  * Obtiene un valor de configuración
666
670
  * @param key - Clave de configuración
667
- * @returns Valor de configuración
668
671
  */
669
672
  get(key) {
670
673
  return this.data[key];
@@ -672,14 +675,12 @@ var Config = class {
672
675
  /**
673
676
  * Obtiene la configuración de una base de datos específica
674
677
  * @param dbName - Nombre de la base de datos
675
- * @returns Configuración de la base de datos o null
676
678
  */
677
679
  getDatabase(dbName) {
678
680
  return this.databases[dbName] || null;
679
681
  }
680
682
  /**
681
683
  * Obtiene todas las bases de datos configuradas
682
- * @returns Todas las configuraciones de bases de datos
683
684
  */
684
685
  getAllDatabases() {
685
686
  return this.databases;
@@ -727,6 +728,39 @@ var DaemonClient = class _DaemonClient {
727
728
  portfilePath() {
728
729
  return path3.join(process.cwd(), ".dbcube", "daemon", `${this.name}.json`);
729
730
  }
731
+ lockfilePath() {
732
+ return path3.join(process.cwd(), ".dbcube", "daemon", `${this.name}.lock`);
733
+ }
734
+ /**
735
+ * Exclusive-create lock so two processes never spawn two daemons for the
736
+ * same database at once. Stale locks (crashed starter) expire after 15s.
737
+ */
738
+ acquireSpawnLock() {
739
+ const lockPath = this.lockfilePath();
740
+ try {
741
+ fs3.mkdirSync(path3.dirname(lockPath), { recursive: true });
742
+ const fd = fs3.openSync(lockPath, "wx");
743
+ fs3.writeSync(fd, String(process.pid));
744
+ fs3.closeSync(fd);
745
+ return true;
746
+ } catch {
747
+ try {
748
+ const age = Date.now() - fs3.statSync(lockPath).mtimeMs;
749
+ if (age > 15e3) {
750
+ fs3.unlinkSync(lockPath);
751
+ return this.acquireSpawnLock();
752
+ }
753
+ } catch {
754
+ }
755
+ return false;
756
+ }
757
+ }
758
+ releaseSpawnLock() {
759
+ try {
760
+ fs3.unlinkSync(this.lockfilePath());
761
+ } catch {
762
+ }
763
+ }
730
764
  /**
731
765
  * Ensures a usable daemon connection. Returns false when the daemon
732
766
  * can't be used (old binary, startup failure) so callers fall back
@@ -743,24 +777,32 @@ var DaemonClient = class _DaemonClient {
743
777
  async connectOrStart() {
744
778
  const port = this.readPortfile();
745
779
  if (port && await this.tryConnect(port)) return true;
780
+ const gotLock = this.acquireSpawnLock();
746
781
  try {
747
- fs3.unlinkSync(this.portfilePath());
748
- } catch {
749
- }
750
- this.spawnDaemon();
751
- const deadline = Date.now() + 1e4;
752
- while (Date.now() < deadline) {
753
- await new Promise((r) => setTimeout(r, 150));
754
- const newPort = this.readPortfile();
755
- if (newPort && await this.tryConnect(newPort)) return true;
782
+ if (gotLock) {
783
+ try {
784
+ fs3.unlinkSync(this.portfilePath());
785
+ } catch {
786
+ }
787
+ this.spawnDaemon();
788
+ }
789
+ const deadline = Date.now() + 1e4;
790
+ while (Date.now() < deadline) {
791
+ await new Promise((r) => setTimeout(r, 150));
792
+ const newPort = this.readPortfile();
793
+ if (newPort && await this.tryConnect(newPort)) return true;
794
+ }
795
+ return false;
796
+ } finally {
797
+ if (gotLock) this.releaseSpawnLock();
756
798
  }
757
- return false;
758
799
  }
759
800
  readPortfile() {
760
801
  try {
761
802
  const raw = fs3.readFileSync(this.portfilePath(), "utf8");
762
803
  const info = JSON.parse(raw);
763
- return typeof info.port === "number" ? info.port : null;
804
+ const port = info?.port;
805
+ return Number.isInteger(port) && port > 0 && port <= 65535 ? port : null;
764
806
  } catch {
765
807
  return null;
766
808
  }
@@ -779,7 +821,7 @@ var DaemonClient = class _DaemonClient {
779
821
  socket.setNoDelay(true);
780
822
  this.attach(socket);
781
823
  try {
782
- const pong = await this.send({ action: "ping" });
824
+ const pong = await this.send({ action: "ping" }, 2e3);
783
825
  resolve5(pong.status === 200);
784
826
  } catch {
785
827
  this.detach();
@@ -836,7 +878,7 @@ var DaemonClient = class _DaemonClient {
836
878
  * Sends a request to the daemon. Responses arrive in FIFO order on the
837
879
  * single socket, so pending requests resolve in send order.
838
880
  */
839
- send(payload) {
881
+ send(payload, timeoutMs) {
840
882
  return new Promise((resolve5, reject) => {
841
883
  if (!this.socket || this.socket.destroyed) {
842
884
  reject(new Error("Daemon not connected"));
@@ -846,7 +888,8 @@ var DaemonClient = class _DaemonClient {
846
888
  const i = this.pending.findIndex((p) => p.timer === timer);
847
889
  if (i !== -1) this.pending.splice(i, 1);
848
890
  reject(new Error("Daemon request timeout"));
849
- }, this.requestTimeout);
891
+ this.detach();
892
+ }, timeoutMs ?? this.requestTimeout);
850
893
  this.pending.push({ resolve: resolve5, reject, timer });
851
894
  this.socket.write(JSON.stringify(payload) + "\n");
852
895
  });
@@ -1003,14 +1046,16 @@ var Engine = class {
1003
1046
  "--host",
1004
1047
  this.config.config.HOST,
1005
1048
  "--port",
1006
- this.config.config.PORT,
1007
- "--user",
1008
- this.config.config.USER,
1009
- "--password",
1010
- this.config.config.PASSWORD,
1049
+ String(this.config.config.PORT),
1011
1050
  "--motor",
1012
1051
  this.config.type
1013
1052
  ];
1053
+ if (this.config.config.USER != null && this.config.config.USER !== "") {
1054
+ args.push("--user", this.config.config.USER);
1055
+ }
1056
+ if (this.config.config.PASSWORD != null && this.config.config.PASSWORD !== "") {
1057
+ args.push("--password", this.config.config.PASSWORD);
1058
+ }
1014
1059
  }
1015
1060
  return args;
1016
1061
  }
@@ -1069,8 +1114,10 @@ var Engine = class {
1069
1114
  }
1070
1115
  };
1071
1116
  child.stdout.on("data", (data) => {
1072
- stdoutBuffer += data.toString();
1073
- console.log(stdoutBuffer);
1117
+ const text = data.toString();
1118
+ stdoutBuffer += text;
1119
+ const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1120
+ if (visible) console.log(visible);
1074
1121
  const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1075
1122
  if (match) {
1076
1123
  try {
@@ -1090,8 +1137,10 @@ var Engine = class {
1090
1137
  }
1091
1138
  });
1092
1139
  child.stderr.on("data", (data) => {
1093
- stderrBuffer += data.toString();
1094
- console.log(stderrBuffer);
1140
+ const text = data.toString();
1141
+ stderrBuffer += text;
1142
+ const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1143
+ if (visible) console.log(visible);
1095
1144
  const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1096
1145
  if (match) {
1097
1146
  try {
@@ -1145,7 +1194,6 @@ var globalTcpConnections = /* @__PURE__ */ new Map();
1145
1194
  var connectionQueues = /* @__PURE__ */ new Map();
1146
1195
  var connectionProcessing = /* @__PURE__ */ new Map();
1147
1196
  var queryCache = /* @__PURE__ */ new Map();
1148
- var cacheSize = 0;
1149
1197
  var MAX_CACHE_SIZE = 500;
1150
1198
  var QueryEngine = class {
1151
1199
  name;
@@ -1159,7 +1207,7 @@ var QueryEngine = class {
1159
1207
  this.name = name;
1160
1208
  this.config = this.setConfig(name);
1161
1209
  this.arguments = this.setArguments();
1162
- this.timeout = timeout;
1210
+ this.timeout = this.config?.daemon?.requestTimeoutMs ?? timeout;
1163
1211
  this.connectionId = `${name}_query_engine_${this.config.type}_${this.config.config.DATABASE}_${this.config.config.HOST || "localhost"}`;
1164
1212
  this.tcpPort = this.generatePort();
1165
1213
  }
@@ -1214,17 +1262,30 @@ var QueryEngine = class {
1214
1262
  "--host",
1215
1263
  this.config.config.HOST,
1216
1264
  "--port",
1217
- this.config.config.PORT,
1218
- "--user",
1219
- this.config.config.USER,
1220
- "--password",
1221
- this.config.config.PASSWORD,
1265
+ String(this.config.config.PORT),
1222
1266
  "--motor",
1223
1267
  this.config.type
1224
1268
  ];
1269
+ if (this.config.config.USER != null && this.config.config.USER !== "") {
1270
+ args.push("--user", this.config.config.USER);
1271
+ }
1272
+ if (this.config.config.PASSWORD != null && this.config.config.PASSWORD !== "") {
1273
+ args.push("--password", this.config.config.PASSWORD);
1274
+ }
1225
1275
  }
1276
+ const pool = this.config.pool ?? {};
1277
+ if (pool.maxConnections != null) args.push("--max-connections", String(pool.maxConnections));
1278
+ if (pool.minConnections != null) args.push("--min-connections", String(pool.minConnections));
1279
+ if (pool.acquireTimeoutMs != null) args.push("--acquire-timeout-ms", String(pool.acquireTimeoutMs));
1280
+ if (pool.idleTimeoutMs != null) args.push("--idle-timeout-ms", String(pool.idleTimeoutMs));
1226
1281
  return args;
1227
1282
  }
1283
+ /** El daemon puede desactivarse por config (daemon.enabled=false) o por env (DBCUBE_DAEMON=0). */
1284
+ daemonEnabled() {
1285
+ const flag = process.env.DBCUBE_DAEMON;
1286
+ if (flag === "0" || flag === "false") return false;
1287
+ return this.config?.daemon?.enabled !== false;
1288
+ }
1228
1289
  setConfig(name) {
1229
1290
  const configInstance = new Config();
1230
1291
  try {
@@ -1260,18 +1321,71 @@ var QueryEngine = class {
1260
1321
  const isExecuteAction = actionIndex !== -1 && args[actionIndex + 1] === "execute";
1261
1322
  const isQueryEngine = binary === "query_engine";
1262
1323
  if (isQueryEngine && isExecuteAction) {
1263
- return this.executeWithTcpServer(args);
1324
+ return this.executeWithTcpServer(this.argsToCommand(args));
1264
1325
  } else {
1265
1326
  return this.createProcess(binary, args);
1266
1327
  }
1267
1328
  }
1268
- async executeWithTcpServer(args) {
1329
+ argsToCommand(args) {
1330
+ const command = {};
1331
+ for (let i = 0; i < args.length; i += 2) {
1332
+ if (args[i].startsWith("--")) {
1333
+ command[args[i].substring(2)] = args[i + 1];
1334
+ }
1335
+ }
1336
+ return command;
1337
+ }
1338
+ /**
1339
+ * Executes a DML plan over the persistent TCP server.
1340
+ * Pass txId to run it inside an active transaction.
1341
+ */
1342
+ async executeDml(dml, txId) {
1343
+ const command = { action: "execute", dml: JSON.stringify(dml) };
1344
+ if (txId) command.tx_id = txId;
1345
+ return this.executeWithTcpServer(command);
1346
+ }
1347
+ /**
1348
+ * Executes raw SQL (or a MongoDB command document) with bound parameters
1349
+ * over the persistent TCP server.
1350
+ */
1351
+ async rawQuery(query, params = [], txId) {
1352
+ const command = { action: "raw", query, params };
1353
+ if (txId) command.tx_id = txId;
1354
+ return this.executeWithTcpServer(command);
1355
+ }
1356
+ /** Starts a server-side transaction and returns its id. */
1357
+ async beginTransaction() {
1358
+ const res = await this.executeWithTcpServer({ action: "begin" });
1359
+ if (res.status !== 200 || !res.data?.tx_id) {
1360
+ throw new Error(String(res.message || "Failed to begin transaction (update the query-engine binary: npx dbcube update)"));
1361
+ }
1362
+ return res.data.tx_id;
1363
+ }
1364
+ async commitTransaction(txId) {
1365
+ const res = await this.executeWithTcpServer({ action: "commit", tx_id: txId });
1366
+ if (res.status !== 200) throw new Error(String(res.message || "Failed to commit transaction"));
1367
+ }
1368
+ async rollbackTransaction(txId) {
1369
+ const res = await this.executeWithTcpServer({ action: "rollback", tx_id: txId });
1370
+ if (res.status !== 200) throw new Error(String(res.message || "Failed to rollback transaction"));
1371
+ }
1372
+ async executeWithTcpServer(command) {
1373
+ if (!this.daemonEnabled()) {
1374
+ if (command.tx_id || ["begin", "commit", "rollback"].includes(command.action)) {
1375
+ throw new Error("Transactions require daemon mode. Remove daemon.enabled=false from dbcube.config.js (or unset DBCUBE_DAEMON=0).");
1376
+ }
1377
+ const args = [];
1378
+ for (const [key, value] of Object.entries(command)) {
1379
+ args.push(`--${key.replace(/_/g, "-")}`, typeof value === "string" ? value : JSON.stringify(value));
1380
+ }
1381
+ return this.createProcess("query_engine", args);
1382
+ }
1269
1383
  const serverInfo = globalTcpServers.get(this.connectionId);
1270
1384
  if (!serverInfo || !serverInfo.process || serverInfo.process.killed) {
1271
1385
  await this.startTcpServer();
1272
1386
  await this.waitForServerReady();
1273
1387
  }
1274
- return this.sendTcpRequestFast(args);
1388
+ return this.sendTcpRequestFast(command);
1275
1389
  }
1276
1390
  async waitForServerReady() {
1277
1391
  const maxRetries = 10;
@@ -1314,10 +1428,11 @@ var QueryEngine = class {
1314
1428
  return queryCache.get(dmlJson);
1315
1429
  }
1316
1430
  const parsed = JSON.parse(dmlJson);
1317
- if (cacheSize < MAX_CACHE_SIZE) {
1318
- queryCache.set(dmlJson, parsed);
1319
- cacheSize++;
1431
+ if (queryCache.size >= MAX_CACHE_SIZE) {
1432
+ const oldest = queryCache.keys().next().value;
1433
+ if (oldest !== void 0) queryCache.delete(oldest);
1320
1434
  }
1435
+ queryCache.set(dmlJson, parsed);
1321
1436
  return parsed;
1322
1437
  }
1323
1438
  async startTcpServer() {
@@ -1364,14 +1479,14 @@ var QueryEngine = class {
1364
1479
  });
1365
1480
  });
1366
1481
  }
1367
- async sendTcpRequestFast(args) {
1482
+ async sendTcpRequestFast(command) {
1368
1483
  return new Promise((resolve5, reject) => {
1369
1484
  let queue = connectionQueues.get(this.connectionId);
1370
1485
  if (!queue) {
1371
1486
  queue = [];
1372
1487
  connectionQueues.set(this.connectionId, queue);
1373
1488
  }
1374
- queue.push({ args, resolve: resolve5, reject });
1489
+ queue.push({ command, resolve: resolve5, reject });
1375
1490
  this.processQueue();
1376
1491
  });
1377
1492
  }
@@ -1398,9 +1513,16 @@ var QueryEngine = class {
1398
1513
  connection = await this.createNewConnection(serverInfo.port);
1399
1514
  globalTcpConnections.set(this.connectionId, connection);
1400
1515
  }
1401
- const result = await this.executeOnConnection(connection, request.args);
1516
+ const result = await this.executeOnConnection(connection, request.command);
1402
1517
  request.resolve(result);
1403
1518
  } catch (error) {
1519
+ const staleConnection = globalTcpConnections.get(this.connectionId);
1520
+ if (staleConnection) {
1521
+ try {
1522
+ staleConnection.destroy();
1523
+ } catch {
1524
+ }
1525
+ }
1404
1526
  globalTcpConnections.delete(this.connectionId);
1405
1527
  request.reject(error);
1406
1528
  }
@@ -1428,16 +1550,8 @@ var QueryEngine = class {
1428
1550
  });
1429
1551
  });
1430
1552
  }
1431
- async executeOnConnection(connection, args) {
1553
+ async executeOnConnection(connection, command) {
1432
1554
  return new Promise((resolve5, reject) => {
1433
- const command = {};
1434
- for (let i = 0; i < args.length; i += 2) {
1435
- if (args[i].startsWith("--")) {
1436
- const key = args[i].substring(2);
1437
- const value = args[i + 1];
1438
- command[key] = value;
1439
- }
1440
- }
1441
1555
  let responseBuffer = "";
1442
1556
  let isResolved = false;
1443
1557
  const timeout = setTimeout(() => {
@@ -1479,7 +1593,7 @@ var QueryEngine = class {
1479
1593
  };
1480
1594
  connection.on("data", onData);
1481
1595
  connection.on("error", onError);
1482
- connection.write(JSON.stringify(command));
1596
+ connection.write(JSON.stringify(command) + "\n");
1483
1597
  });
1484
1598
  }
1485
1599
  async createProcess(binary, args) {
@@ -2403,7 +2517,7 @@ var ComputedFieldProcessor = class {
2403
2517
  const tableExistsQuery = `SELECT name FROM sqlite_master WHERE type='table' AND name='dbcube_computes_config'`;
2404
2518
  const tableExistsResult = await DbConfig_default.query(tableExistsQuery);
2405
2519
  if (tableExistsResult.status === "success" && tableExistsResult.data && tableExistsResult.data.length > 0) {
2406
- const queryComputes = await DbConfig_default.query(`SELECT * FROM dbcube_computes_config WHERE database_ref='${name}'`);
2520
+ const queryComputes = await DbConfig_default.queryWithParameters(`SELECT * FROM dbcube_computes_config WHERE database_ref=?`, [name]);
2407
2521
  computedFields = queryComputes.data;
2408
2522
  } else {
2409
2523
  computedFields = [];
@@ -2434,21 +2548,10 @@ var ComputedFieldProcessor = class {
2434
2548
  }
2435
2549
  functionBody = functionBody.replace(/@column\(([^)]+)\)/g, (_match, columnName) => {
2436
2550
  const cleanColumnName = columnName.trim().replace(/['"]/g, "");
2437
- const value = rowData[cleanColumnName];
2438
- if (value === null || value === void 0) {
2439
- return "null";
2440
- } else if (typeof value === "string") {
2441
- return `"${value.replace(/"/g, '\\"')}"`;
2442
- } else if (typeof value === "number" || typeof value === "boolean") {
2443
- return value.toString();
2444
- } else if (value instanceof Date) {
2445
- return `new Date("${value.toISOString()}")`;
2446
- } else {
2447
- return JSON.stringify(value);
2448
- }
2551
+ return `__row[${JSON.stringify(cleanColumnName)}]`;
2449
2552
  });
2450
- const computeFunction = new Function(functionBody);
2451
- return computeFunction();
2553
+ const computeFunction = new Function("__row", functionBody);
2554
+ return computeFunction(rowData);
2452
2555
  } catch (error) {
2453
2556
  console.error("Error processing computed field:", error);
2454
2557
  return null;
@@ -2491,14 +2594,7 @@ var ComputedFieldProcessor = class {
2491
2594
  /@column\(([^)]+)\)/g,
2492
2595
  (match, columnName) => {
2493
2596
  const cleanColumnName = columnName.replace(/['"]/g, "");
2494
- const value = processedItem[cleanColumnName];
2495
- if (typeof value === "string") {
2496
- return `"${value}"`;
2497
- } else if (value === null || value === void 0) {
2498
- return "null";
2499
- } else {
2500
- return String(value);
2501
- }
2597
+ return `__row[${JSON.stringify(cleanColumnName)}]`;
2502
2598
  }
2503
2599
  );
2504
2600
  const computeMatch = processedExpression.match(/@compute\s*\(\s*\(\s*\)\s*=>\s*\{(.*)\}\s*\)/s);
@@ -2506,8 +2602,8 @@ var ComputedFieldProcessor = class {
2506
2602
  throw new Error(`Formato de @compute inv\xE1lido para campo ${fieldName}`);
2507
2603
  }
2508
2604
  const functionBody = computeMatch[1];
2509
- const computeFunction = new Function(functionBody);
2510
- let result = computeFunction();
2605
+ const computeFunction = new Function("__row", functionBody);
2606
+ let result = computeFunction(processedItem);
2511
2607
  result = convertToType(result, type2);
2512
2608
  processedItem[fieldName] = result;
2513
2609
  } catch (error) {
@@ -2699,14 +2795,14 @@ var TableProcessor = class {
2699
2795
  if (await DbConfig_default.ifExist()) {
2700
2796
  await DbConfig_default.connect();
2701
2797
  try {
2702
- const tableExistsQuery = `SELECT name FROM sqlite_master WHERE type='table' AND name='dbcube_computes_config'`;
2798
+ const tableExistsQuery = `SELECT name FROM sqlite_master WHERE type='table' AND name='dbcube_schemas_config'`;
2703
2799
  const tableExistsResult = await DbConfig_default.query(tableExistsQuery);
2704
2800
  if (tableExistsResult.status === "success" && tableExistsResult.data && tableExistsResult.data.length > 0) {
2705
- const queryComputes = await DbConfig_default.query(`SELECT * FROM dbcube_schemas_config WHERE table_ref='${tableName}' AND database_ref='${database_ref}'`);
2801
+ const queryComputes = await DbConfig_default.queryWithParameters(`SELECT * FROM dbcube_schemas_config WHERE table_ref=? AND database_ref=?`, [tableName, database_ref]);
2706
2802
  const oldQuery = queryComputes.data[0];
2707
2803
  if (!oldQuery || !oldQuery.struct) {
2708
- console.error("No exist a previus schema please execute the refresh first...", oldQuery);
2709
- return [];
2804
+ await DbConfig_default.disconnect();
2805
+ return [nowQuery];
2710
2806
  }
2711
2807
  const nowSchema = parseCreateTableQuery(nowQuery, dbType);
2712
2808
  const oldSchema = parseCreateTableQuery(oldQuery.struct, dbType);
@@ -2741,7 +2837,7 @@ var TableProcessor = class {
2741
2837
  if (await DbConfig_default.ifExist()) {
2742
2838
  await DbConfig_default.connect();
2743
2839
  try {
2744
- await DbConfig_default.query(`DELETE FROM dbcube_schemas_config WHERE table_ref='${table_ref}' AND database_ref='${database_ref}'`);
2840
+ await DbConfig_default.queryWithParameters(`DELETE FROM dbcube_schemas_config WHERE table_ref=? AND database_ref=?`, [table_ref, database_ref]);
2745
2841
  const tableExistsQuery = `INSERT INTO dbcube_schemas_config (table_ref, database_ref, struct) VALUES (?, ?, ?)`;
2746
2842
  await DbConfig_default.queryWithParameters(tableExistsQuery, [table_ref, database_ref, struct]);
2747
2843
  } catch (error) {
@@ -2760,7 +2856,7 @@ var TriggerProcessor = class {
2760
2856
  const tableExistsQuery = `SELECT name FROM sqlite_master WHERE type='table' AND name='dbcube_triggers_config'`;
2761
2857
  const tableExistsResult = await DbConfig_default.query(tableExistsQuery);
2762
2858
  if (tableExistsResult.status === "success" && tableExistsResult.data && tableExistsResult.data.length > 0) {
2763
- const queryComputes = await DbConfig_default.query(`SELECT * FROM dbcube_triggers_config WHERE database_ref='${name}'`);
2859
+ const queryComputes = await DbConfig_default.queryWithParameters(`SELECT * FROM dbcube_triggers_config WHERE database_ref=?`, [name]);
2764
2860
  triggers = queryComputes.data;
2765
2861
  } else {
2766
2862
  triggers = [];