Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/siarheidudko/docdb
LOG-based JavaScript Database
https://github.com/siarheidudko/docdb
Last synced: about 16 hours ago
JSON representation
LOG-based JavaScript Database
- Host: GitHub
- URL: https://github.com/siarheidudko/docdb
- Owner: siarheidudko
- License: apache-2.0
- Created: 2019-08-23T13:11:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-09T14:05:31.000Z (almost 5 years ago)
- Last Synced: 2024-10-12T23:08:05.599Z (26 days ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DocDBLOG-based JavaScript DataBase (based on streaming processing).
The API will be significantly changed.## Install
```
npm i docdb --save
```
## Use
```
const DATASTORE = require('docdb');
let DataBase = new DATASTORE({dbname:'_test'});
DataBase.then(function(db){
//warning stream
db.on('data', function(buffer){
console.log(buffer);
});
//find documents from database (if you use the _id key, the search is performed by index)
db.findMany({..filter documents fields type of Object}, [..document fields returned type of Array]).then(function(arr){
//query result type of Array
console.log(arr);
});
//insert (or update if exists) one document from database
db.insertOne({..insert document type of Object}).then(function(_id){
console.log(arr);
});
//remove one document from database
db.removeOne({_id: first key document type of String}).then(function(_id){
console.log(arr);
});
//backup database files
db.service.toBackup().then(function(){
});
//restore database files from backup
db.service.fromBackup().then(function(){
});
//recovery index file
db.service.recovery().then(function(){
});
//index file compression
db.service.compact().then(function(){
});
//data file compression
db.service.compact("log").then(function(){
});
});
```## EXAMPLE
```
const DATASTORE = require('docdb');
let DataBase = new DATASTORE({dbname:'test'});
DataBase.then(function(db){
//warning stream
db.on('data', function(buffer){
console.log(buffer);
});
//insert (or update if exists) one document from database
db.insertOne({_id: "sdasdasdas", text:"test", data: Date.now()}).then(function(_id){
console.log(_id);
return new Promise(function(res, rej){ //find documents from database (if you use the _id key, the search is performed by index)
setTimeout(function(){
db.findMany({_id: "sdasdasdas"}, ["_id", "text"]).then(res).catch(rej);
}, 100);
});
}).then(function(arr){
//query result
console.log(arr);
return db.removeOne({_id: "sdasdasdas"}); //remove one document from database
}).then(function(_id){
console.log(_id);
return new Promise(function(res, rej){ //find documents from database (if you use the _id key, the search is performed by index)
setTimeout(function(){
db.findMany({_id: "sdasdasdas"}, ["_id", "text"]).then(res).catch(rej);
}, 100);
});
}).then(function(arr){
console.log(arr);
return db.service.toBackup();//backup database files
}).then(function(bool){
console.log(bool);
return db.service.fromBackup();//restore database files from backup
}).then(function(bool){
console.log(bool);
return db.service.recovery();//recovery index file
}).then(function(bool){
console.log(bool);
return db.service.compact();//index file compression
}).then(function(){
return db.service.compact("log");//data file compression
}).then(function(){
console.log('Test complete!');
}).catch(function(err){
console.log('Test interrupted, with error:', err);
});
});
```## EXAMPLE CONSOLE
```
let READLINE = require('readline'),
DATASTORE = require('docdb');
let DataBase = new DATASTORE({dbname:'test'});DataBase.then(function(db){
db.on('data', function(buffer){
console.log(buffer);
});
const rl = READLINE.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'DocDB> '
});
rl.prompt();
rl.on('line', (line) => {
try{
let _tmp = eval(line);
if(typeof(_tmp) !== 'undefined'){
console.log(_tmp);
}
} catch(err) {
console.error("Ошибка команды: "+err);
}
rl.prompt();
}).on('close', () => {
console.log('DocDB disconnected!');
process.exit(0);
});
});
```
## LICENSE
Apache-2.0