doix-db 1.0.4 → 1.0.6

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
@@ -502,6 +502,12 @@ class DbLang {
502
502
 
503
503
  }
504
504
 
505
+ getIndexName (relation, index) {
506
+
507
+ return relation.name + '_' + index.name
508
+
509
+ }
510
+
505
511
  }
506
512
 
507
513
  module.exports = DbLang
@@ -0,0 +1,39 @@
1
+ const DbObject = require ('./DbObject.js')
2
+
3
+ class DbIndex extends DbObject {
4
+
5
+ constructor (o, r, name) {
6
+
7
+ if (typeof o === 'string') o = [o]
8
+
9
+ if (Array.isArray (o)) o = {parts: o}
10
+
11
+ if (typeof o !== 'object') throw Error ('Invalid DbIndex options')
12
+
13
+ o.relation = r
14
+
15
+ if (!o.name) o.name = name
16
+
17
+ for (const k of ['options']) if (!o [k]) o [k] = []
18
+
19
+ o.originalLocalName = o.localName
20
+
21
+ super (o)
22
+
23
+ }
24
+
25
+ setLang (lang) {
26
+
27
+ const {relation} = this
28
+
29
+ this.schemaName = relation.schemaName
30
+
31
+ this.localName = this.originalLocalName || lang.getIndexName (relation, this)
32
+
33
+ super.setLang (lang)
34
+
35
+ }
36
+
37
+ }
38
+
39
+ module.exports = DbIndex
@@ -1,5 +1,6 @@
1
1
  const DbObject = require ('./DbObject.js')
2
2
  const DbColumn = require ('./DbColumn.js')
3
+ const DbIndex = require ('./DbIndex.js')
3
4
 
4
5
  class DbRelation extends DbObject {
5
6
 
@@ -41,6 +42,8 @@ class DbRelation extends DbObject {
41
42
 
42
43
  }
43
44
 
45
+ if (this.keys == null) this.keys = {}
46
+
44
47
  }
45
48
 
46
49
  setLang (lang) {
@@ -49,8 +52,22 @@ class DbRelation extends DbObject {
49
52
 
50
53
  for (const col of Object.values (this.columns)) col.setLang (lang)
51
54
 
55
+ const {keys} = this; for (const k in keys) {
56
+
57
+ const v = keys [k]; if (v !== null) {
58
+
59
+ const index = new DbIndex (v, this, k)
60
+
61
+ index.setLang (lang)
62
+
63
+ keys [k] = index
64
+
65
+ }
66
+
67
+ }
68
+
52
69
  }
53
-
70
+
54
71
  }
55
72
 
56
73
  module.exports = DbRelation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doix-db",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Shared database related code for doix",
5
5
  "main": "index.js",
6
6
  "files": [