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 +6 -0
- package/lib/model/DbIndex.js +39 -0
- package/lib/model/DbRelation.js +18 -1
- package/package.json +1 -1
package/lib/DbLang.js
CHANGED
|
@@ -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
|
package/lib/model/DbRelation.js
CHANGED
|
@@ -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
|