npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

filterdb

v0.5.8

Published

filterdb 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.

Downloads

26

Readme

filterdb

Travis codecov code style: prettier Blazing Fast

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.

Installation

npm install filterdb

DatabaseServer Download

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.

Usage

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);
})();

API

Database

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,
        }),
    );
})();

db.meta

This will return some meta-data about your database.

db.table(tableName)

returns a Table-Class

db.extend(plugin)

extends the database with the plugin

await db.close()

closes the database

await db.delete()

deletes the dataBase

Table

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");
})();

table.meta

This will return some meta-data about your table.

await table.get(_id)

returns the stored object in the table with _id in arguments

await table.ensureIndex(name, rebuild?)

creates a index on the object field name and rebuilds the index if rebuild is set to true

await table.find(searchFunction, functionContext)

returns the first row in table for which searchFunction returns true

await table.filter(searchFunction, functionContext)

returns all rows in table for which searchFunction returns true

await table.save(obj)

saves obj into the table. if obj._id is not present then the id will be autogenerated. returns the id of inserted obj.

await table.remove(_id)

removes obj with id _id from the table

Plugins

http-server based on fastify

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",
        }),
    );
})();

In progress

main-package

  • [x] Index support for && and || operators
  • [x] plugins
  • [x] Multi-Threading (threads.js)
  • [x] Sort
  • [x] Map
  • [x] Reduce
  • [x] Extra Filter after Sort/Map/Reduce
  • [x] more usable events for plugin usage
  • [x] 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)
  • [x] performance optimization
  • [x] remove thread.js and create own ThreadPool due to stability
  • [ ] CLI-Interface
  • [ ] REPL-Interface

httpServer-Plugin

  • [x] full REST-API with fastify
  • [x] client package npm install filterdb-client
  • [ ] realtime-API with websockets or SSE
  • [ ] UI

cluster-Plugin

  • [ ] creation
  • [ ] Stability-Checks
  • [ ] Load-Balancing
  • [ ] ...

Contributing

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.

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

This library is licensed under the terms of the MIT license.