-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c593af5
commit e5c7f02
Showing
4 changed files
with
62 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Database plugins | ||
|
||
Coming soon, but if you want do this now, you can try to understand [dc-api-mysql] and [dc-api-mongo] plugins | ||
|
||
[dc-api-mysql]: https://github.com/DimaCrafter/dc-api-mysql | ||
[dc-api-mongo]: https://github.com/DimaCrafter/dc-api-mongo | ||
|
||
## Sketch of documentation | ||
|
||
This pseudo-code created to show how this works. I don't know how make mornal documentation of this. | ||
|
||
```js | ||
const NativeDB = require('cooldb-native'); | ||
const EventEmitter = require('events'); | ||
const ROOT = process.cwd(); | ||
|
||
class MyCoolDB extends EventEmitter { | ||
constructor (conf, confName) { | ||
super(); | ||
NativeDB.connect(conf, err => this.emit('connected', err)); | ||
this.confName = confName; | ||
} | ||
|
||
getModel (name) { | ||
try { | ||
var schemaRaw = {...require(`${ROOT}/models/${this.confName}/${name}.js`)}; | ||
} catch { | ||
this.emit('no-model', name); | ||
return; | ||
} | ||
return NativeDB.getModelFromSchema(schemaRaw); | ||
} | ||
} | ||
|
||
module.exports = core => core.register('db', MyCoolDB, 'mycooldb'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters