leo-db

1.0.11 • Public • Published

LeoDB

Lightweight Miniature JSON DB

Hello World, The use of JSON is at its peak and th future of the data being passed and store has a higher potential of also being in JSON format. Thus im presenting you with this module of which makes it extremely easy to perform DB like queries on the JSON data.

// Import the module
const leoDB = require("leo-db");

This module provides following functionality,

  1. Loading data from file.
  2. Saving the data to a file.
  3. Performing a search query.
  4. Performing an insert query.
  5. Performing a update query.
  6. Performing a delete query.

I have tried implementing the module to save save using key replacement method to a general structure. Thus reducing the data size without affecting the runtime efficiency.

// Loading an existing DB from the Local disk.
leodb.LoadDB();

// Save the DB to the loacl disk.
leodb.SaveDB();

Now to make a new DB or remove an existing DB we have the following functions, (DB here means the collection/table)

// Create a new DB.
leoDB.NewDB("Enter_DB_Name", ["field_1", "field_2", "field_3"]);

// Delete a particular DB and remove all data.
leoDB.DeleteDB("Enter_DB_Name");

Select the database you want to perform the query on.

// Select the DB. (Only once for multiple query on same DB)
leoDB.SelectDB("Enter_DB_Name");

Performing Insert Query

// Single Data Insert
leoDB.Insert({
    field_1: "value_1",
    field_2: "value_2",
    field_3: "value_3",
});

// Multiple Data Insert
leoDB.Insert([
    {
        field_1: "value_1",
        field_2: "value_2",
        field_3: "value_3",
    },
    {...},
    {...}
]);

Performing Update Query

// Data Update
leoDB.Update(
    {
        search_for_key: "search_for_value",
    },
    {
        update_field: "update_value",
    }
);

Performing Find Query

// Data Find (Returns all data)
leoDB.Find();

// Data Find (Returns all data thats matching)
leoDB.Find({
    search_field_1: "search_value_1",
    OR: {
        // Search for optional values matching.
        search_field_2: [
            "possible_value_1",
            "possible_value_2",
            "possible_value_3",
        ],
        search_field_3: [
            "possible_value_1",
            "possible_value_2",
            "possible_value_3",
        ],
    },
});

Performing Delete Query

// Data Delete
leoDB.Delete({
    search_for_key: "search_for_value",
});

// Delete all data. (Removes all the data);
leoDB.Delete();

Warning: Use with utmost care...its still under development.

Package Sidebar

Install

npm i leo-db

Weekly Downloads

1

Version

1.0.11

License

ISC

Unpacked Size

8.81 kB

Total Files

3

Last publish

Collaborators

  • leomalay