nabladb v2.0.2
An Advance File System API
š Homepage
Install
npm install nabladbIdeology
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.createAllows to create NablaClient Instance
import NablaClient from 'nabladb' const client = NablaClient.create(options?: NablaClientTypes.NablaClientOptions);- options:
NablaClientTypes.NablaClientOptions
- options:
NablaClient.initManually Initialize Client
If
NablaClientTypes.NablaClientOptions.autoInitistrue, you don't need to run this function.client.init();NablaClient.dbReturns a
NablaDbInstanceconst db = client.db(dbName: string, options?: NablaDbTypes.NablaDbOptions);- dbName:
string- Name of the Database
- options:
NablaDbTypes.NablaDbOptions
- dbName:
NablaDb
const db = client.db(dbName, options?: NablaDbTypes.NablaDbOptions);- dbName:
string- Name of the Database
- options:
NablaDbTypes.NablaDbOptions
NablaDb.createCreate Database
If
NablaDbTypes.NablaDbOptions.autoCreateistrue, you don't need to run this function.db.create()NablaDb.deleteDelete Database
db.delete()NablaDb.collectionOpens a Collection Inside a database
const collection = db.collection(collectionName: string, options?: NablaCollectionTypes.NablaCollectionOptions)- collectionName:
string- Name of the Collection
- options:
NablaCollectionTypes.NablaCollectionOptions
- collectionName:
NablaDb.existsChecks if Database exists
db.exists // booleanNablaDb.$DbDirReturns
Filic.DirectoryInstance of directory of the databaseNablaDb.$CollectionsDirReturns
Filic.DirectoryInstance of directory of"collections"inside database directoryNablaDb.$DbJsonReturns
Filic.Fileinstance of"<db>.json"fileNablaDb.ClientReturns
NablaClientInstance.
NablaCollection
const collection = db.collection(collectionName: string, options?: NablaCollectionTypes.NablaCollectionOptions)- collectionName:
string- Name of the Collection
options:
NablaCollectionTypes.NablaCollectionOptionsNablaCollection.createCreate Collection
If
NablaCollectionTypes.NablaCollectionOptions.autoCreateistrue, you don't need to run this function.collection.create()NablaCollection.deleteDelete Collection
collection.delete()NablaCollection.insertInsert a single document
collection.insertSync({ key1: "value1", key2: { key3: true, key4: [6, 4, 6] } })NablaCollection.insertManyInsert multiple documents
collection.insertManySync([ doc1, doc2, doc3, ... ])NablaCollection.getAllGets all documents in collection
collection.getAllSync()NablaCollection.getManyFind 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.getManyFind 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.deleteFirstDelete First document with fields that match given condition object
collection.deleteFirstSync({ email: "example@example.com" })NablaCollection.deleteManyDelete every document with fields that match given condition object
collection.deleteManySync({ expired: true })NablaCollection.updateFirstUpdate first document with fields that match given condition object
collection.updateFirstSync({ password: "123" }, { password: "new_password" })NablaCollection.updateManyUpdate every document with fields that match given condition object
collection.updateManySync({ password: "123" }, { bad_password_user: true })
NablaCollection.existsChecks if Collection exists
collection.exists // booleanNablaCollection.$CollectionJsonReturns
Filic.Directoryinstance of<collection>.jsonfile incollectionsdirectory of databaseNablaCollection.DbReturns
NablaDbInstance
Author
š¤ Henil Malaviya
- E-mail: henilmalaviya06@gmail.com
- Website: henil.xyz
- Twitter: @henil0604
- Github: @henil0604
š¤ Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a āļø if this project helped you!