0.0.7 • Published 6 months ago

bolt-browser-db v0.0.7

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

Bolt Library: 🌟 A Lightweight IndexedDB Library

Bolt is a JavaScript library for working with 🗂️ IndexedDB in a MongoDB-like manner. It simplifies 🛠️ IndexedDB operations by offering methods for creating 📁 databases, performing CRUD operations ✍️, aggregations 📊, and summations ➕.


Features 🚀

1. Initialization 🛠️

The library automatically initializes a 🗂️ database for a given store name. If the database or store does not exist, it creates one automatically.

Example:

const db = new Bolt('MyStore');

Output:

Database 'MyStore' and store 'MyStore' created. ✅

2. Insert One ➕

Inserts a single 📄 document into the store.

Example:

await db.insertOne({ name: 'Alice', age: 25 });

Output:

Document inserted with ID: 1 ✅

3. Insert Many 📋

Inserts multiple 📄📄 documents into the store.

Example:

await db.insertMany([
  { name: 'Bob', age: 30 },
  { name: 'Charlie', age: 35 }
]);

Output:

Documents inserted with IDs: [2, 3] ✅

4. Find One 🔍

Finds a single 📄 document matching a given query.

Example:

const user = await db.findOne({ name: 'Alice' });
console.log(user);

Output:

{ _id: 1, name: 'Alice', age: 25 } ✅

5. Find 🔎

Finds all 📄📄 documents matching a given query.

Example:

const users = await db.find({ age: 30 });
console.log(users);

Output:

[{ _id: 2, name: 'Bob', age: 30 }] ✅

6. Update ♻️

Updates 📄📄 documents matching a query with new values.

Example:

await db.update({ name: 'Alice' }, { age: 26 });

Output:

Updated documents: [{ _id: 1, name: 'Alice', age: 26 }] ✅

7. Delete ❌

Deletes 📄📄 documents matching a query.

Example:

await db.delete({ age: 35 });

Output:

Deleted 1 document(s). ✅

8. Sum ➕

Calculates the sum of a field for 📄📄 documents matching a condition.

Example:

const totalAge = await db.sum('age', { name: 'Alice' });
console.log(totalAge);

Output:

Total age: 26 ✅

9. Aggregate 📊

Performs advanced data aggregation.

Example:

const result = await db.aggregate([
  { $match: { age: { $gte: 30 } } },
  { $group: { _id: 'age', totalAge: { initial: 0, totalAge: 'age' } } }
]);
console.log(result);

Output:

[{ _id: 'age', totalAge: 65 }] ✅

How to Use 🧑‍💻

  1. Include the Bolt library in your project.
  2. Initialize it with a store name 📁.
  3. Use its methods for CRUD operations ✍️ and advanced queries 🔍.

Limitations ⚠️

  • Each store is represented as a separate database.
  • No native support for joins or cross-store queries.

Full Example 🏗️

(async () => {
  const db = new Bolt('ExampleStore');

  // Insert data ➕
  await db.insertOne({ name: 'Alice', age: 25 });
  await db.insertMany([
    { name: 'Bob', age: 30 },
    { name: 'Charlie', age: 35 }
  ]);

  // Query data 🔍
  console.log(await db.findOne({ name: 'Alice' }));
  console.log(await db.find({ age: 30 }));

  // Update data ♻️
  await db.update({ name: 'Alice' }, { age: 26 });

  // Sum ages ➕
  const totalAge = await db.sum('age');
  console.log(`Total age: ${totalAge}`);

  // Aggregate data 📊
  const aggregated = await db.aggregate([
    { $match: { age: { $gte: 25 } } },
    { $group: { _id: 'total', sumAge: { $sum: 'age' } } }
  ]);
  console.log(aggregated);

  // Delete data ❌
  await db.delete({ name: 'Bob' });
})();
0.0.7

6 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.1

7 months ago