JSPM

moonlight.db

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q20843F
  • License MIT

MoonlightDB is a lightweight local database with no dependencies and easy to use.

Package Exports

  • moonlight.db
  • moonlight.db/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (moonlight.db) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


moonlight.db

npm installnfo

Table of contents

About

Moonlight.DB is a lightweight local database with no dependencies and easy to use.

Installation

Node.js v14.0.0 or newer is recommended.

Install: npm install moonlight.db

Getting Started

Setting up the Moonlight.DB instance

database.js

const DatabaseManager = require("moonlight.db");

module.exports = {
    connection: new DatabaseManager.MoonlightDB({
        dbpath: __dirname + "/database"
    })
};

Example Usage

test.js

const database = require("./database.js");
const db = database.connection;

if(db.collections.includes("users") === false) db.createCollection("users");

/* ------- insert item into db ------- */
db.collection("users").insertOne({
    name: "TestUser",
    age: 26,
    banned: false
}).then(() => {
    //ok user created;
}).catch(error => {
    //error;
    console.log(error);
});

/* ------- find item ------- */
db.collection("users").findOne({name: "TestUser"}).then(item => {
    //ok found the user;
    console.log(item);
    /*
        console output => {
          _id: "3bgfvx99l1t99j0pxouv3u8y00fy6n49",
          name: "TestUser",
          age: 26,
          banned: false
        }
    */
}).catch(() => {
    //error not found;
});

/* ------- update item ------- */
db.collection("users").updateOne({_id: "3bgfvx99l1t99j0pxouv3u8y00fy6n49"}, {
    "$set": {
        banned: true
    }
}).then(() => {
    //ok user updated;
}).catch(error => {
    //error not found;
    console.log(error);
});

/* ------- delete item ------- */
db.collection("users").deleteOne({name: "TestUser", banned: true}).then(() => {
    //ok user removed from db;
}).catch(error => {
    console.log(error);
});

Help

If you are experiencing problems, or you just need a nudge in the right direction, please do not hesitate to create a New Issue on Github repository.