Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

ObjectQL Browser Demo

🌐 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.

Overview

This demo shows that ObjectQL's core engine is truly universal - it runs seamlessly in browsers, Node.js, and Edge environments. No server required!

Features Demonstrated

  • 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

Quick Start

Option 1: Direct Browser (No Build Required)

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

Option 2: With Build Step (For Production)

# Install dependencies
pnpm install

# Build the bundle
pnpm build

# Serve the demo
pnpm serve

Files

  • index.html - Main demo page with interactive UI
  • demo.js - Browser-ready JavaScript using ObjectQL
  • package.json - Build configuration (optional)
  • vite.config.js - Vite bundler config (optional)

Usage Examples

Basic Setup

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();

CRUD Operations in Browser

// 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);

Browser Debugging

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);

Use Cases

This browser-native approach is perfect for:

  1. Prototyping - Build UIs without backend setup
  2. Offline Apps - PWAs with client-side data
  3. Educational Tools - Learn ObjectQL interactively
  4. Client-Side State Management - Alternative to Redux/MobX
  5. Browser Extensions - Data management in extensions
  6. Edge Computing - Deploy to Cloudflare Workers/Deno Deploy

Persistence Options

1. Memory Driver (This Demo)

  • ⚡ Fastest performance
  • 💾 Data lost on page refresh
  • 🎯 Perfect for: Prototyping, temporary state

2. LocalStorage Driver

  • 💾 Persists across page refreshes
  • 📦 ~5-10MB storage limit
  • 🎯 Perfect for: User preferences, offline apps

See ../browser-localstorage-demo for LocalStorage example.

Architecture Notes

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

Browser Compatibility

  • ✅ Chrome/Edge 90+
  • ✅ Firefox 88+
  • ✅ Safari 14+
  • ✅ Opera 76+

Performance

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

Next Steps

  1. Try the LocalStorage Demo for persistent data
  2. Build a Task Manager App using this foundation
  3. Explore Advanced Queries in the browser console
  4. Combine with React/Vue for full applications

Related Examples

License

MIT - Same as ObjectQL