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
  • ๐ŸŽจ Enum Support: Full PostgreSQL ENUM support

๐Ÿ“Š Performance

Operation FlashORM Drizzle Prisma
Insert 1000 Users 158ms 224ms 230ms
Insert 10 Cat + 5K Posts + 15K Comments 2410ms 3028ms 3977ms
Complex Query x500 4071ms 12500ms 56322ms
Mixed Workload x1000 (75% read, 25% write) 186ms 1174ms 10863ms
Stress Test Simple Query x2000 122ms 160ms 223ms
TOTAL 6947ms 17149ms 71551ms

๐Ÿš€ Installation

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 Types (flash_gen/index.d.ts)

// Code generated by FlashORM. DO NOT EDIT.

export interface Users {
  id: number | null;
  name: string;
  email: string;
  created_at: Date;
  updated_at: Date;
}

export interface GetUserResult {
  id: number | null;
  name: string;
  email: string;
  created_at: Date;
  updated_at: Date;
}

export class Queries {
  constructor(db: any);

  getUser(id: number): Promise<GetUserResult | null>;
  createUser(name: string, email: string): Promise<Users | null>;
  listUsers(): Promise<Users[]>;
  updateUser(id: number, name: string, email: string): Promise<Users | null>;
  deleteUser(id: number): Promise<void>;
}

export function New(db: any): Queries;

8. Use in Your Code

index.ts

import { Pool } from 'pg';
import { New } from './flash_gen/database';

const DATABASE_URL = process.env.DATABASE_URL || 'postgresql://postgres:postgres@localhost:5432/mydb';

async function main() {
    const pool = new Pool({
        connectionString: DATABASE_URL,
    });
    
    const db = New(pool);
    
    // Create user - fully type-safe!
    const newUser = await db.createUser('Alice', 'alice@example.com');
    console.log('New user:', newUser);
    
    // Get user by ID
    const user = await db.getUser(newUser.id);
    console.log('Found user:', user);
    
    // List all users
    const users = await db.listUsers();
    console.log('All users:', users);
    
    // Update user
    const updated = await db.updateUser(newUser.id, 'Alice Smith', 'alice.smith@example.com');
    console.log('Updated user:', updated);
    
    await pool.end();
}

main().catch((err) => {
    console.error('Error:', err);
    process.exit(1);
});

๐Ÿ“‹ 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
  • ๐Ÿ“ค CSV Export: Export query results to CSV
  • ๐Ÿ” 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": {
    "js": {
      "enabled": true,
    }
  }
}

๐ŸŽจ 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'
);

Query with ENUM

-- name: GetUsersByRole :many
SELECT id, name, role FROM users
WHERE role = $1;

Generated TypeScript

export type UserRole = 'admin' | 'user' | 'guest';

export interface Users {
  id: number | null;
  name: string;
  role: UserRole;
}

๐Ÿ”’ 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

Tech Stack:

  • Backend: Go Fiber v2.52.9
  • Frontend: React 18.2.0, ReactFlow 12.8.4, CodeMirror 5.65.2
  • All assets embedded in single binary

๐Ÿ’ป 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 โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”ง Programmatic API

const flash = require('flashorm');

// Execute commands
flash.exec('status');
flash.exec('migrate "add users"');
flash.exec('apply');
flash.exec('studio'); // Launch Studio

// Get binary path
const binaryPath = flash.getBinaryPath();

๐Ÿ“š 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.0.8.tar.gz (11.9 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.0.8-py3-none-any.whl (7.5 MB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flashorm-2.0.8.tar.gz
Algorithm Hash digest
SHA256 e4b1b3e1be9424420009964e4ae2f0fbd25ef078b0ed2a8af9053f1a7c76a17b
MD5 a2314de4efbbbae0e301cf67d70f3467
BLAKE2b-256 c39f8f42d7a695dd403e07d0abafd7cf4b6d0d0be9e53542c4b820fbf7506cb8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for flashorm-2.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9459400cde496f20207e7b5525aa9f7bdf7b03cc4e53754844dee28d222f4463
MD5 56842a19b07f7d0859411010e51f4df8
BLAKE2b-256 a6ac959a8c47b14bf9b2c7ea68a2d43563a7532abfd761c78547f4dcad2d8581

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