orchidb
v4.2.3
Published
A lightweight, JSON-Document-Oriented database managment module for node.js
Downloads
25
Maintainers
Readme
OrchiDB
OrchiDB is an Open-Source, JSON Document-Oriented database managment system with an emphasis on simple syntax and easy setup. OrchiDB can take queries using JavaScript code using the OrchiDB module or even through text based input through the built in terminal.
For the source code and update logs for OrchiDB vist the GitHub repository here.
Setup
To get started with OrchiDB, first download the npm module.
npm i orchidb
then import it to the js file you want to use it in.
const db = require('orchidb');
//or with ES6 modules
import db from 'orchidb'
Creating Collections
Collections are the basic unit of storage for OrchiDB, each collection can contain documents, a TRASH folder, and even other collections.
To create a collection use the db.Collection
constructor, then input the path to your collection relative to the location of the main js file and the name of the collection.
const myCollection = new db.Collection('./OrchiDB', 'myCollection');
Then from their you can call the many methods included in the Collection
class.
Collection Methods
Terminal
The integrated OrchiDB terminal can be run via the terminal.run()
method included in the collection which you want to read or write data to.
myCollection.terminal.run() //Opens the terminal for the collection 'myCollection'
| Commands | |----------| |exit | |insert | |get | |update | |del | |restore | |empty_trash| |rename | |get_path | |copy_col | |del_col | |clear | |del_var | |find | |get_var | |help |
JavaScript Methods
insert(docName: string, data: obj)
| Creates a new documentget(docName: string)
| Returns the value of the input document, optionally logs value to consoleupdate(docName: string, data: obj)
| Adds or overwrites variables from document with input datadelete(docName: string)
| Moves document to collection's trash foldergetPath(docName: string)
| Returns the path to the documentrestore(docName: string)
| Moves document from trash to collection folder properrename(docName: string, newDocName: string)
| Renames documentemptyTrash()
| Permanently deletes all documents from trash folderoverwrite(docName: string, data: obj)
| Overwrites all data in document to the data inputedcopyCol(targetCollection: string)
| Copies all documents and collections to the target collectioncopyDocToCol(docName: string, targetCollection: string)
| Copies specified document to targetColdeleteCol()
| Deletes directory to collection and every file/folder inside of itfind(inputProperties: obj)
| Returns all documents with specified input properties, if no properties specified then it will return all documents in the collectiongetVar(docName: string, variables: arr)
| Returns the values for the variables specifieddeleteVar(docName: string, variables: arr)
| Deletes all variables specified
All methods contain a logToConsole parameter as the last parameter of the function. By default this is set as false but if you want to log the results of a function then you can by setting the parameter to true. Additionally the Collection constructor method also has the logToConsole parameter.
Example Program
const db = require('orchidb');
const myCollection = new db.Collection('', 'myCollection');
const myCollection2 = new db.Collection('', 'myCollection2');
myCollection.insert('john', {
first_name: 'John',
last_name: 'Smith',
age: 32,
gender: 'male',
address: {
street: '123 Main St',
city: 'NYC',
state: 'NY',
zip: '10001'
},
});
myCollection.insert('jane', {
first_name: 'Jane',
last_name: 'Smith',
age: 30,
gender: 'female',
address: {
street: '123 Main St',
city: 'NYC',
state: 'NY',
zip: '10001'
},
});
myCollection.get('john');
myCollection.update('jane', {
age: 31
});
myCollection.delete('jane');
myCollection.restore('jane');
myCollection.emptyTrash();
myCollection.getPath('jane');
myCollection.insert('sarah', {
first_name: 'Abagail',
last_name: 'Thomas',
age: 22,
gender: 'female',
address: {
street: '123 Main St',
city: 'NYC',
state: 'NY',
zip: '10001'
},
});
myCollection.rename('sarah', 'abagail');
myCollection.copyCol('myCollection2');
myCollection.rename('abagail', 'blank');
myCollection.overwrite('blank', {});
myCollection.copyDocToCol('blank', 'myCollection2');
myCollection.find({
last_name: 'Smith',
address: {
street: '123 Main St',
city: 'NYC',
state: 'NY',
zip: '10001'
}
});
myCollection.getVar('john', [
'first_name',
'last_name',
'age'
]);
myCollection.deleteVar('john', [
'address'
]);
myCollection.get('john');
myCollection.deleteCol();
myCollection2.deleteCol();