dobo 1.2.10 → 2.0.1
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/.github/FUNDING.yml +13 -0
- package/.github/workflows/repo-lockdown.yml +24 -0
- package/.jsdoc.conf.json +45 -0
- package/LICENSE +1 -1
- package/README.md +38 -19
- package/docs/Dobo.html +26 -0
- package/docs/data/search.json +1 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +7 -0
- package/docs/index.html +3 -0
- package/docs/index.js.html +578 -0
- package/docs/lib_collect-connections.js.html +39 -0
- package/docs/lib_collect-drivers.js.html +52 -0
- package/docs/lib_collect-features.js.html +36 -0
- package/docs/lib_collect-schemas.js.html +94 -0
- package/docs/lib_index.js.html +6 -0
- package/docs/method_model_create.js.html +35 -0
- package/docs/method_model_drop.js.html +34 -0
- package/docs/method_model_exists.js.html +40 -0
- package/docs/method_record_count.js.html +69 -0
- package/docs/method_record_create.js.html +114 -0
- package/docs/method_record_find-all.js.html +44 -0
- package/docs/method_record_find-one.js.html +73 -0
- package/docs/method_record_find.js.html +118 -0
- package/docs/method_record_get.js.html +92 -0
- package/docs/method_record_remove.js.html +75 -0
- package/docs/method_record_update.js.html +107 -0
- package/docs/method_record_upsert.js.html +54 -0
- package/docs/method_sanitize_body.js.html +88 -0
- package/docs/method_sanitize_date.js.html +30 -0
- package/docs/method_sanitize_id.js.html +20 -0
- package/docs/method_validate.js.html +249 -0
- package/docs/module-Lib.html +3 -0
- package/docs/scripts/core.js +726 -0
- package/docs/scripts/core.min.js +23 -0
- package/docs/scripts/resize.js +90 -0
- package/docs/scripts/search.js +265 -0
- package/docs/scripts/search.min.js +6 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/scripts/third-party/hljs-original.js +5171 -0
- package/docs/scripts/third-party/hljs.js +1 -0
- package/docs/scripts/third-party/popper.js +5 -0
- package/docs/scripts/third-party/tippy.js +1 -0
- package/docs/scripts/third-party/tocbot.js +672 -0
- package/docs/scripts/third-party/tocbot.min.js +1 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +25 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/styles/clean-jsdoc-theme.min.css +1 -0
- package/{bajo → extend/bajo}/intl/en-US.json +3 -2
- package/{bajo → extend/bajo}/intl/id.json +3 -2
- package/{bajoCli → extend/bajoCli}/applet/connection.js +5 -5
- package/extend/bajoCli/applet/lib/post-process.js +53 -0
- package/extend/bajoCli/applet/model-clear.js +11 -0
- package/{bajoCli → extend/bajoCli}/applet/model-rebuild.js +13 -13
- package/{bajoCli → extend/bajoCli}/applet/record-create.js +10 -8
- package/{bajoCli → extend/bajoCli}/applet/record-find.js +6 -5
- package/{bajoCli → extend/bajoCli}/applet/record-get.js +5 -5
- package/{bajoCli → extend/bajoCli}/applet/record-remove.js +5 -5
- package/{bajoCli → extend/bajoCli}/applet/record-update.js +9 -9
- package/{bajoCli → extend/bajoCli}/applet/schema.js +4 -4
- package/{bajoCli → extend/bajoCli}/applet/stat-count.js +4 -4
- package/{dobo → extend/dobo}/feature/created-at.js +1 -1
- package/{dobo → extend/dobo}/feature/removed-at.js +3 -3
- package/{dobo → extend/dobo}/feature/updated-at.js +2 -2
- package/{waibuMpa → extend/waibuMpa}/route/attachment/@model/@id/@field/@file.js +3 -3
- package/index.js +230 -72
- package/lib/add-fixtures.js +7 -6
- package/lib/build-bulk-action.js +2 -2
- package/lib/check-unique.js +2 -2
- package/lib/collect-connections.js +15 -4
- package/lib/collect-drivers.js +15 -6
- package/lib/{collect-feature.js → collect-features.js} +13 -4
- package/lib/collect-schemas.js +22 -12
- package/lib/exec-feature-hook.js +1 -1
- package/lib/exec-validation.js +5 -5
- package/lib/generic-prop-sanitizer.js +6 -5
- package/lib/handle-attachment-upload.js +2 -2
- package/lib/index.js +3 -0
- package/lib/mem-db/conn-sanitizer.js +1 -1
- package/lib/mem-db/instantiate.js +4 -4
- package/lib/mem-db/method/record/find.js +1 -1
- package/lib/mem-db/method/record/get.js +1 -1
- package/lib/mem-db/method/record/remove.js +1 -1
- package/lib/mem-db/method/record/update.js +1 -1
- package/lib/mem-db/start.js +1 -1
- package/lib/merge-attachment-info.js +2 -2
- package/lib/multi-rel-rows.js +2 -2
- package/lib/resolve-method.js +3 -3
- package/lib/sanitize-schema.js +8 -7
- package/lib/single-rel-rows.js +2 -2
- package/{plugin-method → method}/attachment/copy-uploaded.js +2 -2
- package/{plugin-method → method}/attachment/create.js +3 -3
- package/{plugin-method → method}/attachment/find.js +2 -2
- package/{plugin-method → method}/attachment/get-path.js +3 -3
- package/{plugin-method → method}/attachment/get.js +1 -1
- package/{plugin-method → method}/attachment/pre-check.js +1 -1
- package/{plugin-method → method}/attachment/remove.js +1 -1
- package/{plugin-method → method}/bulk/create.js +6 -6
- package/{plugin-method → method}/model/clear.js +5 -5
- package/method/model/create.js +32 -0
- package/method/model/drop.js +31 -0
- package/method/model/exists.js +37 -0
- package/{plugin-method → method}/record/clear.js +5 -5
- package/{plugin-method → method}/record/count.js +27 -5
- package/{plugin-method → method}/record/create.js +46 -6
- package/{plugin-method → method}/record/find-all.js +16 -0
- package/{plugin-method → method}/record/find-one.js +20 -6
- package/method/record/find.js +115 -0
- package/method/record/get.js +89 -0
- package/method/record/remove.js +72 -0
- package/{plugin-method → method}/record/update.js +47 -6
- package/{plugin-method → method}/record/upsert.js +18 -2
- package/{plugin-method → method}/sanitize/body.js +18 -3
- package/method/sanitize/date.js +27 -0
- package/{plugin-method → method}/sanitize/id.js +10 -0
- package/{plugin-method → method}/stat/aggregate.js +4 -4
- package/{plugin-method → method}/stat/histogram.js +4 -4
- package/{plugin-method → method}/validate.js +96 -7
- package/package.json +41 -36
- package/wiki/APPLETS.md +57 -0
- package/wiki/CONFIG.md +25 -0
- package/wiki/CONTRIBUTING.md +5 -0
- package/wiki/DEV-GUIDE.md +1 -0
- package/wiki/ECOSYSTEM.md +20 -0
- package/wiki/GETTING-STARTED.md +166 -0
- package/wiki/USER-GUIDE.md +1 -0
- package/bajoCli/applet/lib/post-process.js +0 -47
- package/bajoCli/applet/model-clear.js +0 -11
- package/plugin-method/model/create.js +0 -19
- package/plugin-method/model/drop.js +0 -19
- package/plugin-method/model/exists.js +0 -24
- package/plugin-method/record/find.js +0 -52
- package/plugin-method/record/get.js +0 -47
- package/plugin-method/record/remove.js +0 -41
- package/plugin-method/sanitize/date.js +0 -14
- /package/{bajoCli → extend/bajoCli}/applet.js +0 -0
- /package/{dobo → extend/dobo}/feature/dt.js +0 -0
- /package/{dobo → extend/dobo}/feature/int-id.js +0 -0
- /package/{waibuStatic → extend/waibuStatic}/virtual.json +0 -0
- /package/{plugin-method → method}/attachment/update.js +0 -0
- /package/{docs/query-language.md → wiki/QUERY-LANGUAGE.md} +0 -0
|
@@ -7,15 +7,15 @@ async function aggregate (name, filter = {}, options = {}) {
|
|
|
7
7
|
await this.modelExists(name, true)
|
|
8
8
|
const { handler, schema, driver } = await resolveMethod.call(this, name, 'stat-aggregate', options)
|
|
9
9
|
if (!noHook) {
|
|
10
|
-
await runHook(`${this.
|
|
11
|
-
await runHook(`${this.
|
|
10
|
+
await runHook(`${this.ns}:beforeStatAggregate`, name, aggregate, filter, options)
|
|
11
|
+
await runHook(`${this.ns}.${name}:beforeStatAggregate`, aggregate, filter, options)
|
|
12
12
|
}
|
|
13
13
|
filter.query = this.buildQuery({ filter, schema, options }) ?? {}
|
|
14
14
|
filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
|
|
15
15
|
const rec = await handler.call(this.app[driver.ns], { schema, filter, options })
|
|
16
16
|
if (!noHook) {
|
|
17
|
-
await runHook(`${this.
|
|
18
|
-
await runHook(`${this.
|
|
17
|
+
await runHook(`${this.ns}.${name}:afterStatAggregate`, aggregate, filter, options, rec)
|
|
18
|
+
await runHook(`${this.ns}:afterStatAggregate`, name, aggregate, filter, options, rec)
|
|
19
19
|
}
|
|
20
20
|
return dataOnly ? rec.data : rec
|
|
21
21
|
}
|
|
@@ -12,13 +12,13 @@ async function histogram (name, filter = {}, options = {}) {
|
|
|
12
12
|
filter.query = this.buildQuery({ filter, schema, options }) ?? {}
|
|
13
13
|
filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
|
|
14
14
|
if (!noHook) {
|
|
15
|
-
await runHook(`${this.
|
|
16
|
-
await runHook(`${this.
|
|
15
|
+
await runHook(`${this.ns}:beforeStatHistogram`, name, type, filter, options)
|
|
16
|
+
await runHook(`${this.ns}.${name}:beforeStatHistogram`, type, filter, options)
|
|
17
17
|
}
|
|
18
18
|
const rec = await handler.call(this.app[driver.ns], { schema, type, filter, options })
|
|
19
19
|
if (!noHook) {
|
|
20
|
-
await runHook(`${this.
|
|
21
|
-
await runHook(`${this.
|
|
20
|
+
await runHook(`${this.ns}.${name}:afterStatHistogram`, type, filter, options, rec)
|
|
21
|
+
await runHook(`${this.ns}:afterStatHistogram`, name, type, filter, options, rec)
|
|
22
22
|
}
|
|
23
23
|
return dataOnly ? rec.data : rec
|
|
24
24
|
}
|
|
@@ -3,6 +3,80 @@ import joi from 'joi'
|
|
|
3
3
|
const excludedTypes = ['object', 'array']
|
|
4
4
|
const excludedNames = []
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {string[]} TValidatorString
|
|
8
|
+
* @property {string} 0=alphanum
|
|
9
|
+
* @property {string} 1=base64
|
|
10
|
+
* @property {string} 2=case
|
|
11
|
+
* @property {string} 3=creditCard
|
|
12
|
+
* @property {string} 4=dataUri
|
|
13
|
+
* @property {string} 5=email
|
|
14
|
+
* @property {string} 6=guid
|
|
15
|
+
* @property {string} 7=uuid
|
|
16
|
+
* @property {string} 8=hex
|
|
17
|
+
* @property {string} 9=hostname
|
|
18
|
+
* @property {string} 10=insenstive
|
|
19
|
+
* @property {string} 11=ip
|
|
20
|
+
* @property {string} 12=isoDate
|
|
21
|
+
* @property {string} 13=isoDuration
|
|
22
|
+
* @property {string} 14=length
|
|
23
|
+
* @property {string} 15=lowercase
|
|
24
|
+
* @property {string} 16=max
|
|
25
|
+
* @property {string} 17=min
|
|
26
|
+
* @property {string} 18=normalize
|
|
27
|
+
* @property {string} 19=pattern
|
|
28
|
+
* @property {string} 20=regex
|
|
29
|
+
* @property {string} 21=replace
|
|
30
|
+
* @property {string} 22=token
|
|
31
|
+
* @property {string} 23=trim
|
|
32
|
+
* @property {string} 24=truncate
|
|
33
|
+
* @property {string} 25=upercase
|
|
34
|
+
* @property {string} 26=uri
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {string[]} TValidatorNumber
|
|
39
|
+
* @property {string} 0=great
|
|
40
|
+
* @property {string} 1=less
|
|
41
|
+
* @property {string} 2=max
|
|
42
|
+
* @property {string} 3=min
|
|
43
|
+
* @property {string} 4=multiple
|
|
44
|
+
* @property {string} 5=negative
|
|
45
|
+
* @property {string} 6=port
|
|
46
|
+
* @property {string} 7=positive
|
|
47
|
+
* @property {string} 8=sign
|
|
48
|
+
* @property {string} 9=unsafe
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {string[]} TValidatorBoolean
|
|
53
|
+
* @property {string} 0=falsy
|
|
54
|
+
* @property {string} 1=sensitive
|
|
55
|
+
* @property {string} 2=truthy
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {string[]} TValidatorDate
|
|
60
|
+
* @property {string} 0=greater
|
|
61
|
+
* @property {string} 1=iso
|
|
62
|
+
* @property {string} 2=less
|
|
63
|
+
* @property {string} 2=max
|
|
64
|
+
* @property {string} 2=min
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @typedef {string[]} TValidatorTimestamp
|
|
69
|
+
* @property {string} 0=timestamp
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {Object} TValidator
|
|
74
|
+
* @property {TValidatorString} string
|
|
75
|
+
* @property {TValidatorNumber} number
|
|
76
|
+
* @property {TValidatorBoolean} boolean
|
|
77
|
+
* @property {TValidatorDate} date
|
|
78
|
+
* @property {TValidatorTimestamp} timestamp
|
|
79
|
+
*/
|
|
6
80
|
const validator = {
|
|
7
81
|
string: ['alphanum', 'base64', 'case', 'creditCard', 'dataUri', 'domain', 'email', 'guid',
|
|
8
82
|
'uuid', 'hex', 'hostname', 'insensitive', 'ip', 'isoDate', 'isoDuration', 'length', 'lowercase',
|
|
@@ -20,9 +94,9 @@ function buildFromDbSchema (schema, { fields = [], rule = {}, extFields = [] } =
|
|
|
20
94
|
const {
|
|
21
95
|
isPlainObject, get, each, isEmpty, isString, forOwn, keys,
|
|
22
96
|
find, isArray, has, cloneDeep, concat, without
|
|
23
|
-
} = this.lib._
|
|
97
|
+
} = this.app.lib._
|
|
24
98
|
const obj = {}
|
|
25
|
-
const
|
|
99
|
+
const { propType } = this.app.pluginClass.dobo
|
|
26
100
|
const refs = []
|
|
27
101
|
|
|
28
102
|
function getRuleKv (kvRule) {
|
|
@@ -44,7 +118,7 @@ function buildFromDbSchema (schema, { fields = [], rule = {}, extFields = [] } =
|
|
|
44
118
|
const rules = get(rule, prop.name, prop.rules ?? [])
|
|
45
119
|
if (!isArray(rules)) return rules
|
|
46
120
|
each(rules, r => {
|
|
47
|
-
const types = validator[
|
|
121
|
+
const types = validator[propType[prop.type].validator]
|
|
48
122
|
const { key, value } = getRuleKv(r)
|
|
49
123
|
if (keys(minMax).includes(key)) minMax[key] = true
|
|
50
124
|
if (key === 'ref') {
|
|
@@ -110,7 +184,7 @@ function buildFromDbSchema (schema, { fields = [], rule = {}, extFields = [] } =
|
|
|
110
184
|
each(without(keys(obj), ...refs), k => {
|
|
111
185
|
const prop = find(props, { name: k })
|
|
112
186
|
if (!prop) return undefined
|
|
113
|
-
const types = validator[
|
|
187
|
+
const types = validator[propType[prop.type].validator]
|
|
114
188
|
const { key, value, columns = [] } = getRuleKv(r)
|
|
115
189
|
if (!types.includes(key)) return undefined
|
|
116
190
|
if (columns.length === 0 || columns.includes(k)) obj[k] = obj[k][key](value)
|
|
@@ -125,11 +199,26 @@ function buildFromDbSchema (schema, { fields = [], rule = {}, extFields = [] } =
|
|
|
125
199
|
return result
|
|
126
200
|
}
|
|
127
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Validate value against JOI schema
|
|
204
|
+
*
|
|
205
|
+
* @method
|
|
206
|
+
* @memberof Dobo
|
|
207
|
+
* @async
|
|
208
|
+
* @param {Object} value - value to validate
|
|
209
|
+
* @param {Object} joiSchema - JOI schema
|
|
210
|
+
* @param {Object} [options={}] - Options object
|
|
211
|
+
* @param {string} [options.ns=dobo] - Scope's namespace
|
|
212
|
+
* @param {Array} [options.fields=[]]
|
|
213
|
+
* @param {Array} [options.extFields=[]]
|
|
214
|
+
* @param {Object} [options.params={}] - Validation parameters. See {@tutorial config} and {@link https://joi.dev/api/?v=17.13.3#anyvalidateasyncvalue-options|JOI validate's options}
|
|
215
|
+
* @returns {Object}
|
|
216
|
+
*/
|
|
128
217
|
async function validate (value, joiSchema, { ns, fields, extFields, params } = {}) {
|
|
129
|
-
const { defaultsDeep, isSet } = this.lib.aneka
|
|
130
|
-
const { isString, forOwn, find } = this.lib._
|
|
218
|
+
const { defaultsDeep, isSet } = this.app.lib.aneka
|
|
219
|
+
const { isString, forOwn, find } = this.app.lib._
|
|
131
220
|
|
|
132
|
-
ns = ns ?? [this.
|
|
221
|
+
ns = ns ?? [this.ns]
|
|
133
222
|
params = defaultsDeep(params, this.config.validationParams)
|
|
134
223
|
const { rule = {} } = params
|
|
135
224
|
delete params.rule
|
package/package.json
CHANGED
|
@@ -1,36 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dobo",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dobo",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "DBMS for Bajo Framework",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build-doc": "jsdoc -c .jsdoc.conf.json",
|
|
8
|
+
"test": "mocha"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bajo": {
|
|
12
|
+
"type": "plugin"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/ardhi/dobo.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"database",
|
|
20
|
+
"dobo",
|
|
21
|
+
"db",
|
|
22
|
+
"orm",
|
|
23
|
+
"bajo",
|
|
24
|
+
"framework"
|
|
25
|
+
],
|
|
26
|
+
"author": "Ardhi Lukianto <ardhi@lukianto.com>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/ardhi/dobo/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/ardhi/dobo#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@tryghost/nql": "^0.12.7",
|
|
34
|
+
"joi": "^17.13.3",
|
|
35
|
+
"mingo": "^6.5.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"clean-jsdoc-theme": "^4.3.0",
|
|
39
|
+
"jsdoc-plugin-intersection": "^1.0.4"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/wiki/APPLETS.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Applet
|
|
2
|
+
|
|
3
|
+
## connection
|
|
4
|
+
|
|
5
|
+
Gunakan applet ini untuk menampilkan koneksi database yang Anda miliki
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
$ node index.js -a dobo:connection # Masuk ke mode interaktif
|
|
9
|
+
$ node index.js -a dobo:connection default # Tampilkan koneksi dengan nama 'default'
|
|
10
|
+
$ node index.js -a dobo:connection default --format=json # Tampilkan dalam format 'json'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## modelClear
|
|
14
|
+
|
|
15
|
+
Hapus tabel yang Anda inginkan. **Perhatian**: tabel akan dihapus dari database BESERTA isinya. Jadi pastikan bahwa Anda telah membackup tabel Anda terlebih dahulu sebelum Anda memanggil applet ini.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
$ node index.js -a dobo:modelRebuild # Masuk ke mode interaktif
|
|
19
|
+
$ node index.js -a dobo:modelRebuild 'Cdb*' # Hapus model dengan awalan 'Cdb'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## modelRebuild
|
|
23
|
+
|
|
24
|
+
Pada saat pertama kali sebuah plugin dimuat dan plugin meng-extend Dobo, Anda perlu memanggil applet ini untuk membuat tabel sesuai dengan skema yang telah ditentukan.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
$ node index.js -a dobo:modelRebuild # Gunakan mode interaktif
|
|
28
|
+
$ node index.js -a dobo:modelRebuild CdbCountry Sumba # Masukkan satu persatu nama modelnya
|
|
29
|
+
$ node index.js -a dobo:modelRebuild 'Cdb*' # List semua model dengan awalan 'Cdb'
|
|
30
|
+
```
|
|
31
|
+
Setelah tabel sukses dibuat, maka jika model dilengkapi dengan fixture, fixture tersebut akan dimuat didalam tabel yang bersangkutan.
|
|
32
|
+
|
|
33
|
+
Jika tabel telah ada di database, Anda harus menggunakan switch ```--force``` untuk memaksa model bisa di hapus kemudian dibuat ulang kembali.
|
|
34
|
+
|
|
35
|
+
## recordCreate
|
|
36
|
+
|
|
37
|
+
Gunakan applet ini untuk membuat rekord:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
$ node index.js -a dobo:recordCreate CdbCountry
|
|
41
|
+
ℹ App is running as applet...
|
|
42
|
+
✔ Enter JSON payload: { "id": "XX", "name": "My Country" }
|
|
43
|
+
╭ CdbCountry ─────────────╮
|
|
44
|
+
│ { │
|
|
45
|
+
│ "id": "XX", │
|
|
46
|
+
│ "name": "My Country" │
|
|
47
|
+
│ } │
|
|
48
|
+
╰─────────────────────────╯
|
|
49
|
+
? Are you sure to continue? (y/N)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## recordFind
|
|
53
|
+
|
|
54
|
+
Mencari rekord yang sesuai dengan kriteria pemilihan Anda. Jika kriteria tidak dimasukkan (filter kosong), maka akan diberikan semua rekord yang ada.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
|
package/wiki/CONFIG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Config Object
|
|
2
|
+
|
|
3
|
+
| Key Name | Type | Default | Description |
|
|
4
|
+
| ------- | ---- | ----- | ----------- |
|
|
5
|
+
| ```connections``` | ```array``` | ```[]``` | Connection object |
|
|
6
|
+
| ```validationParams``` | ```object``` | | Defaults to [Joi validate's](https://joi.dev/api/?v=17.13.3#anyvalidateasyncvalue-options) options |
|
|
7
|
+
| ```abortEarly``` | ```boolean``` | ```false``` | |
|
|
8
|
+
| ```convert``` | ```boolean``` | ```false``` | |
|
|
9
|
+
| ```allowUnknown``` | ```boolean``` | ```true``` | |
|
|
10
|
+
| ```default``` | ```object``` | | default values |
|
|
11
|
+
| ```property``` | ```object``` | | |
|
|
12
|
+
| ```text``` | ```object``` | | |
|
|
13
|
+
| ```textType``` | ```string``` | ```text``` | Allowed values: ```text```, ```mediumtext```, or ```longtext``` |
|
|
14
|
+
| ```string``` | ```object``` | | |
|
|
15
|
+
| ```length``` | ```number``` | ```50``` | |
|
|
16
|
+
| ```filter``` | ```object``` | | |
|
|
17
|
+
| ```limit``` | ```number``` | ```25``` | Rows returned in one page |
|
|
18
|
+
| ```maxLimit``` | ```number``` | ```200``` | Max rows returned in one page |
|
|
19
|
+
| ```hardLimit``` | ```number``` | ```10000``` | Max rows returned on dataset export |
|
|
20
|
+
| ```sort``` | ```array``` | | |
|
|
21
|
+
| ```idField``` | ```object``` | | |
|
|
22
|
+
| ```memDb``` | ```object``` | | |
|
|
23
|
+
| ```createDefConnAtStart``` | ```boolean``` | ```true``` | |
|
|
24
|
+
| ```persistence``` | ```object``` | | |
|
|
25
|
+
| ```syncPeriodDur``` | ```string | number``` | ```1s``` | |
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks very much to everyone who wants to join as a contributor, but I have committed to devoting 100% of my time to this project. Therefore, I'm currently unable to accept pull requests from anyone until the project is large enough for me to manage it independently.
|
|
4
|
+
|
|
5
|
+
However, I am available if you encounter any bugs that require immediate fixes. Please report your issues in a GitHub issue, and I'll try to address them promptly. I'm also open to criticism and suggestions for improvements or requests for new features.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Developer Guide
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Ecosystem
|
|
2
|
+
|
|
3
|
+
## Drivers
|
|
4
|
+
|
|
5
|
+
| Package | Docs | NS | Alias | Description |
|
|
6
|
+
| ------- | ---- | -- | ----- | ----------- |
|
|
7
|
+
| [dobo-couchdb](https://github.com/ardhi/dobo-couchdb) | [Docs](https://ardhi.github.io/dobo-couchdb) | doboCouchdb | dbcouch | CouchDB Driver |
|
|
8
|
+
| [dobo-elasticsearch](https://github.com/ardhi/dobo-elasticsearch) | [Docs](https://ardhi.github.io/dobo-elasticsearch) | doboElasticsearch | dbes | Elasticsearch Driver |
|
|
9
|
+
| [dobo-knex](https://github.com/ardhi/dobo-knex) | [Docs](https://ardhi.github.io/dobo-knex) | doboKnex | dbknex | Knex/SQL Driver |
|
|
10
|
+
| [dobo-mongodb](https://github.com/ardhi/dobo-mongodb) | [Docs](https://ardhi.github.io/dobo-mongodb) | doboMongodb | dbmongo | MongoDB Driver |
|
|
11
|
+
| [dobo-redis](https://github.com/ardhi/dobo-redis) | [Docs](https://ardhi.github.io/dobo-redis) | doboRedis | dbredis | Redis Driver |
|
|
12
|
+
| [dobo-restproxy](https://github.com/ardhi/dobo-restproxy) | [Docs](https://ardhi.github.io/dobo-restproxy) | doboRestproxy | dbrpx | Restproxy Driver |
|
|
13
|
+
| [dobo-restproxy-jsonserver](https://github.com/ardhi/dobo-restproxy-jsonserver) | [Docs](https://ardhi.github.io/dobo-restproxy-jsonserver) | doboResporoxyJsonserver | dbrpxjs |JsonServer Support for doboRestproxy |
|
|
14
|
+
| [dobo-restproxy-ndut](https://github.com/ardhi/dobo-restproxy-ndut) | [Docs](https://ardhi.github.io/dobo-restproxy-ndut) | doboRestproxyNdut | dbrpxndut | NDUT Support for doboRestproxy |
|
|
15
|
+
|
|
16
|
+
## Misc
|
|
17
|
+
|
|
18
|
+
| Package | Docs | NS | Alias | Description |
|
|
19
|
+
| ------- | ---- | -- | ----- | ----------- |
|
|
20
|
+
| [dobo-extra](https://github.com/ardhi/dobo-extra) | [Docs](https://ardhi.github.io/dobo-extra) | doboExtra | dbx | Dobo Extra Tools/Utility |
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
> If you're new to the [Dobo DBMS](https://ardhi.github.io/dobo), we recommend you to read and follow along with [Bajo Tutorial](https://ardhi.github.io/bajo/tutorial-01-getting-started.html) first, as this document is the continuation of it
|
|
4
|
+
|
|
5
|
+
**Dobo** is the Bajo sub-framework developed specifically to handle database management. In this tutorial, we'll go over how to install the necessary packages and interact with them.
|
|
6
|
+
|
|
7
|
+
Here is some basic knowledge about Dobo you need to be familiar with:
|
|
8
|
+
|
|
9
|
+
- All record-related actions mimic REST API methods: *find* records, *get* a particular record by its ID, *create* a new record, *update* an existing record by ID and payload, and *remove* an existing record by its ID.
|
|
10
|
+
- A Dobo model requires a predefined schema. Even if you use a NoSQL database, you still need to write a schema.
|
|
11
|
+
- There are two main groups of methods to be familiar with:
|
|
12
|
+
- ```dobo.model{Action}``` methods manage everything related to model management, such as table creation or deletion.
|
|
13
|
+
- ```dobo.record{Action}``` methods handle record manipulation.
|
|
14
|
+
- A record in Bajo always needs to have an ID. The ID can be alphanumeric characters or an integer, and it is defined by the underlying driver used by the model.
|
|
15
|
+
|
|
16
|
+
For more info about Dobo, please [click here](https://ardhi.github.io/dobo).
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
|
|
20
|
+
As you might have guessed, Dobo and its drivers are normal Bajo plugins. Although [many drivers](https://github.com/ardhi/dobo/tutorials/drivers.md) exist, for this tutorial, we'll only use SQLite 3, which is provided by the dobo-knex driver.
|
|
21
|
+
|
|
22
|
+
Now, please install the required plugins and SQLite drivers first:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
$ npm install dobo dobo-knex sqlite3
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Don't forget to add ```dobo``` and ```dobo-knex``` to the ```data/config/.plugins``` file.
|
|
29
|
+
|
|
30
|
+
### Model
|
|
31
|
+
|
|
32
|
+
Let's pretend we're building an address book with fields like name, age, phone, etc. This entity needs to be modeled with a schema and then "connected" to a database:
|
|
33
|
+
|
|
34
|
+
1. Create ```main/extend/dobo/schema/address-book.json``` file.
|
|
35
|
+
2. Enter the following schema:
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"properties": [{
|
|
39
|
+
"name": "firstName",
|
|
40
|
+
"type": "string",
|
|
41
|
+
"maxLength": 20,
|
|
42
|
+
"required": true,
|
|
43
|
+
"index": true
|
|
44
|
+
},
|
|
45
|
+
"lastName::20:true:true",
|
|
46
|
+
"age:smallint",
|
|
47
|
+
"phone::20:true:true",
|
|
48
|
+
"email::50:true"
|
|
49
|
+
],
|
|
50
|
+
"feature": {
|
|
51
|
+
"createdAt": true,
|
|
52
|
+
"updatedAt": true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
You should notice here that in properties you can use either the verbose, full-object syntax or the string-based one. Please visit the Dobo documentation to learn more.
|
|
57
|
+
|
|
58
|
+
3. Create ```main/extend/dobo/fixture/address-book.json``` file. Fixtures allow you to quickly fill your database with predefined records. It's not required, but it helps a lot with prototyping.
|
|
59
|
+
```json
|
|
60
|
+
[{
|
|
61
|
+
"firstName": "James",
|
|
62
|
+
"lastName": "Bond",
|
|
63
|
+
"phone": "+44-007"
|
|
64
|
+
}, {
|
|
65
|
+
"firstName": "Felix",
|
|
66
|
+
"lastName": "Leiter",
|
|
67
|
+
"age": 50,
|
|
68
|
+
"phone": "+1-0000001"
|
|
69
|
+
}]
|
|
70
|
+
```
|
|
71
|
+
4. By default, all schemas are connected to a database connection named ```default```. Now let's create this connection by creating ```data/config/dobo.json``` file:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"connections": [{
|
|
76
|
+
"name": "default",
|
|
77
|
+
"type": "knex:sqlite3",
|
|
78
|
+
"connection": {
|
|
79
|
+
"filename": "my-project.sqlite3"
|
|
80
|
+
}
|
|
81
|
+
}]
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
5. That's all there is to it. Now you need to build this model like this:
|
|
85
|
+
```
|
|
86
|
+
$ node index.js -a dobo:modelRebuild MainAddressBook
|
|
87
|
+
ℹ App runs in applet mode
|
|
88
|
+
╭ Schema (1) ──────╮
|
|
89
|
+
│ MainAddressBook │
|
|
90
|
+
╰──────────────────╯
|
|
91
|
+
✔ The above mentioned schema(s) will be rebuilt as model. Continue? Yes
|
|
92
|
+
✔ Model 'MainAddressBook' successfully created
|
|
93
|
+
ℹ Done! Succeded: 1, failed: 0, skipped: 0
|
|
94
|
+
✔ Fixture on 'MainAddressBook': added 2, rejected: 0
|
|
95
|
+
```
|
|
96
|
+
6. Done!
|
|
97
|
+
|
|
98
|
+
Note: Although you can use YAML or TOML for schemas/fixtures, it's recommended to stick with JSON because it's always supported and doesn't require an extra plugin.
|
|
99
|
+
|
|
100
|
+
Dobo models are by default always named with ```{Alias}{ModelName}```, which is a pascal-cased plugin alias and base name from your schema file. For field names, Dobo use camel-cased names as a convention. You can change this behavior to match your needs, but it is suggested that you're keeping these conventions at least for this tutorial.
|
|
101
|
+
|
|
102
|
+
### Applets
|
|
103
|
+
|
|
104
|
+
Dobo provides you with a number of applets that will help you manipulate models and records directly. This means you don't have to touch your tables and databases directly through SQL statements or NoSQL procedures ever again. Everything can be managed through one common syntax provided by Dobo, regardless of your backend type.
|
|
105
|
+
|
|
106
|
+
First, let's try to list records:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
$ node index.js -a dobo:recordFind MainAddressBook
|
|
110
|
+
ℹ App runs in applet mode
|
|
111
|
+
✔ Please enter your query (if any):
|
|
112
|
+
✔ Done
|
|
113
|
+
┌────┬───────────┬──────────┬─────┬────────────┬───────┬──────────────────────────┬──────────────────────────┐
|
|
114
|
+
│ id │ firstName │ lastName │ age │ phone │ email │ createdAt │ updatedAt │
|
|
115
|
+
├────┼───────────┼──────────┼─────┼────────────┼───────┼──────────────────────────┼──────────────────────────┤
|
|
116
|
+
│ 2 │ Felix │ Leiter │ 50 │ +1-0000001 │ │ 2025-09-18T13:47:29.296Z │ 2025-09-18T13:47:29.296Z │
|
|
117
|
+
├────┼───────────┼──────────┼─────┼────────────┼───────┼──────────────────────────┼──────────────────────────┤
|
|
118
|
+
│ 1 │ James │ Bond │ │ +44-007 │ │ 2025-09-18T13:47:29.280Z │ 2025-09-18T13:47:29.280Z │
|
|
119
|
+
└────┴───────────┴──────────┴─────┴────────────┴───────┴──────────────────────────┴──────────────────────────┘
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Now, add a new record:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
$ node index.js -a dobo:recordCreate MainAddressBook
|
|
126
|
+
ℹ App runs in applet mode
|
|
127
|
+
✔ Enter JSON payload: { "firstName": "Miss", "lastName": "Moneypenny" }
|
|
128
|
+
╭ MainAddressBook ────────────╮
|
|
129
|
+
│ { │
|
|
130
|
+
│ "firstName": "Miss", │
|
|
131
|
+
│ "lastName": "Moneypenny" │
|
|
132
|
+
│ } │
|
|
133
|
+
╰─────────────────────────────╯
|
|
134
|
+
✖ Error: Validation Error
|
|
135
|
+
✔ Enter JSON payload: { "firstName": "Miss", "lastName": "Moneypenny", "phone": "+44-111" }
|
|
136
|
+
╭ MainAddressBook ─────────────╮
|
|
137
|
+
│ { │
|
|
138
|
+
│ "firstName": "Miss", │
|
|
139
|
+
│ "lastName": "Moneypenny", │
|
|
140
|
+
│ "phone": "+44-111" │
|
|
141
|
+
│ } │
|
|
142
|
+
╰──────────────────────────────╯
|
|
143
|
+
✔ Done
|
|
144
|
+
┌───────────┬──────────────────────────┐
|
|
145
|
+
│ id │ 3 │
|
|
146
|
+
├───────────┼──────────────────────────┤
|
|
147
|
+
│ firstName │ Miss │
|
|
148
|
+
├───────────┼──────────────────────────┤
|
|
149
|
+
│ lastName │ Moneypenny │
|
|
150
|
+
├───────────┼──────────────────────────┤
|
|
151
|
+
│ age │ │
|
|
152
|
+
├───────────┼──────────────────────────┤
|
|
153
|
+
│ phone │ +44-111 │
|
|
154
|
+
├───────────┼──────────────────────────┤
|
|
155
|
+
│ email │ │
|
|
156
|
+
├───────────┼──────────────────────────┤
|
|
157
|
+
│ createdAt │ 2025-09-18T14:38:11.933Z │
|
|
158
|
+
├───────────┼──────────────────────────┤
|
|
159
|
+
│ updatedAt │ 2025-09-18T14:38:11.933Z │
|
|
160
|
+
└───────────┴──────────────────────────┘
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
As you can see, Dobo is smart enough to reject any payload that isn't right. In this case, we forgot to include the phone number since according to the schema, this field is defined as required.
|
|
164
|
+
|
|
165
|
+
You can now try all of Dobo's other applets. [This page](https://github.com/ardhi/dobo/tutorials/applets) provides its complete list.
|
|
166
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# User Guide
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const conns = []
|
|
2
|
-
|
|
3
|
-
async function postProcess ({ handler, params, path, processMsg, noConfirmation } = {}) {
|
|
4
|
-
const { saveAsDownload, importPkg } = this.app.bajo
|
|
5
|
-
const { prettyPrint } = this.app.bajoCli.helper
|
|
6
|
-
const { find, get } = this.lib._
|
|
7
|
-
const [stripAnsi, confirm] = await importPkg('bajoCli:strip-ansi', 'bajoCli:@inquirer/confirm')
|
|
8
|
-
if (!noConfirmation && this.config.confirmation === false) noConfirmation = true
|
|
9
|
-
params.push({ fields: this.config.fields, dataOnly: !this.config.full })
|
|
10
|
-
|
|
11
|
-
const schema = find(this.schemas, { name: params[0] })
|
|
12
|
-
if (!schema) return this.print.fatal('notFound%s', this.print.write('field.schema'))
|
|
13
|
-
let cont = true
|
|
14
|
-
if (!noConfirmation) {
|
|
15
|
-
const answer = await confirm({ message: this.print.write('sureContinue'), default: false })
|
|
16
|
-
if (!answer) {
|
|
17
|
-
this.print.fail('aborted')
|
|
18
|
-
cont = false
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (!cont) return
|
|
22
|
-
const spin = this.print.spinner().start(`${processMsg}...`)
|
|
23
|
-
const { connection } = this.getInfo(schema)
|
|
24
|
-
if (!conns.includes(connection.name)) {
|
|
25
|
-
await this.start(connection.name)
|
|
26
|
-
conns.push(connection.name)
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
const resp = await this[handler](...params)
|
|
30
|
-
spin.succeed('done')
|
|
31
|
-
const result = this.config.pretty ? (await prettyPrint(resp)) : JSON.stringify(resp, null, 2)
|
|
32
|
-
if (this.config.save) {
|
|
33
|
-
const id = resp.id ?? get(resp, 'data.id') ?? get(resp, 'oldData.id')
|
|
34
|
-
const base = path === 'recordFind' ? params[0] : (params[0] + '/' + id)
|
|
35
|
-
const file = `/${path}/${base}.${this.config.pretty ? 'txt' : 'json'}`
|
|
36
|
-
await saveAsDownload(file, stripAnsi(result))
|
|
37
|
-
} else console.log(result)
|
|
38
|
-
} catch (err) {
|
|
39
|
-
if (this.config.log.applet) {
|
|
40
|
-
spin.stop()
|
|
41
|
-
console.error(err)
|
|
42
|
-
} else spin.fail('error%s', err.message)
|
|
43
|
-
}
|
|
44
|
-
process.exit()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default postProcess
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import postProcess from './lib/post-process.js'
|
|
2
|
-
|
|
3
|
-
async function modelClear (...args) {
|
|
4
|
-
const { print } = this.app.bajo
|
|
5
|
-
const { isEmpty } = this.lib._
|
|
6
|
-
if (isEmpty(this.schemas)) return print.fail('notFound%s', 'schema', { exit: this.app.bajo.applet })
|
|
7
|
-
const [schema] = args
|
|
8
|
-
await postProcess.call(this, { handler: 'modelClear', params: [schema], path: 'modelClear', processMsg: 'Clear records' })
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default modelClear
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import resolveMethod from '../../lib/resolve-method.js'
|
|
2
|
-
|
|
3
|
-
async function create (name, options = {}) {
|
|
4
|
-
const { runHook } = this.app.bajo
|
|
5
|
-
const { camelCase } = this.lib._
|
|
6
|
-
|
|
7
|
-
const { handler, schema, driver } = await resolveMethod.call(this, name, 'model-create', options)
|
|
8
|
-
if (!options.noHook) {
|
|
9
|
-
await runHook(`${this.name}:beforeModelCreate`, schema, options)
|
|
10
|
-
await runHook(`${this.name}.${camelCase(name)}:beforeModelCreate`, options)
|
|
11
|
-
}
|
|
12
|
-
await handler.call(this.app[driver.ns], { schema, options })
|
|
13
|
-
if (!options.noHook) {
|
|
14
|
-
await runHook(`${this.name}.${camelCase(name)}:afterModelCreate`, options)
|
|
15
|
-
await runHook(`${this.name}:afterModelCreate`, schema, options)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default create
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import resolveMethod from '../../lib/resolve-method.js'
|
|
2
|
-
|
|
3
|
-
async function drop (name, options = {}) {
|
|
4
|
-
const { runHook } = this.app.bajo
|
|
5
|
-
const { camelCase } = this.lib._
|
|
6
|
-
const { handler, schema, driver } = await resolveMethod.call(this, name, 'model-drop', options)
|
|
7
|
-
|
|
8
|
-
if (!options.noHook) {
|
|
9
|
-
await runHook(`${this.name}:beforeModelDrop`, schema, options)
|
|
10
|
-
await runHook(`${this.name}.${camelCase(name)}:beforeModelDrop`, options)
|
|
11
|
-
}
|
|
12
|
-
await handler.call(this.app[driver.ns], { schema, options })
|
|
13
|
-
if (!options.noHook) {
|
|
14
|
-
await runHook(`${this.name}.${camelCase(name)}:afterModelDrop`, options)
|
|
15
|
-
await runHook(`${this.name}:afterModelDrop`, schema, options)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default drop
|