clarity-db
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

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']
}```

Readme

Keywords

Package Sidebar

Install

npm i clarity-db

Weekly Downloads

2

Version

2.0.6

License

MIT

Unpacked Size

14.9 kB

Total Files

10

Last publish

Collaborators

  • 1tsubasa