flashorm 2.4.1-beta-dev → 2.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,632 +1,665 @@
1
- # FlashORM
2
-
3
- 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.
4
-
5
- ## ✨ Features
6
-
7
- - 🎨 **FlashORM Studio**: Visual database editor with React-based schema visualization
8
- - 🗃️ **Multi-Database Support**: PostgreSQL, MySQL, SQLite
9
- - 🔄 **Migration Management**: Create, apply, and track migrations
10
- - 🔒 **Safe Migration System**: Transaction-based execution with automatic rollback
11
- - 📤 **Smart Export System**: Multiple formats (JSON, CSV, SQLite)
12
- - 🔧 **Type-Safe Code Generation**: Generate fully typed JavaScript/TypeScript code
13
- - **Blazing Fast**: 2.5x faster than Drizzle, 10x faster than Prisma
14
- - 💻 **Raw SQL Execution**: Execute SQL files or inline queries
15
- - 🎯 **Prisma-like Commands**: Familiar CLI interface
16
- - 🎨 **Enum Support**: Full PostgreSQL ENUM support
17
-
18
- ## 📊 Performance
19
-
20
- | Operation | FlashORM | Drizzle | Prisma |
21
- | ------------------------------------------ | ---------- | ----------- | ----------- |
22
- | Insert 1000 Users | **149ms** | 224ms | 230ms |
23
- | Insert 10 Cat + 5K Posts + 15K Comments | **2410ms** | 3028ms | 3977ms |
24
- | Complex Query x500 | **3156ms** | 12500ms | 56322ms |
25
- | Mixed Workload x1000 (75% read, 25% write) | **186ms** | 1174ms | 10863ms |
26
- | Stress Test Simple Query x2000 | **79ms** | 160ms | 118ms |
27
- | **TOTAL** | **5980ms** | **17149ms** | **71510ms** |
28
-
29
- ## 🚀 Installation
30
-
31
- ```bash
32
- npm install -g flashorm
33
- ```
34
-
35
- The binary will be automatically downloaded on first use. The package:
36
- - Downloads only the binary for your platform (Linux, macOS, Windows)
37
- - ✅ Automatically cleans up binaries for other platforms
38
- - ✅ Works seamlessly with npm, yarn, pnpm, and bun
39
- - ✅ No postinstall scripts (no security warnings!)
40
-
41
- ### Bun Users
42
-
43
- No special configuration needed! The binary downloads on first `flash` command execution:
44
-
45
- ```bash
46
- bun add -g flashorm
47
- flash --version
48
- ```
49
-
50
- ## 🏁 Quick Start
51
-
52
- ### 1. Initialize Project
53
-
54
- ```bash
55
- flash init --postgresql # or --mysql, --sqlite
56
- ```
57
-
58
- This creates:
59
-
60
- ```
61
- your-project/
62
- ├── flash.config.json
63
- ├── .env
64
- └── db/
65
- ├── schema/
66
- │ └── schema.sql
67
- └── queries/
68
- └── users.sql
69
- ```
70
-
71
- ### 2. Configure Database
72
-
73
- ```bash
74
- # .env file
75
- DATABASE_URL=postgresql://user:password@localhost:5432/mydb
76
- ```
77
-
78
- ### 3. Define Schema
79
-
80
- **db/schema/schema.sql**
81
-
82
- ```sql
83
- CREATE TABLE users (
84
- id SERIAL PRIMARY KEY,
85
- name VARCHAR(255) NOT NULL,
86
- email VARCHAR(255) UNIQUE NOT NULL,
87
- created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
88
- updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
89
- );
90
- ```
91
-
92
- ### 4. Write Queries
93
-
94
- **db/queries/users.sql**
95
-
96
- ```sql
97
- -- name: GetUser :one
98
- SELECT id, name, email, created_at, updated_at FROM users
99
- WHERE id = $1 LIMIT 1;
100
-
101
- -- name: CreateUser :one
102
- INSERT INTO users (name, email)
103
- VALUES ($1, $2)
104
- RETURNING id, name, email, created_at, updated_at;
105
-
106
- -- name: ListUsers :many
107
- SELECT id, name, email, created_at, updated_at FROM users
108
- ORDER BY created_at DESC;
109
-
110
- -- name: UpdateUser :one
111
- UPDATE users
112
- SET name = $2, email = $3, updated_at = NOW()
113
- WHERE id = $1
114
- RETURNING id, name, email, created_at, updated_at;
115
-
116
- -- name: DeleteUser :exec
117
- DELETE FROM users WHERE id = $1;
118
- ```
119
-
120
- ### 5. Create Migration
121
-
122
- ```bash
123
- flash migrate "create users table"
124
- ```
125
-
126
- ### 6. Apply Migration
127
-
128
- ```bash
129
- flash apply
130
- ```
131
-
132
- ### 7. Generate Type-Safe Code
133
-
134
- ```bash
135
- flash gen
136
- ```
137
-
138
- **Generated Types (flash_gen/index.d.ts)**
139
-
140
- ```typescript
141
- // Code generated by FlashORM. DO NOT EDIT.
142
-
143
- export interface Users {
144
- id: number | null;
145
- name: string;
146
- email: string;
147
- created_at: Date;
148
- updated_at: Date;
149
- }
150
-
151
- export interface GetUserResult {
152
- id: number | null;
153
- name: string;
154
- email: string;
155
- created_at: Date;
156
- updated_at: Date;
157
- }
158
-
159
- export class Queries {
160
- constructor(db: any);
161
-
162
- getUser(id: number): Promise<GetUserResult | null>;
163
- createUser(name: string, email: string): Promise<Users | null>;
164
- listUsers(): Promise<Users[]>;
165
- updateUser(id: number, name: string, email: string): Promise<Users | null>;
166
- deleteUser(id: number): Promise<void>;
167
- }
168
-
169
- export function New(db: any): Queries;
170
- ```
171
-
172
- ### 8. Use in Your Code
173
-
174
- **index.ts**
175
-
176
- ```typescript
177
- import { Pool } from "pg";
178
- import { New } from "./flash_gen/database";
179
-
180
- const DATABASE_URL =
181
- process.env.DATABASE_URL ||
182
- "postgresql://postgres:postgres@localhost:5432/mydb";
183
-
184
- async function main() {
185
- const pool = new Pool({
186
- connectionString: DATABASE_URL,
187
- });
188
-
189
- const db = New(pool);
190
-
191
- // Create user - fully type-safe!
192
- const newUser = await db.createUser("Alice", "alice@example.com");
193
- console.log("New user:", newUser);
194
-
195
- // Get user by ID
196
- const user = await db.getUser(newUser.id);
197
- console.log("Found user:", user);
198
-
199
- // List all users
200
- const users = await db.listUsers();
201
- console.log("All users:", users);
202
-
203
- // Update user
204
- const updated = await db.updateUser(
205
- newUser.id,
206
- "Alice Smith",
207
- "alice.smith@example.com"
208
- );
209
- console.log("Updated user:", updated);
210
-
211
- await pool.end();
212
- }
213
-
214
- main().catch((err) => {
215
- console.error("Error:", err);
216
- process.exit(1);
217
- });
218
- ```
219
-
220
- ## 📋 All Commands
221
-
222
- ### Visual Database Editor
223
-
224
- ```bash
225
- # Launch FlashORM Studio (web-based database editor)
226
- flash studio
227
-
228
- # Launch on custom port
229
- flash studio --port 3000
230
-
231
- # Connect to any database directly
232
- flash studio --db "postgresql://user:pass@localhost:5432/mydb"
233
-
234
- # Launch without opening browser
235
- flash studio --browser=false
236
- ```
237
-
238
- **Studio Features:**
239
-
240
- - 📊 **Data Browser**: View and edit table data with inline editing
241
- - 💻 **SQL Editor**: Execute queries with CodeMirror syntax highlighting
242
- - 🎨 **Schema Visualization**: Interactive database diagram with React + ReactFlow
243
- - 📤 **CSV Export**: Export query results to CSV
244
- - 🔍 **Search & Filter**: Search across all tables
245
- - **Real-time Updates**: See changes immediately
246
-
247
- ### Project Setup
248
-
249
- ```bash
250
- # Initialize new project
251
- flash init --postgresql
252
- flash init --mysql
253
- flash init --sqlite
254
- ```
255
-
256
- ### Migrations
257
-
258
- ```bash
259
- # Create new migration
260
- flash migrate "migration name"
261
-
262
- # Create empty migration
263
- flash migrate "custom migration" --empty
264
-
265
- # Apply all pending migrations
266
- flash apply
267
-
268
- # Apply with force (skip confirmations)
269
- flash apply --force
270
-
271
- # Check migration status
272
- flash status
273
- ```
274
-
275
- ### Code Generation
276
-
277
- ```bash
278
- # Generate type-safe code
279
- flash gen
280
- ```
281
-
282
- ### Schema Management
283
-
284
- ```bash
285
- # Pull schema from existing database
286
- flash pull
287
-
288
- # Pull with backup
289
- flash pull --backup
290
-
291
- # Pull to custom file
292
- flash pull --output custom-schema.sql
293
- ```
294
-
295
- ### Database Export
296
-
297
- ```bash
298
- # Export as JSON (default)
299
- flash export
300
- flash export --json
301
-
302
- # Export as CSV
303
- flash export --csv
304
-
305
- # Export as SQLite
306
- flash export --sqlite
307
- ```
308
-
309
- ### Database Operations
310
-
311
- ```bash
312
- # Reset database (destructive!)
313
- flash reset
314
-
315
- # Reset with force
316
- flash reset --force
317
-
318
- # Execute raw SQL file
319
- flash raw script.sql
320
- flash raw migrations/seed.sql
321
-
322
- # Execute inline SQL query
323
- flash raw -q "SELECT * FROM users WHERE active = true"
324
- flash raw "SELECT COUNT(*) FROM orders"
325
-
326
- # Force file mode
327
- flash raw --file queries/complex.sql
328
- ```
329
-
330
- ### Help & Info
331
-
332
- ```bash
333
- # Launch FlashORM Studio
334
- flash studio
335
-
336
- # Show version
337
- flash --version
338
- flash -v
339
-
340
- # Show help
341
- flash --help
342
- flash <command> --help
343
- ```
344
-
345
- ## ⚙️ Configuration
346
-
347
- **flash.config.json**
348
-
349
- ```json
350
- {
351
- "version": "2",
352
- "schema_path": "db/schema/schema.sql",
353
- "queries": "db/queries/",
354
- "migrations_path": "db/migrations",
355
- "export_path": "db/export",
356
- "database": {
357
- "provider": "postgresql",
358
- "url_env": "DATABASE_URL"
359
- },
360
- "gen": {
361
- "js": {
362
- "enabled": true
363
- }
364
- }
365
- }
366
- ```
367
-
368
- ## 🎨 PostgreSQL ENUM Support
369
-
370
- **Schema with ENUMs**
371
-
372
- ```sql
373
- CREATE TYPE user_role AS ENUM ('admin', 'user', 'guest');
374
-
375
- CREATE TABLE users (
376
- id SERIAL PRIMARY KEY,
377
- name VARCHAR(255) NOT NULL,
378
- role user_role NOT NULL DEFAULT 'user'
379
- );
380
- ```
381
-
382
- **Query with ENUM**
383
-
384
- ```sql
385
- -- name: GetUsersByRole :many
386
- SELECT id, name, role FROM users
387
- WHERE role = $1;
388
- ```
389
-
390
- **Generated TypeScript**
391
-
392
- ```typescript
393
- export type UserRole = "admin" | "user" | "guest";
394
-
395
- export interface Users {
396
- id: number | null;
397
- name: string;
398
- role: UserRole;
399
- }
400
- ```
401
-
402
- ## 🔒 Safe Migrations
403
-
404
- Every migration runs in a transaction with automatic rollback on failure:
405
-
406
- ```bash
407
- $ flash apply
408
- 📦 Applying 2 migration(s)...
409
- [1/2] 20251103_create_users
410
- Applied
411
- [2/2] 20251103_add_email_index
412
- ✅ Applied
413
- ✅ All migrations applied successfully
414
- ```
415
-
416
- If a migration fails:
417
-
418
- ```bash
419
- Failed at migration: 20251103_bad_migration
420
- Error: syntax error at or near "INVALID"
421
- Transaction rolled back. Fix the error and run 'flash apply' again.
422
- ```
423
-
424
- ## 🛡️ Conflict Detection
425
-
426
- FlashORM automatically detects schema conflicts:
427
-
428
- ```bash
429
- ⚠️ Migration conflicts detected:
430
- - Table 'users' already exists
431
- - Column 'email' conflicts with existing column
432
-
433
- Reset database to resolve conflicts? (y/n): y
434
- Create export before applying? (y/n): y
435
- 📦 Creating export...
436
- ✅ Export created successfully
437
- 🔄 Resetting database and applying all migrations...
438
- ```
439
-
440
- ## 📤 Export Formats
441
-
442
- ### JSON Export
443
-
444
- ```bash
445
- flash export --json
446
- ```
447
-
448
- ```json
449
- {
450
- "timestamp": "2025-11-03 16:30:00",
451
- "version": "1.0",
452
- "tables": {
453
- "users": [{ "id": 1, "name": "Alice", "email": "alice@example.com" }]
454
- }
455
- }
456
- ```
457
-
458
- ### CSV Export
459
-
460
- ```bash
461
- flash export --csv
462
- ```
463
-
464
- Creates directory with individual CSV files per table.
465
-
466
- ### SQLite Export
467
-
468
- ```bash
469
- flash export --sqlite
470
- ```
471
-
472
- Creates portable `.db` file.
473
-
474
- ## 🎨 FlashORM Studio
475
-
476
- Launch the visual database editor:
477
-
478
- ```bash
479
- flash studio
480
- ```
481
-
482
- Open http://localhost:5555 (or your custom port)
483
-
484
- **Features:**
485
-
486
- ### 1. Data Browser (`/`)
487
-
488
- - View all tables in sidebar
489
- - Click any table to view/edit data
490
- - Double-click cells for inline editing
491
- - Add/delete rows with intuitive modals
492
- - Pagination (50 rows per page)
493
- - Search across tables
494
- - Foreign key hints
495
-
496
- ### 2. SQL Editor (`/sql`)
497
-
498
- - Execute custom SQL queries
499
- - CodeMirror editor with syntax highlighting
500
- - Press Ctrl+Enter to run queries
501
- - Export results to CSV
502
- - Resizable split-pane interface
503
- - Query history
504
-
505
- ### 3. Schema Visualization (`/schema`)
506
-
507
- - Interactive database diagram
508
- - React + ReactFlow rendering
509
- - Automatic layout with Dagre algorithm
510
- - Drag and drop tables
511
- - Zoom and pan controls
512
- - Foreign key relationship arrows
513
- - MiniMap for navigation
514
-
515
- **Tech Stack:**
516
-
517
- - Backend: Go Fiber v2.52.9
518
- - Frontend: React 18.2.0, ReactFlow 12.8.4, CodeMirror 5.65.2
519
- - All assets embedded in single binary
520
-
521
- ## 💻 Raw SQL Execution
522
-
523
- Execute SQL files or inline queries:
524
-
525
- ```bash
526
- # Execute SQL file
527
- flash raw script.sql
528
-
529
- # Execute inline query
530
- flash raw -q "SELECT * FROM users LIMIT 10"
531
-
532
- # Auto-detection (file if exists, otherwise query)
533
- flash raw "SELECT COUNT(*) FROM orders"
534
- ```
535
-
536
- **Features:**
537
-
538
- - Beautiful table output for SELECT queries
539
- - ✅ Multi-statement execution
540
- - Transaction support
541
- - Auto-detection of file vs query
542
- - Formatted error messages
543
-
544
- **Example Output:**
545
-
546
- ```bash
547
- $ flash raw -q "SELECT id, name, email FROM users LIMIT 3"
548
-
549
- 🎯 Database: postgresql
550
-
551
- Executing query...
552
- Query executed successfully
553
- 📊 3 row(s) returned
554
-
555
- ┌────┬────────────┬─────────────────────┐
556
- id name │ email │
557
- ├────┼────────────┼─────────────────────┤
558
- │ 1 │ Alice │ alice@example.com │
559
- 2 │ Bob │ bob@example.com │
560
- 3 │ Charlie │ charlie@example.com │
561
- └────┴────────────┴─────────────────────┘
562
- ```
563
-
564
- ## 🔧 Programmatic API
565
-
566
- ```javascript
567
- const flash = require("flashorm");
568
-
569
- // Execute commands
570
- flash.exec("status");
571
- flash.exec('migrate "add users"');
572
- flash.exec("apply");
573
- flash.exec("studio"); // Launch Studio
574
-
575
- // Get binary path
576
- const binaryPath = flash.getBinaryPath();
577
- ```
578
-
579
- ## 📚 Examples
580
-
581
- Check out complete examples:
582
-
583
- - [TypeScript Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/ts)
584
- - [Go Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/go)
585
-
586
- ## 🐛 Troubleshooting
587
-
588
- ### Bun Postinstall Blocked
589
-
590
- ```bash
591
- bun pm trust flashorm
592
- ```
593
-
594
- ### Binary Not Found
595
-
596
- ```bash
597
- npm install -g flashorm --force
598
- ```
599
-
600
- ### Database Connection Failed
601
-
602
- Check your `DATABASE_URL` in `.env` file.
603
-
604
- ### Studio Not Loading
605
-
606
- Make sure port 5555 is not in use, or specify a different port:
607
-
608
- ```bash
609
- flash studio --port 3000
610
- ```
611
-
612
- ## 📖 Documentation
613
-
614
- - [Full Documentation](https://github.com/Lumos-Labs-HQ/flash)
615
- - [How It Works](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/HOW_IT_WORKS.md)
616
- - [Technology Stack](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/TECHNOLOGY_STACK.md)
617
- - [Contributing](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/CONTRIBUTING.md)
618
-
619
- ## 🌟 Key Highlights
620
-
621
- - **Visual Database Editor**: Manage your database visually with FlashORM Studio
622
- - **Raw SQL Support**: Execute SQL files or queries directly from CLI
623
- - **Type-Safe**: Full TypeScript support with generated types
624
- - **Fast**: 2.5x-10x faster than popular ORMs
625
- - **Multi-DB**: PostgreSQL, MySQL, and SQLite support
626
- - **Zero Config**: Works out of the box with sensible defaults
627
-
628
- ## 📄 License
629
-
630
- MIT License - see [LICENSE](https://github.com/Lumos-Labs-HQ/flash/blob/main/LICENSE)
631
-
632
- ---
1
+ # FlashORM
2
+
3
+ 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.
4
+
5
+ ## ✨ Features
6
+
7
+ - 🗃️ **Multi-Database Support**: PostgreSQL, MySQL, SQLite, ScyllaDB / Cassandra, ClickHouse
8
+ - 🔄 **Migration Management**: Create, apply, rollback, and track migrations
9
+ - 🌿 **Schema Branching**: Git-like branching for database schemas
10
+ - 🌱 **Database Seeding**: Generate realistic fake data for development
11
+ - 🔒 **Safe Migration System**: Transaction-based execution with automatic rollback
12
+ - 📤 **Smart Export System**: Multiple formats (JSON, CSV, SQLite)
13
+ - 🔧 **Type-Safe Code Generation**: Generate fully typed JavaScript/TypeScript code
14
+ - **Blazing Fast**: 2.8x faster than Drizzle, 11.9x faster than Prisma
15
+ - 💻 **Raw SQL Execution**: Execute SQL files or inline queries
16
+ - 🎯 **Prisma-like Commands**: Familiar CLI interface
17
+ - 🎨 **Enum Support**: Full PostgreSQL ENUM support with generated union types
18
+
19
+ ## 📊 Performance
20
+
21
+ | Operation | FlashORM | Drizzle | Prisma |
22
+ | ------------------------------------------ | ---------- | ----------- | ----------- |
23
+ | Insert 1000 Users | **149ms** | 224ms | 230ms |
24
+ | Insert 10 Cat + 5K Posts + 15K Comments | **2410ms** | 3028ms | 3977ms |
25
+ | Complex Query x500 | **3156ms** | 12500ms | 56322ms |
26
+ | Mixed Workload x1000 (75% read, 25% write) | **186ms** | 1174ms | 10863ms |
27
+ | Stress Test Simple Query x2000 | **79ms** | 160ms | 118ms |
28
+ | **TOTAL** | **5980ms** | **17149ms** | **71510ms** |
29
+
30
+ ## 🚀 Installation
31
+
32
+ ```bash
33
+ npm install -g flashorm
34
+ ```
35
+
36
+ The binary will be automatically downloaded on first use. The package:
37
+ - ✅ Downloads only the binary for your platform (Linux, macOS, Windows)
38
+ - ✅ Automatically cleans up binaries for other platforms
39
+ - ✅ Works seamlessly with npm, yarn, pnpm, and bun
40
+ - ✅ No postinstall scripts (no security warnings!)
41
+
42
+ ### Bun Users
43
+
44
+ No special configuration needed! The binary downloads on first `flash` command execution:
45
+
46
+ ```bash
47
+ bun add -g flashorm
48
+ flash --version
49
+ ```
50
+
51
+ ## 🏁 Quick Start
52
+
53
+ ### 1. Initialize Project
54
+
55
+ ```bash
56
+ flash init --postgresql # or --mysql, --sqlite, --scylla, --clickhouse
57
+ ```
58
+
59
+ This creates:
60
+
61
+ ```
62
+ your-project/
63
+ ├── flash.toml
64
+ ├── .env
65
+ └── db/
66
+ ├── schema/
67
+ └── schema.sql
68
+ └── queries/
69
+ └── users.sql
70
+ ```
71
+
72
+ ### 2. Configure Database
73
+
74
+ ```bash
75
+ # .env file
76
+ DATABASE_URL=postgresql://user:password@localhost:5432/mydb
77
+ ```
78
+
79
+ ### 3. Define Schema
80
+
81
+ **db/schema/schema.sql**
82
+
83
+ ```sql
84
+ CREATE TABLE users (
85
+ id SERIAL PRIMARY KEY,
86
+ name VARCHAR(255) NOT NULL,
87
+ email VARCHAR(255) UNIQUE NOT NULL,
88
+ created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
89
+ updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
90
+ );
91
+ ```
92
+
93
+ ### 4. Write Queries
94
+
95
+ **db/queries/users.sql**
96
+
97
+ ```sql
98
+ -- name: GetUser :one
99
+ SELECT id, name, email, created_at, updated_at FROM users
100
+ WHERE id = $1 LIMIT 1;
101
+
102
+ -- name: CreateUser :one
103
+ INSERT INTO users (name, email)
104
+ VALUES ($1, $2)
105
+ RETURNING id, name, email, created_at, updated_at;
106
+
107
+ -- name: ListUsers :many
108
+ SELECT id, name, email, created_at, updated_at FROM users
109
+ ORDER BY created_at DESC;
110
+
111
+ -- name: UpdateUser :one
112
+ UPDATE users
113
+ SET name = $2, email = $3, updated_at = NOW()
114
+ WHERE id = $1
115
+ RETURNING id, name, email, created_at, updated_at;
116
+
117
+ -- name: DeleteUser :exec
118
+ DELETE FROM users WHERE id = $1;
119
+ ```
120
+
121
+ ### 5. Create Migration
122
+
123
+ ```bash
124
+ flash migrate "create users table"
125
+ ```
126
+
127
+ ### 6. Apply Migration
128
+
129
+ ```bash
130
+ flash apply
131
+ ```
132
+
133
+ ### 7. Generate Type-Safe Code
134
+
135
+ ```bash
136
+ flash gen
137
+ ```
138
+
139
+ **Generated Types (flash_gen/index.d.ts)**
140
+
141
+ ```typescript
142
+ // Code generated by FlashORM. DO NOT EDIT.
143
+
144
+ export interface Users {
145
+ id: number | null;
146
+ name: string;
147
+ email: string;
148
+ created_at: Date;
149
+ updated_at: Date;
150
+ }
151
+
152
+ export interface GetUserResult {
153
+ id: number | null;
154
+ name: string;
155
+ email: string;
156
+ created_at: Date;
157
+ updated_at: Date;
158
+ }
159
+
160
+ export class Queries {
161
+ constructor(db: any);
162
+
163
+ getUser(id: number): Promise<GetUserResult | null>;
164
+ createUser(name: string, email: string): Promise<Users | null>;
165
+ listUsers(): Promise<Users[]>;
166
+ updateUser(id: number, name: string, email: string): Promise<Users | null>;
167
+ deleteUser(id: number): Promise<void>;
168
+ }
169
+
170
+ export function New(db: any): Queries;
171
+ ```
172
+
173
+ ### 8. Use in Your Code
174
+
175
+ **index.ts**
176
+
177
+ ```typescript
178
+ import { Pool } from "pg";
179
+ import { New } from "./flash_gen/database";
180
+
181
+ const DATABASE_URL =
182
+ process.env.DATABASE_URL ||
183
+ "postgresql://postgres:postgres@localhost:5432/mydb";
184
+
185
+ async function main() {
186
+ const pool = new Pool({
187
+ connectionString: DATABASE_URL,
188
+ });
189
+
190
+ const db = New(pool);
191
+
192
+ // Create user - fully type-safe!
193
+ const newUser = await db.createUser("Alice", "alice@example.com");
194
+ console.log("New user:", newUser);
195
+
196
+ // Get user by ID
197
+ const user = await db.getUser(newUser.id);
198
+ console.log("Found user:", user);
199
+
200
+ // List all users
201
+ const users = await db.listUsers();
202
+ console.log("All users:", users);
203
+
204
+ // Update user
205
+ const updated = await db.updateUser(
206
+ newUser.id,
207
+ "Alice Smith",
208
+ "alice.smith@example.com"
209
+ );
210
+ console.log("Updated user:", updated);
211
+
212
+ await pool.end();
213
+ }
214
+
215
+ main().catch((err) => {
216
+ console.error("Error:", err);
217
+ process.exit(1);
218
+ });
219
+ ```
220
+
221
+ ## 📋 All Commands
222
+
223
+ ### Visual Database Editor
224
+
225
+ ```bash
226
+ # Launch FlashORM Studio (web-based database editor for PostgreSQL, MySQL, SQLite,
227
+ # ScyllaDB, ClickHouse, MongoDB, and Redis)
228
+ flash studio
229
+
230
+ # Launch on custom port
231
+ flash studio --port 3000
232
+
233
+ # Connect to any database directly
234
+ flash studio "postgresql://user:pass@localhost:5432/mydb"
235
+
236
+ # Launch without opening browser
237
+ flash studio --browser=false
238
+ ```
239
+
240
+ **Studio Features:**
241
+
242
+ - 📊 **Data Browser**: View and edit table data with inline editing
243
+ - 💻 **SQL Editor**: Execute queries with CodeMirror syntax highlighting
244
+ - 🎨 **Schema Visualization**: Interactive database diagram with React + ReactFlow
245
+ - 📤 **CSV Export**: Export query results to CSV
246
+ - 🔍 **Search & Filter**: Search across all tables
247
+ - **Real-time Updates**: See changes immediately
248
+
249
+ ### Project Setup
250
+
251
+ ```bash
252
+ # Initialize new project
253
+ flash init --postgresql
254
+ flash init --mysql
255
+ flash init --sqlite
256
+ flash init --scylla
257
+ flash init --clickhouse
258
+ ```
259
+
260
+ ### Migrations
261
+
262
+ ```bash
263
+ # Create new migration
264
+ flash migrate "migration name"
265
+
266
+ # Create empty migration
267
+ flash migrate "custom migration" --empty
268
+
269
+ # Apply all pending migrations
270
+ flash apply
271
+
272
+ # Apply with force (skip confirmations)
273
+ flash apply --force
274
+
275
+ # Check migration status
276
+ flash status
277
+ ```
278
+
279
+ ### Code Generation
280
+
281
+ ```bash
282
+ # Generate type-safe code
283
+ flash gen
284
+ ```
285
+
286
+ ### Schema Management
287
+
288
+ ```bash
289
+ # Pull schema from existing database
290
+ flash pull
291
+
292
+ # Pull with backup
293
+ flash pull --backup
294
+
295
+ # Pull to custom file
296
+ flash pull --output custom-schema.sql
297
+ ```
298
+
299
+ ### Database Export
300
+
301
+ ```bash
302
+ # Export as JSON (default)
303
+ flash export
304
+ flash export --json
305
+
306
+ # Export as CSV
307
+ flash export --csv
308
+
309
+ # Export as SQLite
310
+ flash export --sqlite
311
+ ```
312
+
313
+ ### Database Seeding
314
+
315
+ ```bash
316
+ # Seed all tables with default count
317
+ flash seed
318
+
319
+ # Seed with custom count
320
+ flash seed --count 100
321
+
322
+ # Seed specific tables with different counts
323
+ flash seed users:100 posts:500
324
+
325
+ # Truncate before seeding
326
+ flash seed --truncate --force
327
+ ```
328
+
329
+ ### Schema Branching
330
+
331
+ ```bash
332
+ # Create a feature branch
333
+ flash branch create feature/new-schema
334
+
335
+ # Switch between branches
336
+ flash checkout feature/new-schema
337
+ flash checkout main
338
+
339
+ # List branches
340
+ flash branch list
341
+
342
+ # Merge branches
343
+ flash branch merge feature/new-schema
344
+ ```
345
+
346
+ ### Database Operations
347
+
348
+ ```bash
349
+ # Reset database (destructive!)
350
+ flash reset
351
+
352
+ # Reset with force
353
+ flash reset --force
354
+
355
+ # Execute raw SQL file
356
+ flash raw script.sql
357
+ flash raw migrations/seed.sql
358
+
359
+ # Execute inline SQL query
360
+ flash raw -q "SELECT * FROM users WHERE active = true"
361
+ flash raw "SELECT COUNT(*) FROM orders"
362
+
363
+ # Force file mode
364
+ flash raw --file queries/complex.sql
365
+ ```
366
+
367
+ ### Help & Info
368
+
369
+ ```bash
370
+ # Launch FlashORM Studio
371
+ flash studio
372
+
373
+ # Show version
374
+ flash --version
375
+ flash -v
376
+
377
+ # Show help
378
+ flash --help
379
+ flash <command> --help
380
+ ```
381
+
382
+ ## ⚙️ Configuration
383
+
384
+ **flash.toml**
385
+
386
+ ```toml
387
+ version = "2"
388
+ schema_dir = "db/schema"
389
+ queries = "db/queries/"
390
+ migrations_path = "db/migrations"
391
+ export_path = "db/export"
392
+
393
+ [database]
394
+ provider = "postgresql"
395
+ url_env = "DATABASE_URL"
396
+
397
+ [gen.js]
398
+ enabled = true
399
+ ```
400
+
401
+ ## 🎨 PostgreSQL ENUM Support
402
+
403
+ **Schema with ENUMs**
404
+
405
+ ```sql
406
+ CREATE TYPE user_role AS ENUM ('admin', 'user', 'guest');
407
+
408
+ CREATE TABLE users (
409
+ id SERIAL PRIMARY KEY,
410
+ name VARCHAR(255) NOT NULL,
411
+ role user_role NOT NULL DEFAULT 'user'
412
+ );
413
+ ```
414
+
415
+ **Query with ENUM**
416
+
417
+ ```sql
418
+ -- name: GetUsersByRole :many
419
+ SELECT id, name, role FROM users
420
+ WHERE role = $1;
421
+ ```
422
+
423
+ **Generated TypeScript**
424
+
425
+ ```typescript
426
+ export type UserRole = "admin" | "user" | "guest";
427
+
428
+ export interface Users {
429
+ id: number | null;
430
+ name: string;
431
+ role: UserRole;
432
+ }
433
+ ```
434
+
435
+ ## 🔒 Safe Migrations
436
+
437
+ Every migration runs in a transaction with automatic rollback on failure:
438
+
439
+ ```bash
440
+ $ flash apply
441
+ 📦 Applying 2 migration(s)...
442
+ [1/2] 20251103_create_users
443
+ ✅ Applied
444
+ [2/2] 20251103_add_email_index
445
+ Applied
446
+ ✅ All migrations applied successfully
447
+ ```
448
+
449
+ If a migration fails:
450
+
451
+ ```bash
452
+ ❌ Failed at migration: 20251103_bad_migration
453
+ Error: syntax error at or near "INVALID"
454
+ Transaction rolled back. Fix the error and run 'flash apply' again.
455
+ ```
456
+
457
+ ## 🛡️ Conflict Detection
458
+
459
+ FlashORM automatically detects schema conflicts:
460
+
461
+ ```bash
462
+ ⚠️ Migration conflicts detected:
463
+ - Table 'users' already exists
464
+ - Column 'email' conflicts with existing column
465
+
466
+ Reset database to resolve conflicts? (y/n): y
467
+ Create export before applying? (y/n): y
468
+ 📦 Creating export...
469
+ Export created successfully
470
+ 🔄 Resetting database and applying all migrations...
471
+ ```
472
+
473
+ ## 📤 Export Formats
474
+
475
+ ### JSON Export
476
+
477
+ ```bash
478
+ flash export --json
479
+ ```
480
+
481
+ ```json
482
+ {
483
+ "timestamp": "2025-11-03 16:30:00",
484
+ "version": "1.0",
485
+ "tables": {
486
+ "users": [{ "id": 1, "name": "Alice", "email": "alice@example.com" }]
487
+ }
488
+ }
489
+ ```
490
+
491
+ ### CSV Export
492
+
493
+ ```bash
494
+ flash export --csv
495
+ ```
496
+
497
+ Creates directory with individual CSV files per table.
498
+
499
+ ### SQLite Export
500
+
501
+ ```bash
502
+ flash export --sqlite
503
+ ```
504
+
505
+ Creates portable `.db` file.
506
+
507
+ ## 🎨 FlashORM Studio
508
+
509
+ Launch the visual database editor:
510
+
511
+ ```bash
512
+ flash studio
513
+ ```
514
+
515
+ Open http://localhost:5555 (or your custom port)
516
+
517
+ **Features:**
518
+
519
+ ### 1. Data Browser (`/`)
520
+
521
+ - View all tables in sidebar
522
+ - Click any table to view/edit data
523
+ - Double-click cells for inline editing
524
+ - Add/delete rows with intuitive modals
525
+ - Pagination (50 rows per page)
526
+ - Search across tables
527
+ - Foreign key hints
528
+
529
+ ### 2. SQL Editor (`/sql`)
530
+
531
+ - Execute custom SQL queries
532
+ - CodeMirror editor with syntax highlighting
533
+ - Press Ctrl+Enter to run queries
534
+ - Export results to CSV
535
+ - Resizable split-pane interface
536
+ - Query history
537
+
538
+ ### 3. Schema Visualization (`/schema`)
539
+
540
+ - Interactive database diagram
541
+ - React + ReactFlow rendering
542
+ - Automatic layout with Dagre algorithm
543
+ - Drag and drop tables
544
+ - Zoom and pan controls
545
+ - Foreign key relationship arrows
546
+ - MiniMap for navigation
547
+
548
+ **Tech Stack:**
549
+
550
+ - Backend: Go Fiber v2.52.9
551
+ - Frontend: React 18.2.0, ReactFlow 12.8.4, CodeMirror 5.65.2
552
+ - All assets embedded in single binary
553
+
554
+ ## 💻 Raw SQL Execution
555
+
556
+ Execute SQL files or inline queries:
557
+
558
+ ```bash
559
+ # Execute SQL file
560
+ flash raw script.sql
561
+
562
+ # Execute inline query
563
+ flash raw -q "SELECT * FROM users LIMIT 10"
564
+
565
+ # Auto-detection (file if exists, otherwise query)
566
+ flash raw "SELECT COUNT(*) FROM orders"
567
+ ```
568
+
569
+ **Features:**
570
+
571
+ - Beautiful table output for SELECT queries
572
+ - ✅ Multi-statement execution
573
+ - Transaction support
574
+ - ✅ Auto-detection of file vs query
575
+ - Formatted error messages
576
+
577
+ **Example Output:**
578
+
579
+ ```bash
580
+ $ flash raw -q "SELECT id, name, email FROM users LIMIT 3"
581
+
582
+ 🎯 Database: postgresql
583
+
584
+ Executing query...
585
+ ✅ Query executed successfully
586
+ 📊 3 row(s) returned
587
+
588
+ ┌────┬────────────┬─────────────────────┐
589
+ │ id │ name │ email │
590
+ ├────┼────────────┼─────────────────────┤
591
+ 1 │ Alice │ alice@example.com │
592
+ │ 2 │ Bob │ bob@example.com │
593
+ │ 3 │ Charlie │ charlie@example.com │
594
+ └────┴────────────┴─────────────────────┘
595
+ ```
596
+
597
+ ## 🔧 Programmatic API
598
+
599
+ ```javascript
600
+ const flash = require("flashorm");
601
+
602
+ // Execute commands
603
+ flash.exec("status");
604
+ flash.exec('migrate "add users"');
605
+ flash.exec("apply");
606
+ flash.exec("studio"); // Launch Studio
607
+
608
+ // Get binary path
609
+ const binaryPath = flash.getBinaryPath();
610
+ ```
611
+
612
+ ## 📚 Examples
613
+
614
+ Check out complete examples:
615
+
616
+ - [TypeScript Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/ts)
617
+ - [Go Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/go)
618
+
619
+ ## 🐛 Troubleshooting
620
+
621
+ ### Bun Postinstall Blocked
622
+
623
+ ```bash
624
+ bun pm trust flashorm
625
+ ```
626
+
627
+ ### Binary Not Found
628
+
629
+ ```bash
630
+ npm install -g flashorm --force
631
+ ```
632
+
633
+ ### Database Connection Failed
634
+
635
+ Check your `DATABASE_URL` in `.env` file.
636
+
637
+ ### Studio Not Loading
638
+
639
+ Make sure port 5555 is not in use, or specify a different port:
640
+
641
+ ```bash
642
+ flash studio --port 3000
643
+ ```
644
+
645
+ ## 📖 Documentation
646
+
647
+ - [Full Documentation](https://github.com/Lumos-Labs-HQ/flash)
648
+ - [How It Works](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/HOW_IT_WORKS.md)
649
+ - [Technology Stack](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/TECHNOLOGY_STACK.md)
650
+ - [Contributing](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/CONTRIBUTING.md)
651
+
652
+ ## 🌟 Key Highlights
653
+
654
+ - **Visual Database Editor**: Manage your database visually with FlashORM Studio
655
+ - **Raw SQL Support**: Execute SQL files or queries directly from CLI
656
+ - **Type-Safe**: Full TypeScript support with generated types
657
+ - **Fast**: 2.8x-11.9x faster than popular ORMs
658
+ - **Multi-DB**: PostgreSQL, MySQL, SQLite, ScyllaDB, Cassandra, ClickHouse
659
+ - **Zero Config**: Works out of the box with sensible defaults
660
+
661
+ ## 📄 License
662
+
663
+ MIT License - see [LICENSE](https://github.com/Lumos-Labs-HQ/flash/blob/main/LICENSE)
664
+
665
+ ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flashorm",
3
- "version": "2.4.1-beta-dev",
3
+ "version": "2.4.6",
4
4
  "description": "A powerful, database-agnostic ORM with plugin-based architecture - Base CLI only",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -4,7 +4,7 @@ const https = require('https');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
 
7
- const VERSION = '2.4.1-beta-dev';
7
+ const VERSION = '2.4.6';
8
8
  const REPO = 'Lumos-Labs-HQ/flash';
9
9
 
10
10
  const platform = process.platform;