1.0.3 • Published 7 years ago

filebaser v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Filebaser

TravisCI CodeCov NPM Version NPM Downloads Licence Filebaser is an engine for managing database documents like MongoDB.

Installation

All dependencies of Filebaser are easily installed by npm.

    npm install -g istanbul codecov
    npm install

Declaration

How to declare:

    const FileBaser = require('filebase');

    let fb = new FileBaser('databasefile.db');

Querying

You can apply any filter like in MongoDB

    let collection = fb.getColletion('users');

    let users = collection.find({
        limit: 10,
        where: {
            age: { gte: 18 },
            active: true
        }
    });

There's an alternative way for filtering data, shown in the example below:

    let collection = fb.getCollection('users');

    let users = collection
        .find()
        .where('age', 'gte', 18)
        .where('active', true)
        .limit(10)
        .fetchAll();

Or you can even use your own custom filter:

    let users = collection()
        .find()
        .where((element) => {
            return element.active || element.name.indexOf('base');
        })
        .limit(5)
        .fetchAll();

Saving

For inserting and updating data we use a pattern similar to an ORM

    let collection = fb.getCollection('users');

    let obj = {
        name: 'filebase',
        login: 'file.baser',
        pass: 'file@123baser#',
        age: 24,
        active: true
    };

    collection.save(obj);

After that this object received an unique ID for identification and was saved to memory.

In case object already has an ID (is not a new object), than the data is saved and ID is not regenerated.

Why saved on memory ?

Because we are talking about writing data into a file. Even NodeJS works asynchronously it should sometime overload the app. So, to solve this problem we created a function called "flush()". It's reponsible for sending saved data directly to the database file. E.g.: continuing from last example about inserting data.

    collection.flush();

What about async ?

Recently implemented, there're some calls that can be made asynchronously.

    let fb = new FileBaser('databasefile.db');

    let collection = fb
        .getCollectionAsync('users')
        .then((collection) => {
           let users = collection
                .find()
                .where((element) => element.active)
                .limit(10)
                .fetchAll();
        });

Testing

For automated tests we're using Mocha. And, integrated with npm custom scripts, you can run that easily using the following command.

    npm run test

Project also relies on codecov and istanbul for measuring codecoverage.

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.9.16

7 years ago

0.9.13

7 years ago

0.9.12

7 years ago

0.9.11

7 years ago

0.9.10

7 years ago

0.9.8

7 years ago

0.9.6

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.7.15

7 years ago

0.7.14

7 years ago

0.7.13

7 years ago

0.7.12

7 years ago

0.7.9

7 years ago

0.7.5

7 years ago