doix-db 0.0.2 → 0.0.3
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/index.js +2 -0
- package/lib/DbModel.js +42 -0
- package/lib/DbPool.js +18 -0
- package/package.json +1 -1
package/index.js
CHANGED
package/lib/DbModel.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const DbPool = require ('./DbPool.js')
|
|
2
|
+
const DbObjectMap = require ('./DbObjectMap.js')
|
|
3
|
+
|
|
4
|
+
class DbModel {
|
|
5
|
+
|
|
6
|
+
constructor (o) {
|
|
7
|
+
|
|
8
|
+
let mapOptions = {}
|
|
9
|
+
|
|
10
|
+
for (const [k, v] of Object.entries (o)) if (v !== undefined) switch (k) {
|
|
11
|
+
|
|
12
|
+
case 'dir':
|
|
13
|
+
case 'ext':
|
|
14
|
+
case 'merger':
|
|
15
|
+
case 'detector':
|
|
16
|
+
mapOptions [k] = v
|
|
17
|
+
break
|
|
18
|
+
|
|
19
|
+
case 'db':
|
|
20
|
+
if (!(v instanceof DbPool)) throw new Error ('Only DbPool descendant can be used as db')
|
|
21
|
+
this.db = v
|
|
22
|
+
v.model = this
|
|
23
|
+
break
|
|
24
|
+
|
|
25
|
+
default:
|
|
26
|
+
throw new Error ('Unknown DbModel option: ' + k)
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.map = new DbObjectMap (mapOptions)
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
loadModules () {
|
|
35
|
+
|
|
36
|
+
this.map.load ()
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = DbModel
|
package/lib/DbPool.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const {ResourcePool} = require ('doix')
|
|
2
|
+
const DbEventLogger = require ('./DbEventLogger.js')
|
|
3
|
+
|
|
4
|
+
class DbPool extends ResourcePool {
|
|
5
|
+
|
|
6
|
+
constructor (o) {
|
|
7
|
+
|
|
8
|
+
super ()
|
|
9
|
+
|
|
10
|
+
this.logger = o.logger
|
|
11
|
+
|
|
12
|
+
this.eventLoggerClass = o.eventLoggerClass || DbEventLogger
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = DbPool
|