2.0.2 ā€¢ Published 1 year ago

nabladb v2.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

An Advance File System API

šŸ  Homepage

Install

npm install nabladb

Ideology

This Simple Database allows you to quickly start a project where you needs database. The Database is self stored means it can exists inside the project structure. NablaDb uses object oriented approach to handle files and directories. NablaDb's First Priority is to make API type-safe and simple.

Quick Start

import NablaClient from 'nabladb';

const client = new NablaClient({
    verbose: 2,
    root: Path.join(process.cwd(), "test/.ndb"),
})

const db = client.db("my_app");

const users = db.collection("users");

users.insertSync([
    {
        email: "test@example.com",
        username: "test_user",
        password: "super_secret_hehe",
        verified_email: false
    },
    {
        email: "test2@example.com",
        username: "test_user_2",
        password: "you_can_not_hack_me",
        verified_email: false
    }
])

console.log(users.getAllSync()) // [{ email: "test@example.com"...}, { email: "test2@example.com"...}]

API

Types

import * as NablaClientTypes from 'filic/types/NablaClient';
import * as NablaDbTypes from 'filic/types/NablaDb';
import * as NablaCollectionTypes from 'filic/types/NablaCollection';

NablaClient

  • static NablaClient.create

    Allows to create NablaClient Instance

        import NablaClient from 'nabladb'
    
        const client = NablaClient.create(options?: NablaClientTypes.NablaClientOptions);
    • options: NablaClientTypes.NablaClientOptions
  • NablaClient.init

    Manually Initialize Client

    If NablaClientTypes.NablaClientOptions.autoInit is true, you don't need to run this function.

        client.init();
  • NablaClient.db

    Returns a NablaDb Instance

        const db = client.db(dbName: string, options?: NablaDbTypes.NablaDbOptions);
    • dbName: string
      • Name of the Database
    • options: NablaDbTypes.NablaDbOptions

NablaDb

const db = client.db(dbName, options?: NablaDbTypes.NablaDbOptions);
  • dbName: string
    • Name of the Database
  • options: NablaDbTypes.NablaDbOptions
  • NablaDb.create

    Create Database

    If NablaDbTypes.NablaDbOptions.autoCreate is true, you don't need to run this function.

        db.create()
  • NablaDb.delete

    Delete Database

        db.delete()
  • NablaDb.collection

    Opens a Collection Inside a database

        const collection = db.collection(collectionName: string, options?: NablaCollectionTypes.NablaCollectionOptions)
    • collectionName: string
      • Name of the Collection
    • options: NablaCollectionTypes.NablaCollectionOptions
  • NablaDb.exists

    Checks if Database exists

        db.exists // boolean
  • NablaDb.$DbDir

    Returns Filic.Directory Instance of directory of the database

  • NablaDb.$CollectionsDir

    Returns Filic.Directory Instance of directory of "collections" inside database directory

  • NablaDb.$DbJson

    Returns Filic.File instance of "<db>.json" file

  • NablaDb.Client

    Returns NablaClient Instance.


NablaCollection

    const collection = db.collection(collectionName: string, options?: NablaCollectionTypes.NablaCollectionOptions)
  • collectionName: string
    • Name of the Collection
  • options: NablaCollectionTypes.NablaCollectionOptions

  • NablaCollection.create

    Create Collection

    If NablaCollectionTypes.NablaCollectionOptions.autoCreate is true, you don't need to run this function.

        collection.create()
  • NablaCollection.delete

    Delete Collection

        collection.delete()
  • NablaCollection.insert

    Insert a single document

    collection.insertSync({
        key1: "value1",
        key2: {
            key3: true,
            key4: [6, 4, 6]
        }
    })
  • NablaCollection.insertMany

    Insert multiple documents

    collection.insertManySync([
        doc1,
        doc2,
        doc3,
        ...
    ])
  • NablaCollection.getAll

    Gets all documents in collection

    collection.getAllSync()
  • NablaCollection.getMany

    Find Many multiple documents where fields that match given condition object

    collection.getManySync({
        verified: false
    })
    // finds every document in the collection with `verified` that is `false`
  • NablaCollection.getMany

    Find First document where fields that match given condition object

    collection.getFirstSync({
        verified: false
    })
    // finds first document in the collection with `verified` that is `false`
  • NablaCollection.deleteFirst

    Delete First document with fields that match given condition object

    collection.deleteFirstSync({
        email: "example@example.com"
    })
  • NablaCollection.deleteMany

    Delete every document with fields that match given condition object

    collection.deleteManySync({
        expired: true
    })
  • NablaCollection.updateFirst

    Update first document with fields that match given condition object

    collection.updateFirstSync({
        password: "123"
    }, {
        password: "new_password"
    })
  • NablaCollection.updateMany

    Update every document with fields that match given condition object

    collection.updateManySync({
        password: "123"
    }, {
        bad_password_user: true
    })
  • NablaCollection.exists

    Checks if Collection exists

        collection.exists // boolean
  • NablaCollection.$CollectionJson

    Returns Filic.Directory instance of <collection>.json file in collections directory of database

  • NablaCollection.Db

    Returns NablaDb Instance


Author

šŸ‘¤ Henil Malaviya

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago