@platformatic/sql-mapper 1.16.0 → 1.17.0

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.
Files changed (3) hide show
  1. package/mapper.js +18 -1
  2. package/package.json +4 -4
  3. package/.taprc +0 -1
package/mapper.js CHANGED
@@ -101,7 +101,7 @@ async function createConnectionPool ({ log, connectionString, poolSize, idleTime
101
101
  return { db, sql }
102
102
  }
103
103
 
104
- async function connect ({ connectionString, log, onDatabaseLoad, poolSize, ignore = {}, autoTimestamp = true, hooks = {}, schema, limit = {}, dbschema, cache, idleTimeoutMilliseconds, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds }) {
104
+ async function connect ({ connectionString, log, onDatabaseLoad, poolSize, include = {}, ignore = {}, autoTimestamp = true, hooks = {}, schema, limit = {}, dbschema, cache, idleTimeoutMilliseconds, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds }) {
105
105
  if (typeof autoTimestamp === 'boolean' && autoTimestamp === true) {
106
106
  autoTimestamp = defaultAutoTimestampFields
107
107
  }
@@ -164,6 +164,19 @@ async function connect ({ connectionString, log, onDatabaseLoad, poolSize, ignor
164
164
  }
165
165
 
166
166
  const schemaTables = dbschema.map(table => table.table)
167
+ if (Object.keys(include).length) {
168
+ for (const includedTable of Object.keys(include)) {
169
+ if (!schemaTables.includes(includedTable)) {
170
+ const nearestTable = findNearestString(schemaTables, includedTable)
171
+ let warningMessage = `Specified table "${includedTable}" not found.`
172
+ if (nearestTable) {
173
+ warningMessage += ` Did you mean "${nearestTable}"?`
174
+ }
175
+ log.warn(warningMessage)
176
+ }
177
+ }
178
+ }
179
+
167
180
  for (const ignoredTable of Object.keys(ignore)) {
168
181
  if (!schemaTables.includes(ignoredTable)) {
169
182
  const nearestTable = findNearestString(schemaTables, ignoredTable)
@@ -182,6 +195,10 @@ async function connect ({ connectionString, log, onDatabaseLoad, poolSize, ignor
182
195
  if (typeof table !== 'string') {
183
196
  throw new errors.TableMustBeAStringError(table)
184
197
  }
198
+ // If include is being used and a table is not explicitly included add it to the ignore object
199
+ if (Object.keys(include).length && !include[table]) {
200
+ ignore[table] = true
201
+ }
185
202
  if (ignore[table] === true) {
186
203
  continue
187
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-mapper",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "A data mapper utility for SQL databases",
5
5
  "main": "mapper.js",
6
6
  "types": "mapper.d.ts",
@@ -20,7 +20,7 @@
20
20
  "glob": "^10.3.10",
21
21
  "snazzy": "^9.0.0",
22
22
  "standard": "^17.1.0",
23
- "tsd": "^0.29.0"
23
+ "tsd": "^0.30.0"
24
24
  },
25
25
  "dependencies": {
26
26
  "@databases/mysql": "^6.0.0",
@@ -33,14 +33,14 @@
33
33
  "camelcase": "^6.3.0",
34
34
  "fastify-plugin": "^4.5.1",
35
35
  "inflected": "^2.1.0",
36
- "@platformatic/utils": "1.16.0"
36
+ "@platformatic/utils": "1.17.0"
37
37
  },
38
38
  "tsd": {
39
39
  "directory": "test/types"
40
40
  },
41
41
  "scripts": {
42
42
  "lint": "standard | snazzy",
43
- "test": "standard | snazzy && npm run test:typescript && npm run test:postgresql && npm run test:mariadb && npm run test:mysql && npm run test:mysql8 && npm run test:sqlite",
43
+ "test": "npm run lint && npm run test:typescript && npm run test:postgresql && npm run test:mariadb && npm run test:mysql && npm run test:mysql8 && npm run test:sqlite",
44
44
  "test:runner": "node ./test/runner.js",
45
45
  "test:postgresql": "DB=postgresql npm run test:runner",
46
46
  "test:mariadb": "DB=mariadb npm run test:runner",
package/.taprc DELETED
@@ -1 +0,0 @@
1
- jobs: 1