doix-db 1.0.12 → 1.0.13

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/lib/DbLang.js CHANGED
@@ -267,9 +267,11 @@ class DbLang {
267
267
 
268
268
  if (!Array.isArray (params)) params = [params]
269
269
 
270
- const {map} = this.model || {}; if (map && map.has (sqlOrName)) {
270
+ const {model} = this
271
271
 
272
- const {qName, pk, columns} = map.get (sqlOrName)
272
+ const relation = model ? model.find (sqlOrName) : undefined; if (relation) {
273
+
274
+ const {qName, pk, columns} = relation
273
275
 
274
276
  let filter = ''; for (const name of pk) {
275
277
 
@@ -296,9 +298,9 @@ class DbLang {
296
298
 
297
299
  const {model} = this; if (!model) throw Error ('Model not set')
298
300
 
299
- const {map} = model; if (!map.has (name)) throw Error ('Entity not defined: ' + name)
301
+ const table = model.find (name); if (!table) throw Error ('Entity not defined: ' + name)
300
302
 
301
- const {pk, columns, qName} = map.get (name)
303
+ const {columns, qName} = table
302
304
 
303
305
  let sql = '', params = []
304
306
 
@@ -308,7 +310,7 @@ class DbLang {
308
310
 
309
311
  if (!(k in columns)) continue
310
312
 
311
- const {qName, nullable} = columns [k]
313
+ const {qName} = columns [k]
312
314
 
313
315
  if (sql.length !== 0) sql += ','
314
316
 
@@ -345,9 +347,9 @@ class DbLang {
345
347
 
346
348
  const {model} = this; if (!model) throw Error ('Model not set')
347
349
 
348
- const {map} = model; if (!map.has (name)) throw Error ('Entity not defined: ' + name)
350
+ const table = model.find (name); if (!table) throw Error ('Entity not defined: ' + name)
349
351
 
350
- const {pk, columns, qName} = map.get (name)
352
+ const {pk, columns, qName} = table
351
353
 
352
354
  const sql = ['', ''], params = []
353
355
 
@@ -33,7 +33,10 @@ class DbMigrationPlan extends EventEmitter {
33
33
  this.db = db
34
34
  this.lang = db.lang
35
35
  this.model = db.model
36
- this.toBe = db.model.map
36
+
37
+ this.toBe = new Map (); for (const {prefix, map} of db.model.schemata.values ())
38
+ for (const [k, v] of map.entries ())
39
+ this.toBe.set (prefix + k, v)
37
40
 
38
41
  db.lang.migrationPlan = this
39
42
 
@@ -148,7 +151,7 @@ class DbMigrationPlan extends EventEmitter {
148
151
 
149
152
  const methodName = `getStreamOfExisting${type.name.slice (2)}s`
150
153
 
151
- const {db, asIs, toBe} = this, s = await db [methodName] ()
154
+ const {db, toBe} = this, s = await db [methodName] ()
152
155
 
153
156
  return new Promise ((ok, fail) => {
154
157
 
@@ -74,12 +74,6 @@ class DbModel extends EventEmitter {
74
74
  return this.schemata.get (null)
75
75
 
76
76
  }
77
-
78
- get map () {
79
-
80
- return this.defaultSchema.map
81
-
82
- }
83
77
 
84
78
  loadModules () {
85
79
 
@@ -91,13 +85,13 @@ class DbModel extends EventEmitter {
91
85
 
92
86
  find (name) {
93
87
 
94
- if (this.map.has (name)) return this.map.get (name)
88
+ if (typeof name !== 'string') return undefined
95
89
 
96
- const dot = name.indexOf ('.'); if (dot < 1) return undefined
90
+ const dot = name.indexOf ('.'); if (dot === -1) return this.defaultSchema.map.get (name)
97
91
 
98
- const schema = this.getSchema (name.slice (0, dot)); if (!schema) return undefined
92
+ const schema = this.schemata.get (name.slice (0, dot))
99
93
 
100
- return schema.map.get (name.slice (dot + 1)) || undefined
94
+ return schema ? schema.map.get (name.slice (dot + 1)) : undefined
101
95
 
102
96
  }
103
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doix-db",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Shared database related code for doix",
5
5
  "main": "index.js",
6
6
  "files": [