Qwery.js
v2.0.0
Zero dependency, fast-performing in-memory database

Lightweight JavaScript
Document Database

Store, query and manage JSON documents using a fluent, callback-oriented query API with configurable, automatic storage persistence. Ideal for client-side applications, fast prototyping, and offlining data.

0 KB Zero Dependencies
100% Fluent Callbacks
MIT Open Source License
app.js
const qwery = new Qwery({
    name: "app"
}).create();

qwery
    .query("users")
    .add({
        id: qwery.uuid(),
        name: "John"
    });

const users = qwery
    .query("users")
    .where(x => x.name.startsWith("J"))
    .orderBy(x => x.name)
    .get();

Why developers choose Qwery.js

Direct browser APIs like LocalStorage require manual parsing, updating, and serialization overhead. Qwery acts as an in-memory document caching layers with transparent persistence.

Manual Web Storage API Code

Painful deserialization steps, string arrays to manage, filter callbacks done manually on non-cached entities. No direct sorting helpers.

// High risk of data mutations, crashes on invalid JSON
const raw = localStorage.getItem("app_users");
let users = raw ? JSON.parse(raw) : [];

// Complex update logic
users = users.map(user => {
    if (user.id === 1) {
        return { ...user, active: true };
    }
    return user;
});

// Ordering needs manually written comparative logic
users.sort((a, b) => a.name.localeCompare(b.name));

localStorage.setItem("app_users", JSON.stringify(users));
⚠️ Manual parsing overhead • No transactional in-memory speed

With Qwery.js

Elegant declarative API with immediate in-memory responses. Persistent operations write back automatically with built-in cache synchronization.

// Seamless update and state execution
qwery
    .query("users")
    .update(x => x.id === 1, { active: true });

// Highly chainable sorting and selection 
const activeUsers = qwery
    .query("users")
    .where(x => x.active === true)
    .orderBy(x => x.name)
    .get();
✨ In-memory acceleration • Auto persistence • Chainable actions
Extremely Capable

Feature Overview

Fully equipped to handle fast prototyping or reliable client-side client data architectures.

Fluent Query Builder

Write high level query statements using pure ES6 callback functions instead of cryptic custom strings or mock SQL.

Flexible Storage

Seamlessly toggle storage backends. Target localStorage, sessionStorage, or customize.

Memory Cache

Queries read straight from an optimized active memory copy of your JSON store, preventing expensive physical read cycles.

CRUD Operations

Add records, query collections, bulk update matching models, slice lists, or selectively purge data arrays safely.

Zero Dependencies

No bloat, no complex node package dependency tree warnings. Copy a single script reference into any workspace.

Fast Performance

Because data operations happen in-memory first, read steps perform virtually instantly. Write cycles persist asynchronously.

MIT Licensed

Completely free for commercial and personal open-source projects. Maintain full ownership of your data code configurations.

Chainable API

Chain operations like filtering, sorting, skipping, and mapping gracefully into sleek, highly readable single-expression calls.

Interactive Playground

Try Qwery.js Live

Modify this real Javascript snippet on the right. Hit **"Run Query"** to execute it against the fully loaded in-browser database!

Available mock data schema:
• id (number)
• name (string)
• age (number)
• role (string)
Click "Run Query Expression" to see current database cache state...
Setup Guide

Quick Start Setup

Integrate Qwery.js into your web workflow in seconds without complex compilers, transpilers, or setups.

Step 1
1

Include Library

Add the lightweight script directly into your client HTML page.

<script src="qwery.js"></script>
Step 2
2

Initialization

Instantiate your workspace storage, enable tracking logs to debug faster.

const qwery = new Qwery({
    name: "app",
    log: true
}).create();
Step 3
3

Custom Storage Backend

Optionally route to Session Storage instead of default local persistence.

const qwery = new Qwery({
    name: "session",
    storage: sessionStorage
}).create();
Database CRUD Operations

Data Mutation Operations

Review complete operational signatures for adding, retrieving, modifying, and flushing datasets.

CREATE

Add Documents

Insert single objects or datasets arrays into a target collection cache space.

qwery
  .query("users")
  .add({
    id: qwery.uuid(),
    name: "John"
  });
READ ONE

Find Document

Locate the first single document matching callback parameters.

const user = qwery
  .query("users")
  .find(x => x.id === 1);
READ ALL

Query Filter

Query multiple documents satisfying evaluation conditions.

const users = qwery
  .query("users")
  .where(x => x.age > 18)
  .get();
UPDATE

Update Document

Target records dynamically, merging properties via callback execution.

qwery
  .query("users")
  .update(
    x => x.id === 1,
    { active: true }
  );
DELETE

Delete Documents

Remove matching elements, instantly updating local or session targets.

qwery
  .query("users")
  .delete(x => x.age < 18);
TRUNCATE

Clear collection

Purge entire dataset target contents while leaving storage instance keys safe.

qwery
  .query("users")
  .clear();
Query Methods

Fluent API Features

Explore every chainable helper method provided to filter, sort, slice, and verify JSON records.

where()

Filter list

Filters collection array items matches based on evaluation functions.

query("users")
.where(x => x.age > 21)

orderBy()

Sort Asc

Orders collection documents in ascending manner based on keys.

query("users")
.orderBy(x => x.lastName)

orderByDesc()

Sort Desc

Orders collection documents in descending manner based on keys.

query("users")
.orderByDesc(x => x.age)

distinct()

De-duplicate

Filters out records that return duplicate values on target selector criteria.

query("users")
.distinct(x => x.city)

select()

Projection

Maps fields, selecting only specific properties from parent entities.

query("users")
.select(x => ({ name: x.name }))

page()

Pagination

Slices lists smoothly based on page counts and page sizing inputs.

query("users")
.page(1, 10)

skip()

Skip index

Bypasses targeted counts of elements starting at the beginning.

query("users")
.skip(5)

take()

Limit size

Trims out results array leaving only targeted length of documents.

query("users")
.take(3)

first()

First object

Returns first collection entity, defaulting to null if array is empty.

query("users")
.first()

last()

Last object

Returns last collection entity, defaulting to null if array is empty.

query("users")
.last()

count()

Integer size

Returns length of the dataset array calculated instantly.

query("users")
.count()

any()

Exist check

Returns boolean stating if query array has any entities inside.

query("users")
.any()

empty()

Boolean check

Returns true if dataset length equals zero, otherwise false.

query("users")
.empty()
Storage Backends

Storage Provider Support

Qwery.js automatically syncs data out of local cache arrays straight back into persistence engines. Swap storage platforms at configuration init using default engines or build custom storage wrappers.

localStorage (Default)

Persistent across tab lifespans and device power restarts.

sessionStorage

Ideal for session data. Automatic flush once the user closes the page.

Custom Storage Adapter

Any plain object providing: getItem(), setItem(), removeItem()

customAdapter.js
// Implement custom mock storage provider interface
const myAdapter = {
    getItem: (key) => sessionStorage.getItem(key),
    setItem: (key, val) => sessionStorage.setItem(key, val),
    removeItem: (key) => sessionStorage.removeItem(key)
};

// Pass it safely at construction phase
const db = new Qwery({
    name: "secure_workspace",
    storage: myAdapter
}).create();
Specification Docs

API System Reference

Detailed technical documentation representing all core classes, method interfaces, parameter definitions, and returns.

Class: Qwery

Primary engine coordinator managing global workspaces, JSON mapping, and cache structures.

Method Name Parameters Return Type Description
create() - Qwery Primes physical memory caches, deserializing data back-ends or initializes key stores.
query(collection) collection: string|array QueryBuilder Initializes and returns a fluent QueryBuilder query channel for dataset array items.
json() - Object Exports complete internal in-memory schema states, dataset matrices, metadata logs.
truncate() - void Clears all dataset record entities, saving clean state representations back to storage keys.
reset() - Qwery Destroys database storage backend keys and uninstantiates current system values.
uuid() - string Utility method returning secure, unique cryptographic V4 string UUID values.
datasetExists(name) name: string boolean Returns boolean verifying if target collection dataset schemas exist currently.

Class: QueryBuilder

Dynamic wrapper coordinating callback processing loops, arrays, indexes, and mutations.

class="py-4 px-4 font-mono text-xs text-gray-500">func: Function
Method Name Parameters Return Type Description
add(data) data: Object|Array Object Inserts records, saves changes. Returns { affectedRows: number, qwery: Qwery }.
where(predicate) predicate: Function QueryBuilder Filters dataset workspace arrays based on validation query expressions.
find(predicate) predicate: Function Object|null Returns the first item matching predicate expression or returns null.
update(predicate, rawData) predicate: Function, rawData: Object Object Mutates target items, saves storage. Returns { affectedRows: number, qwery: Qwery }.
delete(predicate) predicate: Function Object Deletes matching records. Returns { affectedRows: number, qwery: Qwery }.
clear() - Object Purges collection, triggers save sync. Returns { affectedRows: number, qwery: Qwery }.
orderBy(selector) selector: Function QueryBuilder Sorts query arrays in ascending direction using returned comparator properties.
orderByDesc(selector) selector: Function QueryBuilder Sorts query arrays in descending direction using returned comparator properties.
distinct(selector) selector: Function QueryBuilder Filters out any records with matching duplicate values on selector attributes.
select(func) QueryBuilder Performs inline javascript array maps to project fields to custom shapes.
page(page, pageSize) page: number, pageSize: number QueryBuilder Extracts pagination arrays smoothly from selected query lists.
take(count) count: number QueryBuilder Trims workspace lists keeping targeted maximum element numbers.
skip(count) count: number QueryBuilder Slices datasets skipping first targeted integer count of elements.
first() - Object|null Extracts first array item, returning null if workspace contains no records.
last() - Object|null Extracts last array item, returning null if workspace contains no records.
count() - number Calculates and yields current query array count value instantly.
any() - boolean Verifies dataset state is populated. Returns true if count > 0.
empty() - boolean Verifies dataset states is empty. Returns true if count === 0.
get() - Array Materializes processing arrays, returning clean Javascript arrays of target matches.