Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
![example workflow](https://github.com/AllanPinheiroDeLima/indexedDBWrapper/actions/workflows/main.yml/badge.svg)
A simple and powerful wrapper for IndexedDB that simplifies data persistence in web applications. The DataStore
class provides methods for CRUD operations, bulk inserts, and flexible querying capabilities.
You can install the DataStore
library via npm:
npm install indexedkit
First, import the DataStore
class:
import { DataStore } from "indexedkit";
Create an instance of the DataStore
by specifying the database name, collection name, and optional data store options.
const dataStore = new DataStore<MyDataType>("myDatabase", "myCollection", {
idKey: "id",
indexes: [{ name: "nameIndex", keyPath: "name", unique: false }],
idGenerator: () => "custom-id" // optional custom ID generator
});
Initialize the database. It is mandatory the call of this method, otherwise, the database will return an error:
await dataStore.init();
Insert a single record:
const newUser = { name: "Alice", age: 30 };
await dataStore.insert(newUser);
Insert multiple records:
const users = [
{ name: "Bob", age: 25 },
{ name: "Charlie", age: 35 },
];
await dataStore.bulkInsert(users);
Insert or update a record. important if you are trying to update an existing record, this will shallow merge the existing record, overwriting any existing data with your new data:
const userInDataBase = { id: "1", name: "Alice", age: 31, subFields: [] }
await dataStore.upsert({ id: "1", name: "Alice", age: 31 });
// When you try and find this record again, the subFields WILL be missing! Be warned!
Update a record based on a query. The update method is used to update records. This operation makes a deep merge of the objects keeping any subFields intact in case they weren't sent to the operation:
await dataStore.update({ where: { name: "Alice" } }, { age: 32 });
Remove a record by ID. Remember that the type of your key is important! By default, all ids are string, but if you overwrote using the idKey option you should use the correct type to find your record. If it is a number, you should use a number to find. We will address this issue in the future roadmap so the types can hint the ids:
await dataStore.removeByIdKey("1");
Clear all records from a collection:
await dataStore.clearCollection();
Retrieve all records with optional query parameters:
const allUsers = await dataStore.findAll({ where: { age: 30 } });
You can paginate the records using limit and offset keys:
const allUsers = await dataStore.findAll({ where: { age: 30 }, limit: 5, offset: 5 });
Find a single record based on query parameters:
const user = await dataStore.findOne({ where: { name: "Alice" } });
The DataStore
class throws specific errors for various scenarios:
DatabaseNotDefinedError
: Thrown when the database is not initialized.InvalidInputError
: Thrown for invalid input data.CollectionNotFoundError
: Thrown when the specified collection does not exist.DocumentNotFoundError
: Thrown when the specified document is not found.This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
FAQs
![example workflow](https://github.com/AllanPinheiroDeLima/indexedDBWrapper/actions/workflows/main.yml/badge.svg)
The npm package indexedkit receives a total of 0 weekly downloads. As such, indexedkit popularity was classified as not popular.
We found that indexedkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.