db-model-router 1.0.20 → 1.0.21

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": "db-model-router",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Generative API Creation using mysql2 and express libraries in node js",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -2,7 +2,7 @@
2
2
 
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
- const { generateModelFile } = require("./generate-model.js");
5
+ const { generateModelFile, generateIndexFile } = require("./generate-model.js");
6
6
  const {
7
7
  generateRouteFile,
8
8
  generateParentRouteFile,
@@ -87,6 +87,10 @@ function buildExpectedFiles(meta, relationships, options = {}) {
87
87
  expected.set(`models/${m.table}.js`, generateModelFile(m));
88
88
  }
89
89
 
90
+ // Model barrel. SaaS mode overwrites this with the combined SaaS+dbmr
91
+ // barrel when saasFiles are merged below.
92
+ expected.set("models/index.js", generateIndexFile(meta));
93
+
90
94
  // Route files: exactly one per table at its correct nested path
91
95
  for (const m of meta) {
92
96
  const tableName = m.table;
@@ -703,9 +703,17 @@ function generateInitialMigration(answers, date) {
703
703
  executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
704
704
  checksum VARCHAR2(64) NOT NULL
705
705
  );
706
+ `;
707
+ } else if (answers.database === "mysql" || answers.database === "mariadb") {
708
+ content = `CREATE TABLE IF NOT EXISTS _migrations (
709
+ id BIGINT AUTO_INCREMENT PRIMARY KEY,
710
+ filename VARCHAR(255) NOT NULL UNIQUE,
711
+ executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
712
+ checksum VARCHAR(64) NOT NULL
713
+ );
706
714
  `;
707
715
  } else {
708
- // mysql, sqlite3
716
+ // sqlite3
709
717
  content = `CREATE TABLE IF NOT EXISTS _migrations (
710
718
  id INTEGER PRIMARY KEY AUTOINCREMENT,
711
719
  filename VARCHAR(255) NOT NULL UNIQUE,
package/src/mysql/db.js CHANGED
@@ -7,6 +7,12 @@ function connect(credentails) {
7
7
  // Force UTC timezone so timestamps are consistent
8
8
  // dateStrings: true returns raw strings without JS Date conversion
9
9
  credentails.timezone = "+00:00";
10
+ // Enable multiple statements by default so multi-query migration files
11
+ // (e.g. a single .sql with many CREATE TABLE statements) run in one call.
12
+ // Applied to mysql and mariadb (both use this adapter).
13
+ if (credentails.multipleStatements === undefined) {
14
+ credentails.multipleStatements = true;
15
+ }
10
16
  pool = mysql.createPool(credentails);
11
17
  return pool;
12
18
  }