waibu-db 1.2.1 → 1.2.2

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/README.md CHANGED
@@ -18,6 +18,10 @@ $ npm install waibu-db
18
18
 
19
19
  Now open your ```<bajo-data-dir>/config/.plugins``` and put ```waibu-db``` in it
20
20
 
21
+ ## Configuration
22
+
23
+ - ```modelRestApi```: set to ```true``` to enable the auto creation of model's rest API. default: ```false```
24
+
21
25
  ## License
22
26
 
23
27
  [MIT](LICENSE)
@@ -0,0 +1,10 @@
1
+ async function afterInit () {
2
+ if (!this.config.modelRestApi) {
3
+ this.app.waibuRestApi.config.disabled.push(
4
+ 'waibuDb:/:model',
5
+ 'waibuDb:/:model/:id'
6
+ )
7
+ }
8
+ }
9
+
10
+ export default afterInit
package/index.js CHANGED
@@ -21,7 +21,8 @@ async function factory (pkgName) {
21
21
  dbModel: {
22
22
  count: false,
23
23
  patchEnabled: false
24
- }
24
+ },
25
+ modelRestApi: false
25
26
  }
26
27
  }
27
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,5 @@
1
+ async function get (req, reply) {
2
+ return await this.recordGet({ req, reply })
3
+ }
4
+
5
+ export default get
@@ -0,0 +1,5 @@
1
+ async function remove (req, reply) {
2
+ return await this.recordRemove({ req, reply })
3
+ }
4
+
5
+ export default remove
@@ -0,0 +1,5 @@
1
+ async function update (req, reply) {
2
+ return await this.recordUpdate({ req, reply })
3
+ }
4
+
5
+ export default update
@@ -0,0 +1,5 @@
1
+ async function create (req, reply) {
2
+ return await this.recordCreate({ req, reply })
3
+ }
4
+
5
+ export default create
@@ -0,0 +1,14 @@
1
+ async function find (req, reply) {
2
+ const { isSet } = this.lib.aneka
3
+ const { parseObject } = this.app.bajo
4
+ let { fields, count } = this.getParams(req)
5
+ let rels = []
6
+ const headers = parseObject(req.headers, { parseValue: true })
7
+ if (isSet(headers['x-count'])) count = headers['x-count']
8
+ if (isSet(headers['x-rels'])) rels = headers['x-rels']
9
+ if (typeof rels === 'string' && !['*', 'all'].includes(rels)) rels = [rels]
10
+ const options = { fields, count, rels }
11
+ return await this.recordFind({ req, reply, options })
12
+ }
13
+
14
+ export default find