Skip to content

Latest commit

 

History

History
189 lines (151 loc) · 5.1 KB

README_SQLITE.md

File metadata and controls

189 lines (151 loc) · 5.1 KB

Node Editor with SQLite Backend

The node editor now uses SQLite database instead of hardcoded data.

Architecture

┌─────────────────┐      HTTP       ┌─────────────────┐      SQL      ┌─────────────────┐
│                 │  ──────────────> │                 │ ────────────> │                 │
│  node-editor    │   GET /api/     │   Flask API     │   SELECT *    │  SQLite DB      │
│  .html          │   components    │   (api.py)      │   FROM ...    │  (components    │
│  (Frontend)     │                 │   (Backend)     │               │  .db)           │
│                 │  <────────────── │                 │ <──────────── │                 │
└─────────────────┘      JSON       └─────────────────┘    Results    └─────────────────┘

Files

  • components.db.sql - Database schema and sample data
  • api.py - Flask API server
  • node-editor.html - Frontend (modified to fetch from API)
  • requirements.txt - Python dependencies
  • setup.sh - Setup script

Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Initialize Database

python3 api.py

This will automatically create components.db from the schema file.

3. Open Editor

Open node-editor.html in your browser (or use the local server):

python3 -m http.server 9999
# Then open: http://localhost:9999/node-editor.html

Database Schema

components table

Column Type Description
id INTEGER Primary key
name TEXT Component name (unique)
created_at TIMESTAMP Creation timestamp

parameters table

Column Type Description
id INTEGER Primary key
component_id INTEGER Foreign key to components
name TEXT Parameter name
datatype TEXT Data type (float, int, boolean, string)
default_value TEXT Default value
description TEXT Parameter description
options TEXT JSON array for dropdown options

API Endpoints

GET /api/components

Returns all components with their parameters.

Response:

[
  {
    "name": "darts",
    "parameters": [
      {
        "name": "x",
        "datatype": "float",
        "defaultValue": 0.0,
        "description": "X coordinate"
      },
      {
        "name": "y",
        "datatype": "float",
        "defaultValue": 0.0,
        "description": "Y coordinate"
      }
    ]
  }
]

Adding New Components

Option 1: Direct SQL

sqlite3 components.db
-- Add new component
INSERT INTO components (name) VALUES ('my_component');

-- Add parameters (replace component_id with actual ID)
INSERT INTO parameters (component_id, name, datatype, default_value, description)
VALUES (6, 'my_param', 'float', '1.0', 'My parameter description');

Option 2: Python Script

import sqlite3

conn = sqlite3.connect('components.db')
cursor = conn.cursor()

# Insert component
cursor.execute("INSERT INTO components (name) VALUES (?)", ('my_component',))
component_id = cursor.lastrowid

# Insert parameters
cursor.execute("""
    INSERT INTO parameters (component_id, name, datatype, default_value, description)
    VALUES (?, ?, ?, ?, ?)
""", (component_id, 'my_param', 'float', '1.0', 'My parameter'))

conn.commit()
conn.close()

Option 3: Edit components.db.sql and Reinitialize

Edit components.db.sql, then:

rm components.db
python3 api.py  # Will recreate from schema

Troubleshooting

"Failed to load components" error

  • Make sure Flask API is running: python3 api.py
  • Check console for errors
  • Verify API is accessible: curl http://localhost:5000/api/components

CORS errors

  • flask-cors should handle this automatically
  • If issues persist, check browser console

Database locked

  • Only one process can write to SQLite at a time
  • Close other connections to components.db

Development

View Database

sqlite3 components.db
sqlite> .tables
sqlite> SELECT * FROM components;
sqlite> .quit

Reset Database

rm components.db
python3 api.py

Check API

curl http://localhost:5000/api/components | jq

Production Notes

For production use, consider:

  • Use PostgreSQL/MySQL instead of SQLite for concurrent access
  • Add authentication to API
  • Add validation for component data
  • Add API endpoints for CREATE/UPDATE/DELETE operations
  • Use proper WSGI server (gunicorn/uwsgi) instead of Flask dev server

Migration from Hardcoded Data

The original hardcoded data has been migrated to SQLite:

  • 5 components (darts, linear_model, data_processor, evaluator, neural_network)
  • 13 total parameters
  • All data types supported (float, int, boolean, string with options)

Data is preserved and now editable via database!