quantum-db

1.0.1 • Public • Published

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

  1. Initialize the database by creating a new instance of the FullDataStore class.
  2. Define the schema for the entries in the database, including field types and required fields.
  3. 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);

Package Sidebar

Install

npm i quantum-db

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

15.9 kB

Total Files

4

Last publish

Collaborators

  • rami.sweyri