Skip to main content

A powerful, database-agnostic ORM with multi-database support and type-safe code generation

Project description

FlashORM

A powerful, database-agnostic migration CLI tool built in Go with multi-database support, visual database editor (FlashORM Studio), and type-safe code generation for JavaScript/TypeScript.

โœจ Features

  • ๐ŸŽจ FlashORM Studio: Visual database editor with React-based schema visualization
  • ๐Ÿ—ƒ๏ธ Multi-Database Support: PostgreSQL, MySQL, SQLite
  • ๐Ÿ”„ Migration Management: Create, apply, and track migrations
  • ๐Ÿ”’ Safe Migration System: Transaction-based execution with automatic rollback
  • ๐Ÿ“ค Smart Export System: Multiple formats (JSON, CSV, SQLite)
  • ๐Ÿ”ง Type-Safe Code Generation: Generate fully typed JavaScript/TypeScript code
  • โšก Blazing Fast: 2.5x faster than Drizzle, 10x faster than Prisma
  • ๐Ÿ’ป Raw SQL Execution: Execute SQL files or inline queries
  • ๐ŸŽฏ Prisma-like Commands: Familiar CLI interface

๐Ÿ“Š Performance

FlashORM significantly outperforms popular ORMs in real-world scenarios:

Operation FlashORM SQLAlchemy
Insert 1000 Users 16ms 299ms
Insert 10 Cat + 5K Posts + 15K Comments 440ms 1333ms
Complex Query x500 1199ms 10627ms
Mixed Workload x1000 (75% read, 25% write) 248ms 645ms
Stress Test Simple Query x2000 338ms 984ms
TOTAL 2241ms 13888ms

๐Ÿš€ Installation

Install from PyPI (recommended):

pip install flashorm

๐Ÿ Quick Start

1. Initialize Project

flash init --postgresql  # or --mysql, --sqlite

This creates:

your-project/
โ”œโ”€โ”€ flash.config.json
โ”œโ”€โ”€ .env
โ””โ”€โ”€ db/
    โ”œโ”€โ”€ schema/
    โ”‚   โ””โ”€โ”€ schema.sql
    โ””โ”€โ”€ queries/
        โ””โ”€โ”€ users.sql

2. Configure Database

# .env file
DATABASE_URL=postgresql://user:password@localhost:5432/mydb

3. Define Schema

db/schema/schema.sql

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);

4. Write Queries

db/queries/users.sql

-- name: GetUser :one
SELECT id, name, email, created_at, updated_at FROM users
WHERE id = $1 LIMIT 1;

-- name: CreateUser :one
INSERT INTO users (name, email)
VALUES ($1, $2)
RETURNING id, name, email, created_at, updated_at;

-- name: ListUsers :many
SELECT id, name, email, created_at, updated_at FROM users
ORDER BY created_at DESC;

-- name: UpdateUser :one
UPDATE users
SET name = $2, email = $3, updated_at = NOW()
WHERE id = $1
RETURNING id, name, email, created_at, updated_at;

-- name: DeleteUser :exec
DELETE FROM users WHERE id = $1;

5. Create Migration

flash migrate "create users table"

6. Apply Migration

flash apply

7. Generate Type-Safe Code

flash gen

Generated Table Types (flash_gen/models.py)

# Code generated by FlashORM. DO NOT EDIT.

from dataclasses import dataclass
from typing import Optional, Literal
from datetime import datetime
from decimal import Decimal

@dataclass
class Users:
    id: int
    name: str
    email: str
    created_at: datetime
    updated_at: datetime

8. Use in Your Code

Async Example (default)

import asyncio
import asyncpg
import os
from flash_gen.database import new

DATABASE_URL = os.getenv('DATABASE_URL', 'postgresql://postgres:postgres@localhost:5432/FlashORM_test')

async def main():
    pool = await asyncpg.create_pool(DATABASE_URL)

    db = new(pool)

    newuser = await db.create_user('jack', 'jack@gmail.com')
    print('New user:', newuser)

    await pool.close()

if __name__ == '__main__':
    asyncio.run(main())

Sync Example (set "async": false in config)

import psycopg2
import os
from flash_gen.database import new

DATABASE_URL = os.getenv('DATABASE_URL', 'postgresql://postgres:postgres@localhost:5432/FlashORM_test')

def main():
    conn = psycopg2.connect(DATABASE_URL)

    db = new(conn)

    newuser = db.create_user('jack', 'jack@gmail.com')
    print('New user:', newuser)

    conn.close()

if __name__ == '__main__':
    main()

๐Ÿ“‹ All Commands

Visual Database Editor

# Launch FlashORM Studio (web-based database editor)
flash studio

# Launch on custom port
flash studio --port 3000

# Connect to any database directly
flash studio --db "postgresql://user:pass@localhost:5432/mydb"

# Launch without opening browser
flash studio --browser=false

Studio Features:

  • ๐Ÿ“Š Data Browser: View and edit table data with inline editing
  • ๐Ÿ’ป SQL Editor: Execute queries with CodeMirror syntax highlighting
  • ๐ŸŽจ Schema Visualization: Interactive database diagram with React + ReactFlow
  • ๐Ÿ” Search & Filter: Search across all tables
  • โšก Real-time Updates: See changes immediately

Project Setup

# Initialize new project
flash init --postgresql
flash init --mysql
flash init --sqlite

Migrations

# Create new migration
flash migrate "migration name"

# Create empty migration
flash migrate "custom migration" --empty

# Apply all pending migrations
flash apply

# Apply with force (skip confirmations)
flash apply --force

# Check migration status
flash status

Code Generation

# Generate type-safe code
flash gen

Schema Management

# Pull schema from existing database
flash pull

# Pull with backup
flash pull --backup

# Pull to custom file
flash pull --output custom-schema.sql

Database Export

# Export as JSON (default)
flash export
flash export --json

# Export as CSV
flash export --csv

# Export as SQLite
flash export --sqlite

Database Operations

# Reset database (destructive!)
flash reset

# Reset with force
flash reset --force

# Execute raw SQL file
flash raw script.sql
flash raw migrations/seed.sql

# Execute inline SQL query
flash raw -q "SELECT * FROM users WHERE active = true"
flash raw "SELECT COUNT(*) FROM orders"

# Force file mode
flash raw --file queries/complex.sql

Help & Info

# Launch FlashORM Studio
flash studio

# Show version
flash --version
flash -v

# Show help
flash --help
flash <command> --help

โš™๏ธ Configuration

flash.config.json

{
  "version": "2",
  "schema_path": "db/schema/schema.sql",
  "queries": "db/queries/",
  "migrations_path": "db/migrations",
  "export_path": "db/export",
  "database": {
    "provider": "postgresql",
    "url_env": "DATABASE_URL"
  },
  "gen": {
    
    "python": {
      "enabled": true,
      "async": false
    }
  }
}

Python Generation Options:

  • async: Set to true for async/await code generation (default), false for synchronous code generation.

๐ŸŽจ PostgreSQL ENUM Support

Schema with ENUMs

CREATE TYPE user_role AS ENUM ('admin', 'user', 'guest');

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    role user_role NOT NULL DEFAULT 'user'
);

๐Ÿ”’ Safe Migrations

Every migration runs in a transaction with automatic rollback on failure:

$ flash apply
๐Ÿ“ฆ Applying 2 migration(s)...
  [1/2] 20251103_create_users
      โœ… Applied
  [2/2] 20251103_add_email_index
      โœ… Applied
โœ… All migrations applied successfully

If a migration fails:

โŒ Failed at migration: 20251103_bad_migration
   Error: syntax error at or near "INVALID"
   Transaction rolled back. Fix the error and run 'flash apply' again.

๐Ÿ›ก๏ธ Conflict Detection

FlashORM automatically detects schema conflicts:

โš ๏ธ  Migration conflicts detected:
  - Table 'users' already exists
  - Column 'email' conflicts with existing column

Reset database to resolve conflicts? (y/n): y
Create export before applying? (y/n): y
๐Ÿ“ฆ Creating export...
โœ… Export created successfully
๐Ÿ”„ Resetting database and applying all migrations...

๐Ÿ“ค Export Formats

JSON Export

flash export --json
{
  "timestamp": "2025-11-03 16:30:00",
  "version": "1.0",
  "tables": {
    "users": [{ "id": 1, "name": "Alice", "email": "alice@example.com" }]
  }
}

CSV Export

flash export --csv

Creates directory with individual CSV files per table.

SQLite Export

flash export --sqlite

Creates portable .db file.

๐ŸŽจ FlashORM Studio

Launch the visual database editor:

flash studio

Open http://localhost:5555 (or your custom port)

Features:

1. Data Browser (/)

  • View all tables in sidebar
  • Click any table to view/edit data
  • Double-click cells for inline editing
  • Add/delete rows with intuitive modals
  • Pagination (50 rows per page)
  • Search across tables
  • Foreign key hints

2. SQL Editor (/sql)

  • Execute custom SQL queries
  • CodeMirror editor with syntax highlighting
  • Press Ctrl+Enter to run queries
  • Export results to CSV
  • Resizable split-pane interface
  • Query history

3. Schema Visualization (/schema)

  • Interactive database diagram
  • React + ReactFlow rendering
  • Automatic layout with Dagre algorithm
  • Drag and drop tables
  • Zoom and pan controls
  • Foreign key relationship arrows
  • MiniMap for navigation

๐Ÿ’ป Raw SQL Execution

Execute SQL files or inline queries:

# Execute SQL file
flash raw script.sql

# Execute inline query
flash raw -q "SELECT * FROM users LIMIT 10"

# Auto-detection (file if exists, otherwise query)
flash raw "SELECT COUNT(*) FROM orders"

Features:

  • โœ… Beautiful table output for SELECT queries
  • โœ… Multi-statement execution
  • โœ… Transaction support
  • โœ… Auto-detection of file vs query
  • โœ… Formatted error messages

Example Output:

$ flash raw -q "SELECT id, name, email FROM users LIMIT 3"

๐ŸŽฏ Database: postgresql

โšก Executing query...
โœ… Query executed successfully
๐Ÿ“Š 3 row(s) returned

โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ id โ”‚ name       โ”‚ email               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ Alice      โ”‚ alice@example.com   โ”‚
โ”‚ 2  โ”‚ Bob        โ”‚ bob@example.com     โ”‚
โ”‚ 3  โ”‚ Charlie    โ”‚ charlie@example.com โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

d

๐Ÿ“š Examples

Check out complete examples:

๐Ÿ› Troubleshooting

Bun Postinstall Blocked

bun pm trust flashorm

Binary Not Found

npm install -g flashorm --force

Database Connection Failed

Check your DATABASE_URL in .env file.

Studio Not Loading

Make sure port 5555 is not in use, or specify a different port:

flash studio --port 3000

๐Ÿ“– Documentation

๐ŸŒŸ Key Highlights

  • Visual Database Editor: Manage your database visually with FlashORM Studio
  • Raw SQL Support: Execute SQL files or queries directly from CLI
  • Type-Safe: Full TypeScript support with generated types
  • Fast: 2.5x-10x faster than popular ORMs
  • Multi-DB: PostgreSQL, MySQL, and SQLite support
  • Zero Config: Works out of the box with sensible defaults

๐Ÿ“„ License

MIT License - see LICENSE


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flashorm-2.4.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flashorm-2.4.0-py3-none-any.whl (7.6 MB view details)

Uploaded Python 3

File details

Details for the file flashorm-2.4.0.tar.gz.

File metadata

  • Download URL: flashorm-2.4.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for flashorm-2.4.0.tar.gz
Algorithm Hash digest
SHA256 1b1cebb0565c49d3f80ec3234fa2fccbc2c315438a1321b991e6c831c67399f8
MD5 519408c98e54830955d5dd0a15fc0c75
BLAKE2b-256 9f7969301740714ad7e65e8f89dbcb1a33de784ee9044db09b12a78ad15ebd17

See more details on using hashes here.

File details

Details for the file flashorm-2.4.0-py3-none-any.whl.

File metadata

  • Download URL: flashorm-2.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for flashorm-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6094aa2b063eb1a0fce3132ecbc7b72d8d2347b270d1760e14b151293b45623
MD5 c6be2f6955de57ccdc0ba812466d9118
BLAKE2b-256 72750a93bfbc9e2a13345fe27fb1794db3084df4544d64ffbac3c01fc79638ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page