@morphql/store
v0.1.43
Published
In-memory and persistent data store for morphql with SQL-like query support.
Maintainers
Readme
@morphql/store
A lightweight data store for MorphQL with a familiar SQL-like query interface. SELECT, INSERT, UPDATE, and DELETE statements are transpiled to MorphQL and executed against pluggable storage adapters.
Key Features
- 🗂️ SQL-like API: Query and mutate data with
SELECT,INSERT,UPDATE,DELETE. - 🔌 Pluggable Adapters: In-memory adapter for tests and runtime data, folder adapter for JSON-on-disk persistence.
- 🚀 Powered by MorphQL: Statements are transpiled to MorphQL and compiled to native JS for fast execution.
- 🔢 Autoincrement: Built-in
auto()/$autoplaceholders for numeric primary keys. - 🌐 Isomorphic Core: The in-memory adapter runs in both Node.js and the browser; the folder adapter is Node-only.
Installation
npm install @morphql/storeUsage
In-memory store
import { Store, MemoryAdapter } from '@morphql/store';
const store = new Store(new MemoryAdapter());
await store.query(`INSERT INTO users (id, name, age) VALUES (auto(), 'Alice', 30)`);
await store.query(`INSERT INTO users (id, name, age) VALUES (auto(), 'Bob', 17)`);
const adults = await store.query(`SELECT name FROM users WHERE age >= 18`);
// → [{ name: 'Alice' }]Persistent folder store (Node.js)
import { Store } from '@morphql/store';
import { FolderAdapter } from '@morphql/store/node';
const store = new Store(new FolderAdapter('./data', { pretty: true }));
await store.query(`UPDATE users SET status = 'active' WHERE age >= 18`);Each table is persisted as a JSON file inside the directory (e.g. ./data/users.json).
Learn More
License
MIT
