Have ideas to improve npm?Join in the discussion! »

    basedb

    2.0.4 • Public • Published

    basedb

    A lightweight database

    DATABASE

    Structure

    STRUCTURE

    • Database -> Folder
    • Collection -> File ( json )
    • Document -> {"package": "basedb"}

    Installation

    npm i basedb

    Usage

    • Require Module
    const {database} = require('basedb');
    • Create Database
    let db = new database('DATABASE');
    • Create Collection
    db.createCollection('user',(err)=>{
        if (err) throw err;
        console.log('collection created');
    });
    • Insert Document

      • Single Document
      let doc = {
         username: 'bit-web',
         email: 'bit-web404@gmail.com',
            password: "********"
        };
       
      db.createCollection('user',(err, collection)=>{
        if (err) throw err;
        console.log('collection created');
        collection.insert(doc,(err)=>{
         if (err) throw err;
         console.log('document inserted');
        });
      });
      • Multiple Documents
      let docs = [
        {
         username: 'bit-web',
         email: 'bit-web404@gmail.com',
            password: "********"
        },
        {
         username: 'bit-web2',
         email: 'bit-web200@gmail.com',
            password: "########"
        }
      ];
       
      db.createCollection('user',(err, collection)=>{
        if (err) throw err;
        console.log('collection created');
        collection.insert(docs,(err)=>{
         if (err) throw err;
         console.log('document inserted');
        });
      });
    • Insert Document (if the collection already exists)

      • Single Document
      let doc = {
         username: 'bit-web',
         email: 'bit-web404@gmail.com',
            password: "********"
        };
        
      db.collection('user').insert(doc,(err)=>{
        if (err) throw err;
        console.log('document inserted');
      });
      • Multiple Documents
       let docs = [
        {
         username: 'bit-web',
         email: 'bit-web404@gmail.com',
            password: "********"
        },
        {
         username: 'bit-web2',
         email: 'bit-web200@gmail.com',
            password: "########"
        }
      ];
       
      db.collection('user').insert(docs,(err)=>{
        if (err) throw err;
        console.log('documents inserted');
      });
    • Find

    db.collection('user').get(item =>{
        if (item.username === 'bit-web' && item.password === "********") {
            console.log(item);
        }else{
            console.log('couldn\'t found the document');
        };
    });

    Note: Always take the parameter item

    • Update
    db.collection('user').get(item =>{
        if (item.username === 'bit-web' && item.password === "********") {
            item.username = 'npmjs';
            item.email = 'npmjs123@gmail.com';
        }else{
            console.log('couldn\'t found the document');
        };
    });

    Note: Always take the parameter item

    • Delete Collection
    db.delete('user',(err)=>{
        if (err) throw err;
        console.log('collection deleted');
    });
    • Remove Database
    const {database, remove} = require('basedb');
    remove('DATABASE',(err)=>{
        if (err) throw err;
        console.log('database removed');
    });

    license

    ISC

    Install

    npm i basedb

    DownloadsWeekly Downloads

    1

    Version

    2.0.4

    License

    ISC

    Unpacked Size

    14.5 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar