1.0.1 • Published 12 months ago
quantum-db v1.0.1
FullDataStore Class
This is a simple database class that provides basic CRUD operations (create, read, update, delete) and additional functionality like searching, sorting, pagination, and unique constraints.
Usage
- Initialize the database by creating a new instance of the
FullDataStore
class. - Define the schema for the entries in the database, including field types and required fields.
- Use the provided methods to interact with the database, such as creating, reading, updating, and deleting entries.
Example
// Initialize the database
const db = new Database(
"db.json",
{
name: { type: "string", required: true },
age: { type: "number" },
},
{
timestamp: true,
}
);
// Create new entries
const entry1 = { name: "John", age: 30 };
const entry2 = { name: "Jane", age: 25 };
db.create(entry1);
db.create(entry2);
// Get all entries
console.log(db.getAll());
// Update an entry
entry1.age = 31;
db.update(entry1._id, entry1);
console.log(db.get(entry1._id));
// Delete an entry
db.delete(entry2._id);
console.log(db.getAll());
// Perform a search
const searchCriteria = { age: 30 };
const searchResults = db.search(searchCriteria);
console.log("Search results:", searchResults);
// Sort entries
db.sort(["age"]);
console.log("Sorted entries:", db.getAll());
// Paginate entries
const pageNumber = 2;
const pageSize = 2;
const pageEntries = db.paginate(pageNumber, pageSize);
console.log(`Page ${pageNumber} (${pageSize} entries per page):`, pageEntries);
1.0.1
12 months ago