mocaoi.db
v1.0.1
Published
A simple and flexible Node.js database module for managing user data with support for setting, adding, removing values, and array operations.
Downloads
16
Maintainers
Readme
Example Usage;
const Database = require("mocaoi.db")
const userId = 12345678910
const loves = ["cat", "dog"]
function main() {
const db = new Database("users", { name: "TestUser", extension: "database" })
//Generator file .database (Custom)
//Set User
db.set(userId, { xp: 0, coins: 0, loves: [] })
//Add value on userId
db.add(userId + ".xp", 2)
db.add(userId + ".coins", 15)
//Remove value on userId
db.remove(userId + ".xp", 1)
db.remove(userId + ".coins", 5)
//Push on array
for (const love of loves) {
db.push(userId + ".loves", love)
}
//Get userId
return db.get(userId)
}
console.log(main())
//Result: { xp: 1, coins: 10, loves: [ 'cat', 'dog' ] }
add
db.add("path", number)
remove
db.remove("path", number)
delete
db.delete("path")
get
db.get("path")
push
db.push("path", { object: true })
db.push("path", { string: true })
set
const value = {
string: "abc",
number: 10
}
db.set("path", value)
has
// db.has(value)
db.has("apples") // returns: boolean
toJSON
db.toJSON(); // { ... }
resetval
// db.resetval(name)
db.resetval("apples") // "apples": ""