- Simple json database. Backup system included!
- Install the project first by using:
- Don't forget to define it!
const { Database } = require('zanci.db')
const db = new Database("MySuperSecretDatabase.json")
- Typescript support added as well!
import { Database } from 'zanci.db';
const db = new Database();
- Now if a file doesn't exist, it will automatically create it!
- Path is automatically set to "./"
- Define an object and push it to the file.
let object1 = {key: true, key2: "true"}
db.set('Object', object1); // Object: {key: "value1", key2: "value2"}
- Define an array and push it to the file.
let array1 = ['element', 'element2']
db.set('Array', array1); // Array: ['element', 'element2']
db.push('Array', 'element3'); // Array: ['element', 'element2', 'element3']
db.objectFetch('Object', 'key'); // key: "value1"
db.arrayFetch('Array', 1); // element2
db.fetch('data'); // Fetches the value of the data
db.get('data'); // Get the value of the data
db.fetchAll(); // Fetches all the data in the database
db.all(); // Fetches everything in the database
db.remove('data'); // Removes the data from the database
db.delete('Array', 'element3'); // Removing something from an array using value
db.deleteKey('object', 'key'); // Deletes the provided key from the given object
db.deleteEach('data'); // Deletes each data that starts with the given parameter
- Remove database content. Carefully with this!
db.clear(); // Clears everything from the database
db.destroy(); // Deletes the database file
db.has('data'); // Returns "true" or "false" if the database has the data or not.
db.add('data', 1); // Adds one to the data
db.subtract('data', 1); // Subtracts one from the data
db.math("eco", "+", 10); // Adds 10 to the data. You can use +, -, * and /.