Back
March 25, 2026

Live Web - Database

Author

Written by

Zuri Zuri

User Guide: How to Use the Database in Your Live Web Editor


This is NOT a traditional, complicated SQL database (no MySQL, PostgreSQL, or phpMyAdmin to configure).
It is a simple, fast, project-specific database called WebDB+ that works directly in your code and automatically syncs with the server's filesystem.

It gives you database-like functionality — without setup, servers, or configuration. Perfect for projects such as blogs, user lists, product galleries, public contact forms, and more.

1. How to Open the Database

1. Open any project in the editor.
2. At the top (tabs row) click the 🗄️ Database tab.
3. You will see:
  • Left sidebar: list of your tables
  • Right area: table data + management buttons

2. Creating Your First Table

1. Click the + Table button (top left).
2. Type a name (e.g., users, products, posts).
3. Click Create.
4. The table instantly appears in the sidebar with two default columns: id and updated_at.

3. Adding Columns

1. Click any table in the sidebar to view it.
2. Click the + Column button.
3. Type the column name (e.g., name, email, avatar_url).
4. Click Add.
→ The column appears immediately in the table.

4. Adding Rows (Data)

1. With a table open, click + Row.
2. A form appears with one field for every column.
3. Fill the fields (you can leave updated_at empty — it fills automatically).
4. Click Save.
→ The row is added and the table refreshes.

5. Editing & Deleting

  • Delete a row: Click the trash icon on the right of any row.
  • Delete a column: Click the small trash icon in the column header.
  • Delete entire table: Click the big red trash icon next to the table name (Warning: irreversible!).

6. Importing from SQL (Super Useful!)

You can easily generate tables by pasting normal CREATE TABLE statements:
1. Click the SQL button (or the big "Click to import SQL" area).
2. Paste your SQL (or select from the example dropdown).
3. Click Import.

Supported examples (ready to use):
  • Users table
  • Products table
  • Blog posts + comments
Note: The system automatically adds an updated_at column if it's missing!

7. Using the Database in Your Web Page (The Magic Part)

Your preview and live site automatically include the WebDB+ library behind the scenes. Just add JavaScript anywhere in your HTML or script.js file.

Full list of easy commands:

Get all data:
const data = await WebDB.select('tableName');
Add new row:
await WebDB.insert('tableName', { name: "John", age: 25 });
Update data (Example):
let users = await WebDB.select('users');
users = users.map(u => {
    if (u.id === 1) u.name = "New Name";
    return u;
});
// Save the updated list back to the server
await WebDB._setRaw('users', { columns: ['id','name','email','updated_at'], rows: users });

8. NEW: Handling File Uploads from Your Live Site

If you want visitors on your generated website to upload files (like profile pictures, resumes, or gallery images), you can use the built-in WebDB.uploadFile() method.

How it works:
  1. The user selects a file using an HTML <input type="file">.
  2. You pass that input to WebDB.uploadFile(inputElement).
  3. It securely uploads the file to your project's user_assets/ folder and returns the file path.
  4. You save that file path into your database using WebDB.insert().

9. Tips & Important Notes

  • Auto-saving: Data is saved securely to the server's disk every time you add/edit/delete.
  • Instant Updates: Works in the live preview immediately.
  • File Security: Uploaded files are automatically renamed to prevent overwrites, and strict file-type checking keeps your site safe.
  • No Complex Queries: You cannot run complex SQL queries like SELECT * WHERE age > 18. Instead, just do it in JavaScript: users.filter(u => u.age > 18).
  • Survives Refreshes: Tables and data are permanent and survive even if you close the browser or clear your cache.


10. OPTIONAL: Realtime Updates

Simple Realtime Example:

let lastCount = 0;
 
 async function startRealtime() {
     checkUpdates();
     setInterval
(checkUpdates, 5000);
 }
 
 async function checkUpdates() {
     const data = await WebDB.select('posts');
     const count = data ? data.length : 0;
 
     if (count !== lastCount) {
         lastCount = count;
         renderPosts(data);
     }
 }
 
 startRealtime();

Better Version:

let lastUpdated = 0;
 
 async function checkUpdates() {
     const data =
await WebDB.select('posts');
 
     if (!data || data.length === 0) return;
 
     const latest = Math.max(...data.map(d => new Date(d.updated_at).getTime()));
 
     if (latest !== lastUpdated) {
         lastUpdated = latest;
         renderPosts(data);
     }
 }

Quick Start Template:

<div id="feed">Loading...</div>
 
 <script>
 let last = 0;
 
 async function render() {
     const posts = await WebDB.select('posts');
     document.getElementById('feed').innerHTML =
         posts.map(p => `<p>${
p.text}</p>`).join('');
 }
 
 async function sync() {
     const posts = await WebDB.select('posts');
     if (!posts) return;
 
     if (posts.length !== last) {
         last = posts.length;
         render();
     }
 }
 
 setInterval(sync, 5000);
 render();
 </script>



Quick Start Template 1: User List

Copy and paste this into your HTML file to instantly display a list of users:
<h2>Our Users</h2>
<div id="user-list">Loading...</div>

<script>
async function showUsers() {
    const users = await WebDB.select('users');
    if (!users || users.length === 0) {
        document.getElementById('user-list').innerHTML = "<p>No users found.</p>";
        return;
    }
    document.getElementById('user-list').innerHTML = 
        users.map(u => `<p><b>${u.username}</b> - ${u.email}</p>`).join('');
}
showUsers();
</script>

Quick Start Template 2: Image Upload Form & Gallery

Copy and paste this to let users upload photos and display them instantly! (Make sure you created a table named gallery with a column named image_path first!)
<h2>Public Photo Gallery</h2>

<!-- The Upload Form -->
<input type="file" id="photoInput" accept="image/*">
<button onclick="uploadPhoto()" id="uploadBtn">Upload Photo</button>
<p id="statusMsg"></p>

<!-- The Gallery Display -->
<div id="gallery-grid" style="display: flex; gap: 10px; margin-top: 20px;"></div>

<script>
async function uploadPhoto() {
    const fileInput = document.getElementById('photoInput');
    const statusMsg = document.getElementById('statusMsg');
    const btn = document.getElementById('uploadBtn');

    if (fileInput.files.length === 0) {
        alert("Please select a file first!");
        return;
    }

    btn.innerText = "Uploading...";
    btn.disabled = true;

    // 1. Upload the file to the server
    const savedPath = await WebDB.uploadFile(fileInput);

    if (savedPath) {
        // 2. Save the path to the 'gallery' table
        await WebDB.insert('gallery', { image_path: savedPath });
        
        statusMsg.innerText = "Upload successful!";
        fileInput.value = ''; // Clear the input
        loadGallery(); // Refresh the images
    } else {
        statusMsg.innerText = "Upload failed. (Is your project set to Public?)";
    }

    btn.innerText = "Upload Photo";
    btn.disabled = false;
}

async function loadGallery() {
    const photos = await WebDB.select('gallery');
    const grid = document.getElementById('gallery-grid');
    
    if (!photos || photos.length === 0) {
        grid.innerHTML = "<p>No photos yet.</p>";
        return;
    }

    // 3. Display the images using the saved paths!
    grid.innerHTML = photos.map(photo => 
        `<img src="${photo.image_path}" style="width: 150px; height: 150px; object-fit: cover; border-radius: 8px;">`
    ).join('');
}

// Load gallery when page opens
loadGallery();
</script>

You now have a real working database and file upload system inside your website — no backend setup needed!

zuri

Zuri Zuri

@zuri

zuri zuri meeeeee