🌐 Browser-Native ObjectQL - Running ObjectQL directly in the browser with zero backend required.
This example demonstrates how to use ObjectQL in a web browser with the Memory Driver for instant, client-side data management.
This demo shows that ObjectQL's core engine is truly universal - it runs seamlessly in browsers, Node.js, and Edge environments. No server required!
- ✅ In-Memory Data Storage - Fast client-side operations
- ✅ Live CRUD Operations - Create, Read, Update, Delete in real-time
- ✅ Interactive UI - See operations execute in the browser
- ✅ Browser Console Debugging - Full access to ObjectQL API
- ✅ Zero Dependencies - No backend, no build step (using CDN)
- ✅ TypeScript Support - Full type safety in browser
Simply open index.html in your browser:
# From the examples/browser-demo directory
open index.html
# or
python3 -m http.server 8080
# Then visit http://localhost:8080# Install dependencies
pnpm install
# Build the bundle
pnpm build
# Serve the demo
pnpm serveindex.html- Main demo page with interactive UIdemo.js- Browser-ready JavaScript using ObjectQLpackage.json- Build configuration (optional)vite.config.js- Vite bundler config (optional)
import { ObjectQL } from '@objectql/core';
import { MemoryDriver } from '@objectql/driver-memory';
// Initialize the memory driver
const driver = new MemoryDriver();
// Create ObjectQL instance
const app = new ObjectQL({
datasources: { default: driver }
});
// Define a schema
app.registerObject({
name: 'tasks',
fields: {
title: { type: 'text', required: true },
completed: { type: 'boolean', defaultValue: false },
priority: { type: 'select', options: ['low', 'medium', 'high'] }
}
});
await app.init();// Create a context
const ctx = app.createContext({ isSystem: true });
const tasks = ctx.object('tasks');
// Create
const task = await tasks.create({
title: 'Learn ObjectQL in Browser',
priority: 'high'
});
// Read
const allTasks = await tasks.find({});
// Update
await tasks.update(task.id, { completed: true });
// Delete
await tasks.delete(task.id);Open the browser console (F12) and interact with ObjectQL directly:
// The demo exposes a global 'app' object
console.log(window.app);
// Get a repository
const ctx = window.app.createContext({ isSystem: true });
const tasks = ctx.object('tasks');
// Try operations
await tasks.create({ title: 'Debug in console!', priority: 'high' });
const all = await tasks.find({});
console.log(all);This browser-native approach is perfect for:
- Prototyping - Build UIs without backend setup
- Offline Apps - PWAs with client-side data
- Educational Tools - Learn ObjectQL interactively
- Client-Side State Management - Alternative to Redux/MobX
- Browser Extensions - Data management in extensions
- Edge Computing - Deploy to Cloudflare Workers/Deno Deploy
- ⚡ Fastest performance
- 💾 Data lost on page refresh
- 🎯 Perfect for: Prototyping, temporary state
- 💾 Persists across page refreshes
- 📦 ~5-10MB storage limit
- 🎯 Perfect for: User preferences, offline apps
See ../browser-localstorage-demo for LocalStorage example.
ObjectQL's universal architecture makes this possible:
@objectql/types (Pure TypeScript - Browser ✅)
↓
@objectql/core (No Node.js deps - Browser ✅)
↓
@objectql/driver-memory (Zero deps - Browser ✅)
Key Design Principles:
- ❌ No
fs,path, or Node.js modules in core - ✅ Pure JavaScript/TypeScript logic
- ✅ Universal driver interface
- ✅ Works in any JavaScript runtime
- ✅ Chrome/Edge 90+
- ✅ Firefox 88+
- ✅ Safari 14+
- ✅ Opera 76+
Browser performance metrics (on modern desktop):
| Operation | Time (avg) | Records |
|---|---|---|
| Create | ~0.1ms | 1 |
| Find (no filter) | ~0.5ms | 1000 |
| Find (with filter) | ~1.5ms | 1000 |
| Update | ~0.1ms | 1 |
| Delete | ~0.1ms | 1 |
- Try the LocalStorage Demo for persistent data
- Build a Task Manager App using this foundation
- Explore Advanced Queries in the browser console
- Combine with React/Vue for full applications
- LocalStorage Demo - Persistent browser storage
- Task Manager Tutorial - Full application
- Memory Driver Docs - Driver details
MIT - Same as ObjectQL