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 totruefor async/await code generation (default),falsefor 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b1cebb0565c49d3f80ec3234fa2fccbc2c315438a1321b991e6c831c67399f8
|
|
| MD5 |
519408c98e54830955d5dd0a15fc0c75
|
|
| BLAKE2b-256 |
9f7969301740714ad7e65e8f89dbcb1a33de784ee9044db09b12a78ad15ebd17
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6094aa2b063eb1a0fce3132ecbc7b72d8d2347b270d1760e14b151293b45623
|
|
| MD5 |
c6be2f6955de57ccdc0ba812466d9118
|
|
| BLAKE2b-256 |
72750a93bfbc9e2a13345fe27fb1794db3084df4544d64ffbac3c01fc79638ad
|