1.0.7 • Published 4 years ago

corny-database v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Corny-Database

This is a really redneck, incredibly simple, database written in JS . It stores all data in memory, but is fast when retrieving/writing data. Should you use this over something like MongoDB? Definitely not for large scale applications that will be storing a lot of data, but maybe for smaller programs where keeping all the data in memory won't hurt. And yes this does have persistent storage through json files.

So how does it work?

The only export present in this package is the class "Database"

const Database = require('corny-database');

To use the database simply assign it a name to be loaded/saved as.

const db = new Database("database-main");

Each database is organized into a hierarchical tree similar to that of an object in JSON. To store something in it, simply do.

db.setData(value, 'foo', 'bar', 'foobar');

This would create an object akin to

const obj =
{
  foo:
  {
    bar:
    {
      foobar: value
    }
  }
};

in your database. To get the value there, simply use

db.getData('foo', 'bar', 'foobar');

You can also get the object containing other values in the database by doing:

db.getData('foo', 'bar');

Be mindful of modifying this however, as doing so will not save the database unless another db.setData() is called or db.save() is called.

To check if the database contains a value or category you can do this check:

database.containsData('foo', 'bar', 'foobar');

You can get all the data in the database (modifying this is not reccomended) by just doing "db.data", and set it by saying "db.data = ...;". This will also save the database. The datafile this database is saved to can be found by getting db.dataFile.

Backups

To backup your database, you can use the function

db.backup(callback);

This will create a folder with the database name suffixed with -backup.

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.3

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago