1.0.4 • Published 1 year ago

fpdb v1.0.4

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

FPDB

Hello, This Package is A Database Package That Uses The Storage ROM Or The File Storage System To Save Data, It Doesn't Have Any Dependencies Other Than The Built-In Node.JS Packages, It Can Run Totally Offline But Still Requires Internet Just For Checking If It's In The Latest Version.

This Package Is For Beginners Of Nodejs As Well As For The Advanced.

Note: This Package Works Well For Advanced Projects But Isn't Recommended For Them.

Install Package

To deploy this project run

  npm install fpdb

Changelog

v1.0.3

Special Characters Are Now Supported In All Params

Removed A Lot Of Junk code

Discontinued The Manual Key Editing Support

Documentation

Set()

Function To Set A Key In A Collection Or Without Collection

Usage: set(key,cname,value)

Key : The Key For Saving Value

Cname : The Name Of The Collection In Which The Key Should Be Saved

Value : The Data To Be Saved For the Key

Example (Without Collection):

const db = require("fpdb")
db.init()
db.set("MyUsername","","MyData")

or

const db = require("fpdb")
db.init()
db.set("MyUsername",undefined,"MyData")

Example (With Collection):

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")
db.set("MyUsername","MyCollectionName","MyData")

Note :- All Special Characters Are Now Supported In v1.0.3


CreateCol()

Function To Create A Collection

Usage : createCol(cname)

Cname : Name Of The Collection To Be Created

Example :

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")

Get()

Function To Get Or Read A Key

Usage : get(key,cname,callback)

Key And Cname : Click Here

Callback : The Callback, Returns Data In Form Of function (err,data){}

Example :

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")
db.set("MyUsername","MyCollectionName","MyData")
db.get("MyUsername","MyCollectionName",(err,data)=>{
    if (err){
        console.log(err)
    } else {
        console.log(data)
    }
})

Output (Console) :

 Database Directory Check Complete 
 Checking If The Package(FPDB) Has The Latest Version 
 Version Is Latest 
 Initiation Done
 MyData

DelKey()

DelKey()

Function To Delete A Key With Or Without A Collection

Usage : delKey(key,cname)

Key : The Name Of The The Key You Want To Delete

Cname : The Collection From Which The Key Originates

Example (Without Collection) :

const db = require("fpdb")
db.init()
db.set("MyUsername",undefined,"MyData")
db.delKey("MyUsername")

Example (With Collection) :

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")
db.set("MyUsername","MyCollectionName","MyData")
db.delKey("MyUsername","MyCollectionName")

DelAll()

DelAll()

Function To Delete All The DB Data(DB Keys And Collections) From Database

Usage : delAll()

Example :

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")
db.set("MyUsername","MyCollectionName","MyData")
db.delAll()

DelCol()

DelCol()

Function To Delete A Collection

Usage : delCol(cname)

Cname : The Name Of The Collection You Want To Delete

Example :

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")
db.delCol("MyCollectionName")

Note :- Deleting A Collection Also Deletes All Of Its Keys


ListKeys()

ListKeys()

Function To List Keys That Are In Or Not In A Directory

Usage : listKeys(cname,callback)

Cname : The Name Of The Collection From Which You Want The List From, If You Want The List Of The Files Not In Any Directory Use "" Or undefined.

Callback : The Callback, in the Form Of function(err,data)

Example (With Collection) :

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")
db.set("MyUsername","MyCollectionName","MyData")
db.set("MyUsername-1","MyCollectionName","MyData")
db.set("MyUsername-2","MyCollectionName","MyData")
db.set("MyUsername-3","MyCollectionName","MyData")
db.set("MyUsername-4","MyCollectionName","MyData")
db.listKeys("MyCollectionName",(err,data)=>{
    if(err){
        console.log(err)
    } else {
        console.log(data)
    }
})

Example (Without Collection) :

const db = require("fpdb")
db.init()
db.set("MyUsername","","MyData")
db.set("MyUsername-1","","MyData")
db.set("MyUsername-2","","MyData")
db.set("MyUsername-3","","MyData")
db.set("MyUsername-4","","MyData")
db.listKeys("",(err,data)=>{
    if(err){
        console.log(err)
    } else {
        console.log(data)
    }
})

Output Of Both (Console) :

Database Directory Check Complete 
Checking If The Package(FPDB) Has The Latest Version 
Initiation Done
Version Is Latest
MyUsername-1
MyUsername-2
MyUsername-3
MyUsername-4
MyUsername

ListCol()

ListCol()

Function To List All The Collections

Usage : listCol(callback)

Callback : The Callback, Returns Data In Form Of function(err,data)

Example :

const db = require("fpdb")
db.init()
db.createCol("MyCollectionName")
db.createCol("MyCollectionName-1")
db.createCol("MyCollectionName-2")
db.createCol("MyCollectionName-3")
db.createCol("MyCollectionName-4")
db.createCol("MyCollectionName-5")
db.listCol((err,data)=>{
    if(err){
        console.log(err)
    } else {
        console.log(data)
    }
})

Output (Console) :

Database Directory Check Complete 
 Checking If The Package(FPDB) Has The Latest Version 
Initiation Done
MyCollectionName,MyCollectionName-1,MyCollectionName-2,MyCollectionName-3,MyCollectionName-4,MyCollectionName-5
 Version Is Latest 

CheckKeyExists()

CheckKeyExists()

Function That Checks If The Given Key Exists

Usage : checkKeyExists(key,cname,callback)

Key : The Name Of The Key

Cname : The Collection Where Key Exists (Optional)

Callback : Returns true If File Exists Or Returns false If Key Doesn't Exist

Example (With Collection) :

const db = require("fpdb")
db.init()
db.createCol("users")
db.set("username","users","Dhruva S")
db.checkKeyExists("username","users",callback =>{
    if(callback){
        console.log("Key Exists")
        // Here `callback` Is Returned As `true`
    } else {
        console.log("Key Doesn't Exist")
        // Here `callback` Is Returned As `false`
    }
})

Example (Without Collection) :

const db = require("fpdb")
db.init()
db.set("username","","Dhruva S")
db.checkKeyExists("username","",callback =>{
    if(callback){
        console.log("Key Exists")
        // Here `callback` Is Returned As `true`
    } else {
        console.log("Key Doesn't Exist")
        // Here `callback` Is Returned As `false`
    }
})

CheckColExists()

CheckColExists()

Synchronous Function To Check If Given Collection Exists

Usage : checkColExists(cname)

Cname : The Collection's Name

This Function Returns true If Given Collection Exists And Returns false If Given Collection Doesn't Exist

Example :

const db = require("fpdb")
db.init()
db.createCol("test")
console.log(db.checkColExists("test"))
// returns `true`

Features

  • Can Run Fully Offline
  • 0 Dependencies
  • Extremely Simple

FAQ

How To Edit Keys Manually ?

Manual Key Editing Has Been Discontinued From v1.0.3 Onwards Due To Security Issues


How Do I Contact The Author For Suggestions/Complaints/Errors ?

You Can Contact Me Via Email : dhruvakalur9@gmail.com

OR You Can DM Me Via Discord : Dhruva kalur#4678


Thank You For Visiting This Package, We Trust That This Package Will Be Useful For You

The End