@norjs/database-service
v1.0.10
Published
NorJS Database Service
Downloads
1
Maintainers
Readme
@norjs/database-service
JSDoc-configurable database service over UNIX socket file
Design
This is a simple document database service implementing a REST interface to a data over a UNIX socket file.
The data can be defined using JSDoc-style configuration files and our TypeUtils.
Usage
First define your custom data objects in a file named ./types.js
:
const TypeUtils = require('@norjs/utils/Type');
/**
* @typedef {Object} MyResourceItemDTO
* @property {number} id - My resource id
* @property {string} name - My resource name
*/
TypeUtils.defineType(
"MyResourceItemDTO",
{
"id": "number",
"name": "string"
}
);
/**
* @typedef {Object} MyResourceDTO
* @property {number} id - My resource id
* @property {string} name - My resource name
* @property {boolean} deleted - Deleted or not?
* @property {Array.<MyResourceItemDTO>} items - My items
*/
TypeUtils.defineType(
"MyResourceDTO",
{
"id": "number",
"name": "string",
"deleted": "boolean",
"items": "Array.<MyResourceItemDTO>"
}
);
Start the service:
NOR_DATABASE_LOAD_TYPES='./types.js' \
NOR_DATABASE_RESOURCES=MyResourceDTO \
NOR_DATABASE_STORE='./my-resource-dir' \
NODE_LISTEN=./socket.sock \
npm start
Using the service
See @norjs/database about using the service.