js-loco

1.0.0 • Public • Published

Loco -- JavaScript Local Collection (Database)

Local database built using JavaScript and Node.JS.

🚀 Get started!

First, download the file with npm.

npm i --save js-loco

Then, import it inside of your code and create the database instance.

// Multiple `Database` instances can be created.
const Database = require("js-loco");

// No name = `default`
const db = new Database("db-name");

If you have an existing database file (example.collection.json), you can import it using node:fs.

const fs = require("node:fs");

try {
  // Replace whole database.
  db.replace(
    // Parse the JSON file.
    JSON.parse(
      // Read the JSON file.
      fs.readFileSync("example.collection.json", "utf-8")
    )
  );
} catch (err) {
  // If there is an error reading or parsing the file...
  throw err;
}

Communicating with the database.

Push data:

db.add("This is a test");

Delete data:

db.remove("This is a test");

Update data:

db.update("This is a test", "Replacement");

Replace the whole database:

db.replace(["This is the new database"]);

// You can fill the method with an empty array to reset the database.
db.replace([]);

🧪 Testing.

Open a terminal (Windows) inside of the module folder.

Then, type this command:

npm test

It will open a new terminal and show some examples.

Package Sidebar

Install

npm i js-loco

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

5.62 kB

Total Files

9

Last publish

Collaborators

  • langedechu