A lightweight JavaScript library to add, get, and update JSON data in a structured way using a memory cache with persistence.
Manage your JSON objects using datasets, keeping your local storage organized and queryable.
Utilizes internal memory for lightning-fast read operations before syncing to persistent storage.
Built for modern workflows with full Promise support and clean asynchronous APIs.
Initialize your Qwery instance. This sets up the initial store in LocalStorage if it doesn't exist.
const qwery = new Qwery({ name: "my_app_db" });
await qwery.create();
// Output: The instance itself (chainable)
Push a new object into a specific dataset.
await qwery.add({
dataset: "users",
data: { id: "u1", name: "John Doe", email: "john@example.com" }
});
// Output: Promise<void>
Fetch items based on a predicate function. Returns a single object if one match is found, or an array for multiple.
const user = await qwery.get({
dataset: "users",
predicate: (x) => x.id === "u1"
});
// Output: { id: "u1", name: "John Doe", ... }
Merge new values into an existing record identified by a field/value pair.
await qwery.update({
dataset: "users",
field: "id",
value: "u1",
data: { name: "Johnny" }
});
// Output: Promise<void>
Delete an item from a dataset.
await qwery.remove({
dataset: "users",
field: "id",
value: "u1"
});
Get an array of all available dataset names in the instance.
const sets = qwery.listDatasets();
// Output: ["users", "settings", "posts"]
A complete list of methods available on the Qwery instance.
uuid()
Generates a standard v4 UUID for unique record IDs.
count(dataset)
Returns the number of items in a specified dataset.
has(options)
Checks if a specific value exists in a dataset field. Returns boolean.
truncate()
Clears all datasets but preserves the database structure.
reset()
Deletes the database from LocalStorage entirely.
json()
Returns the raw object state of the entire database.