This is an fully extendable no-SQL database completly written in node.js. Data could be accessed with JS-Array like find/filter Syntax. So there is no need to learn a new QueryLanguage.
npm install filterdb
If you just need a Database-Server and don't wan't to build the access Level around it, stay updated. Soon we will build a ready server-build.
import Database from "filterdb";
import faker from "faker";
(async () => {
//creates or opens Database
let db = await new Database("myDB");
for (let i = 0; i < 1000; i++) {
//Push data in the "persons" table.
await db.table("persons").save(faker.helpers.userCard());
}
//Yeap, simple Array.filter Syntax
let resultArray = await db.table("persons").filter((row) => row.name === val);
console.log(resultArray);
//Aync Iteratoion possible
let r2 = db.table("persons").filter((row) => {
return row.website === "filterdb.io";
});
for await (let row of r2) {
console.log(row);
}
for (let i = 0; i < 100; i++) {
await db.table("numbers").save({ num: i });
}
//Sort your data
let resultSort = await db
.table("numbers")
.filter((row) => row.num <= 50)
.sort((a, b) => {
a.num < b.num ? -1 : a.num > b.num ? 1 : 0;
});
console.log(resultSort);
//Map your data
let resultMap = await db
.table("numbers")
.filter((row) => row.num <= 50)
.map((row) => {
return row.num * 2;
});
console.log(resultMap);
//Reduce your data
let resultSortMapReduce = await db
.table("numbers")
.filter((row) => row.num <= 50)
.reduce((total, row) => {
return total + row.num;
});
console.log(resultReduce);
//All functions could be chained too
let resultMapReduce = await db
.table("numbers")
.filter((row) => row.num <= 50)
.map((row) => {
return row.num * 2;
})
.reduce((total, num) => {
return total + num;
});
console.log(resultMapReduce);
})();
An filterdb Database instance is created with by using default
export from the main module:
import Database from "filterdb";
import Server from "filterdb/plugins/Server";
(async () => {
//create database with options
let db = await new Database("myDB", {
path: "/database/data/",
cache: true,
plugins: [],
});
//extend Database with Http-Server plugin
db.extend(
new Server({
port: 8080,
}),
);
})();
This will return some meta-data about your database.
returns a Table-Class
extends the database with the plugin
closes the database
deletes the dataBase
An filterdb Table instance is created with by using the table
function from the dataBase Instance:
import Database from "filterdb";
(async () => {
let db = await new Database("myDB");
let table = db.table("tableName");
})();
This will return some meta-data about your table.
returns the stored object in the table with _id in arguments
creates a index on the object field name
and rebuilds the index if rebuild is set to true
returns the first row in table for which searchFunction
returns true
returns all rows in table for which searchFunction
returns true
saves obj
into the table. if obj._id
is not present then the id will be autogenerated.
returns the id of inserted obj.
removes obj with id _id
from the table
import Database from "filterdb";
import Server from "filterdb/plugins/Server";
(async () => {
let db = await new Database("myDB");
db.extend(
new Server({
port: 8080,
}),
);
})();
import Database from "filterdb";
import Cluster from "filterdb/plugins/Cluster";
(async () => {
let db1 = await new Database("db1");
let db2 = await new Database("db2");
db1.extend(
new Cluster({
port: 9000,
}),
);
db2.extend(
new Cluster({
port: 9001,
join: "172.0.0.1:9000",
}),
);
})();
- Index support for && and || operators
- plugins
- Multi-Threading (threads.js)
- Sort
- Map
- Reduce
- Extra Filter after Sort/Map/Reduce
- more usable events for plugin usage
- authentication
- CI Failing on Backup but no problems on win32 tests
- add Simple sort syntax maybe something like this:
db.table().find(row => row.name == "test").sort(row => row.status, 1)
- performance optimization
- remove thread.js and create own ThreadPool due to stability
- CLI-Interface
- REPL-Interface
- full REST-API with fastify
- client package
npm install filterdb-client
- realtime-API with websockets or SSE
- UI
- creation
- Stability-Checks
- Load-Balancing
- ...
It's hard bringing this thing to life, but maybe you have some time and like the idea behind this project. Every created issue, feature, bugfix, test and docs will help to get filterdb one step further. Contribution is always welcome.
- Create a fork
- Create your feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 🚀
This library is licensed under the terms of the MIT license.