nabladb
v2.0.2
Published
An Advance yet simple to use Database
Downloads
1
Maintainers
Readme
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: "[email protected]",
username: "test_user",
password: "super_secret_hehe",
verified_email: false
},
{
email: "[email protected]",
username: "test_user_2",
password: "you_can_not_hack_me",
verified_email: false
}
])
console.log(users.getAllSync()) // [{ email: "[email protected]"...}, { email: "[email protected]"...}]
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
- options:
NablaClient.init
Manually Initialize Client
If
NablaClientTypes.NablaClientOptions.autoInit
istrue
, you don't need to run this function.client.init();
NablaClient.db
Returns a
NablaDb
Instanceconst 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.create
Create Database
If
NablaDbTypes.NablaDbOptions.autoCreate
istrue
, 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
- collectionName:
NablaDb.exists
Checks if Database exists
db.exists // boolean
NablaDb.$DbDir
Returns
Filic.Directory
Instance of directory of the databaseNablaDb.$CollectionsDir
Returns
Filic.Directory
Instance of directory of"collections"
inside database directoryNablaDb.$DbJson
Returns
Filic.File
instance of"<db>.json"
fileNablaDb.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
istrue
, 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: "[email protected]" })
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 incollections
directory of databaseNablaCollection.Db
Returns
NablaDb
Instance
Author
👤 Henil Malaviya
- E-mail: [email protected]
- 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!