absurder-sql 0.1.23

AbsurderSQL - SQLite + IndexedDB that's absurdly better than absurd-sql
Documentation
# AbsurderSQL Web Demo Guide

## What You're Looking At

The web demo (`examples/web_demo.html`) is a **fully interactive SQLite playground** running entirely in your browser.

## How to Run It

### 1. **Build for Web**
```bash
wasm-pack build --target web
```
Output:
```
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
    Finished `release` profile [optimized] target(s) in 0.08s
[INFO]: Installing wasm-bindgen...
[INFO]: Done in 0.32s
[INFO]: Your wasm pkg is ready to publish at /Users/nicholas.piesco/Downloads/DataSync/pkg.
```

### 2. **Start Web Server**
```bash
python3 -m http.server 8080 &
```
Output:
```
Serving HTTP on :: port 8080 (http://[::]:8080/) ...
```

### 2.5 **Kill the Web Server**
```bash
lsof -ti:8080 | xargs kill -9
```

### 3. **Open the Demo**
Navigate to: `http://localhost:8080/examples/web_demo.html`

### 4. **Connect to Database**
- You'll see a "Connect to Database" button
- Click it to initialize SQLite with IndexedDB backend
- Watch the console output show the connection process

### 5. **Try the Quick Actions** (Pre-made queries)

**Create Demo Table:**
```sql
CREATE TABLE demo_users (
    id INTEGER PRIMARY KEY, 
    name TEXT, 
    email TEXT, 
    created_at TEXT DEFAULT CURRENT_TIMESTAMP
);
```

**Insert Sample Data:**
```sql
INSERT INTO demo_users (name, email) 
VALUES ('John Doe', 'john@example.com');
```

**View All Users:**
```sql
SELECT * FROM demo_users ORDER BY id DESC;
```

**List Tables:**
```sql
SELECT name FROM sqlite_master WHERE type='table';
```

### 6. **Write Your Own SQL**
Type any SQL query in the textarea:
```sql
CREATE TABLE products (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    price REAL,
    stock INTEGER
);

INSERT INTO products VALUES (1, 'Laptop', 999.99, 10);
INSERT INTO products VALUES (2, 'Mouse', 29.99, 50);

SELECT * FROM products WHERE price > 50;
```

### 5. **See Real-Time Results**
- Query results appear in a formatted table
- Console shows execution logs
- Statistics update (queries executed, rows affected, execution time)

### 6. **Test Persistence**
1. Insert some data
2. Refresh the page
3. Reconnect to the database
4. Query the data - **it's still there!** (stored in IndexedDB)

## What Makes This Special

**[✓]** **No Backend** - Everything runs in the browser  
**[✓]** **Real SQLite** - Full SQL support with transactions  
**[✓]** **Persistent** - Data survives page refreshes (IndexedDB)  
**[✓]** **Fast** - Sub-millisecond queries  
**[✓]** **Type-Safe** - Proper data types (INTEGER, TEXT, REAL, BLOB)  
**[✓]** **Multi-Tab Ready** - Built-in coordination (leader election, write queuing, optimistic updates, metrics)  

## Features You Can Demo

### Basic Operations
- CREATE TABLE with constraints
- INSERT, UPDATE, DELETE
- SELECT with WHERE, ORDER BY, LIMIT

### Advanced SQL
- JOINs (INNER, LEFT, RIGHT)
- Aggregations (COUNT, SUM, AVG, MIN, MAX)
- GROUP BY and HAVING
- Subqueries
- Transactions (BEGIN, COMMIT, ROLLBACK)

### Real-World Scenarios
```sql
-- Create related tables
CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE orders (
    id INTEGER PRIMARY KEY, 
    customer_id INTEGER, 
    total REAL,
    FOREIGN KEY(customer_id) REFERENCES customers(id)
);

-- Insert data
INSERT INTO customers VALUES (1, 'Alice'), (2, 'Bob');
INSERT INTO orders VALUES (1, 1, 99.99), (2, 1, 149.50), (3, 2, 75.00);

-- Complex query
SELECT 
    c.name, 
    COUNT(o.id) as order_count, 
    SUM(o.total) as total_spent
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
GROUP BY c.id
ORDER BY total_spent DESC;
```

## Console Output

Watch the console for:
- ✓ Connection status
- ✓ Query execution time
- ✓ Rows affected
- ✓ Error messages (if any)
- ✓ Success confirmations

## Statistics Panel

Tracks:
- Total queries executed
- Total rows affected  
- Average execution time
- Tables created

## Browser DevTools

Open DevTools (F12) and check:
- **Application → IndexedDB** - See your data stored
- **Console** - View detailed logs
- **Network** - See WASM module loading

## Try These Demos

### 1. **Todo List**
```sql
CREATE TABLE todos (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    task TEXT NOT NULL,
    completed INTEGER DEFAULT 0,
    created_at TEXT DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO todos (task) VALUES 
    ('Learn AbsurderSQL'),
    ('Build an app'),
    ('Deploy to production');

SELECT * FROM todos WHERE completed = 0;
```

### 2. **Blog Posts**
```sql
CREATE TABLE posts (
    id INTEGER PRIMARY KEY,
    title TEXT,
    content TEXT,
    views INTEGER DEFAULT 0,
    published_at TEXT
);

INSERT INTO posts VALUES 
    (1, 'Getting Started', 'Welcome to my blog...', 100, '2024-01-01'),
    (2, 'Advanced Tips', 'Here are some tips...', 250, '2024-01-15');

SELECT title, views FROM posts ORDER BY views DESC;
```

### 3. **E-commerce**
```sql
CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT, price REAL, category TEXT);
CREATE TABLE cart (id INTEGER PRIMARY KEY, product_id INTEGER, quantity INTEGER);

INSERT INTO products VALUES 
    (1, 'Laptop', 999.99, 'Electronics'),
    (2, 'Mouse', 29.99, 'Electronics'),
    (3, 'Desk', 299.99, 'Furniture');

INSERT INTO cart VALUES (1, 1, 1), (2, 2, 2);

SELECT p.name, p.price, c.quantity, (p.price * c.quantity) as subtotal
FROM cart c
JOIN products p ON c.product_id = p.id;
```

## This Proves

**[✓]** **Full SQLite compatibility** - All SQL features work  
**[✓]** **Browser persistence** - Data survives refreshes  
**[✓]** **Production-ready** - Fast, reliable, type-safe  
**[✓]** **Better than absurd-sql** - More features, better tested  

**Now you have a working demo to show anyone who asks "Does it really work?"**