1.0.1 • Published 6 months ago

feazy.db v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

Overview

This database module was created for fun and experimentation. It's designed to work with a SQLite database using the 'better-sqlite3' library.

Installation

To use this module, you can install it with npm:

npm install feazy.db

Usage

const db = require('feazy.db');
const userKey = 'user';

// Set a key
db.setKey(userKey, { name: 'John', age: 30 });
// Sets user data under the specified key.

// Get a key
const user = db.getKey(userKey);
console.log(user); // Output: { name: 'John', age: 30 }
// Retrieves user data from the given key.

// Update or insert a key
db.upsertKey(userKey, { name: 'Alice', age: 25 });
// Updates user data or creates a new user under the specified key.

// Get the key after updating
const updatedUser = db.getKey(userKey);
console.log(updatedUser); // Output: { name: 'Alice', age: 25 }
// Retrieves user data after the update.

// Add an element to an array
db.pushArray(`${userKey}.hobbies`, 'Reading', 'Cooking');
// Adds user interests to the array.

// Get an array
const hobbies = db.getKey(`${userKey}.hobbies`);
console.log(hobbies); // Output: ['Reading', 'Cooking']
// Retrieves user interests.

// Remove an element from an array
db.unpushArray(`${userKey}.hobbies`, 'Cooking');
// Removes an interest from the user's array.

// Get the array after removal
const updatedHobbies = db.getKey(`${userKey}.hobbies`);
console.log(updatedHobbies); // Output: ['Reading']
// Retrieves user interests after removal.

// Add a numerical value
db.addValue(`${userKey}.age`, 5);
// Adds the user's age.

// Get a numerical value
const age = db.getKey(`${userKey}.age`);
console.log(age); // Output: 30 (initial age) + 5 (added) = 35
// Retrieves the user's age.

// Subtract a numerical value
db.subtractValue(`${userKey}.age`, 10);
// Subtracts the user's age.

// Get the numerical value after subtraction
const updatedAge = db.getKey(`${userKey}.age`);
console.log(updatedAge); // Output: 35 (previous age) - 10 (subtracted) = 25
// Retrieves the user's age after subtraction.

// Delete a key
db.deleteKey(userKey);
// Deletes user data.
             

Acknowledgments

This database module is based on 'better-sqlite3' and was created by user adam<3 (Discord: adam34679). It has been pre-tested, but if you encounter any issues, please feel free to report them.

Happy coding ❤️!

1.0.1

6 months ago

1.0.0

7 months ago