@sophia-iot/database-adapter v0.25.0
- Sophia database adapter
Since we use moleculer we could easily add one of a few different database mixins to provide restful access to the different databases on offer.
However, I'd like to lock down any unauthorised requests to the database and have so created a database adapter system by which we can leverage the best of the mixin system with the security of the single database access model.
** Usage
~npm i --save @sophia-iot/database-adapter~
#+BEGIN_SRC javascript const getDatabase = require('@sophia-iot/database-adapter');
const database = getDatabase();
console.log(await database.get(id)); #+END_SRC
** Adapters exist for
- RethinkDB
- NeDB
** Database access
In the Sophia project, the database should ONLY be accessed through one of these database adapters. This prevents unusual reliance on any one specific feature of a database set.
If and when the microservice requires a different database architecture in order to perform more efficiently in it's task set, this adapter makes it a simple task to switch to the preffered model.
** Writing an adapter
Please include your adapter in the adapters folder, and link it into the index file there.
*** Requirements
Your database adapter must include the following functions:
- ~get(id)~ Returns: new promise which resolves to the item. Throws: NotFound error if the item does not exist
- ~remove(id)~ Returns: new promise which resolves to the number of items removed. Throws: NotFound error if the item does not exist
- ~insert(item = {})~ Returns: new promise which resolves to the item added (with ID).
- ~list(filters = {})~ Returns: new promise which resolves to an array of matching items
- ~connect(params = {})~ Returns: New promise which resolves when we are connected
- ~update(id, changes = {})~ Returns: New promise with the number of items changed
- ~findOne(filters = {})~ Returns: New promise with the item which matches filters (if any)
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago