clarity-db
v2.0.6
Published
Manage database is easy
Downloads
4
Readme
npm install clarity-db
Usage
To use the library, you need to import it into your project:
const Clarity = require("clarity-db")
const db = new Clarity("./mydb.json", {
backup: {
enabled: true,
folder: './db_backups/',
interval: 3600000
},
preset: {
hello: "world"
}
})```
```js
// Check if a key exists in the database
if(db.has(`sown`)) {
console.log("sown is registered")
} else {
console.log("sown is not registered")
}
// Get a value from a key
let sparrow = db.get("sparrow")
console.log(sparrow) // Output: Sparrow
// Set a value for a key
db.set("bird", "Sparrow")
// Perform arithmetic operations on values
db.add("tsubasa_money", 10000)
db.sub("sparrow_money", 10000)
// Get all data from the database
db.all()```
```js
// Delete a key and its value
db.delete("bird")
// Clear all data
db.clear()
// Save changes (optional)
db.save()
// Backup the database
db.backup()
// Restore db
db.restore('clarity-test')
// Working with arrays
let owners = db.get(`allowners`)
if(!owners){
db.set("owners", ["tsubasa"])
} else {
db.push("owners", "xon") //['tsubasa','xon']
}```