SylvieJS is a document oriented database written in javascript, published under MIT License. Its purpose is to store javascript objects as documents in a NoSQL fashion and retrieve them with a similar mechanism. Runs in both node and browser environments.
SylvieJS is a fork of LokiJS repository. SylvieJS aims to be a drop-in replacement for LokiJS while maintaining more modern APIs.
Creating a database :
/**
* Note: Sylvie exports loki as well for backwards compatibility.
* let db = new loki("example.db");
*/
let db = new Sylvie("example.db");
Add a collection :
let users = db.addCollection("users");
Insert documents :
users.insert({
name: "Odin",
age: 50,
address: "Asgard",
});
// alternatively, insert array of documents
users.insert([
{ name: "Thor", age: 35 },
{ name: "Loki", age: 30 },
]);
Simple find query :
let results = users.find({ age: { $gte: 35 } });
let odin = users.findOne({ name: "Odin" });
Simple where query :
let results = users.where(function (obj) {
return obj.age >= 35;
});
Simple Chaining :
let results = users
.chain()
.find({ age: { $gte: 35 } })
.simplesort("name")
.data();
Simple named transform :
users.addTransform("progeny", [
{
type: "find",
value: {
age: { $lte: 40 },
},
},
]);
let results = users.chain("progeny").data();
Simple Dynamic View :
let pview = users.addDynamicView("progeny");
pview.applyFind({
age: { $lte: 40 },
});
pview.applySimpleSort("name");
let results = pview.data();
Generated using TypeDoc