flashorm 2.0.7 → 2.1.0
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 +77 -45
- package/package.json +1 -1
- package/scripts/install.js +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# FlashORM
|
|
1
|
+
# FlashORM
|
|
2
2
|
|
|
3
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
4
|
|
|
@@ -17,12 +17,14 @@ A powerful, database-agnostic migration CLI tool built in Go with multi-database
|
|
|
17
17
|
|
|
18
18
|
## 📊 Performance
|
|
19
19
|
|
|
20
|
-
| Operation
|
|
21
|
-
|
|
22
|
-
| Insert 1000 Users
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
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** |
|
|
26
28
|
|
|
27
29
|
## 🚀 Installation
|
|
28
30
|
|
|
@@ -39,6 +41,7 @@ bun pm trust flashorm
|
|
|
39
41
|
```
|
|
40
42
|
|
|
41
43
|
Or add to your `package.json`:
|
|
44
|
+
|
|
42
45
|
```json
|
|
43
46
|
{
|
|
44
47
|
"trustedDependencies": ["flashorm"]
|
|
@@ -54,6 +57,7 @@ flash init --postgresql # or --mysql, --sqlite
|
|
|
54
57
|
```
|
|
55
58
|
|
|
56
59
|
This creates:
|
|
60
|
+
|
|
57
61
|
```
|
|
58
62
|
your-project/
|
|
59
63
|
├── flash.config.json
|
|
@@ -75,6 +79,7 @@ DATABASE_URL=postgresql://user:password@localhost:5432/mydb
|
|
|
75
79
|
### 3. Define Schema
|
|
76
80
|
|
|
77
81
|
**db/schema/schema.sql**
|
|
82
|
+
|
|
78
83
|
```sql
|
|
79
84
|
CREATE TABLE users (
|
|
80
85
|
id SERIAL PRIMARY KEY,
|
|
@@ -88,6 +93,7 @@ CREATE TABLE users (
|
|
|
88
93
|
### 4. Write Queries
|
|
89
94
|
|
|
90
95
|
**db/queries/users.sql**
|
|
96
|
+
|
|
91
97
|
```sql
|
|
92
98
|
-- name: GetUser :one
|
|
93
99
|
SELECT id, name, email, created_at, updated_at FROM users
|
|
@@ -131,6 +137,7 @@ flash gen
|
|
|
131
137
|
```
|
|
132
138
|
|
|
133
139
|
**Generated Types (flash_gen/index.d.ts)**
|
|
140
|
+
|
|
134
141
|
```typescript
|
|
135
142
|
// Code generated by FlashORM. DO NOT EDIT.
|
|
136
143
|
|
|
@@ -166,41 +173,48 @@ export function New(db: any): Queries;
|
|
|
166
173
|
### 8. Use in Your Code
|
|
167
174
|
|
|
168
175
|
**index.ts**
|
|
176
|
+
|
|
169
177
|
```typescript
|
|
170
|
-
import { Pool } from
|
|
171
|
-
import { New } from
|
|
178
|
+
import { Pool } from "pg";
|
|
179
|
+
import { New } from "./flash_gen/database";
|
|
172
180
|
|
|
173
|
-
const DATABASE_URL =
|
|
181
|
+
const DATABASE_URL =
|
|
182
|
+
process.env.DATABASE_URL ||
|
|
183
|
+
"postgresql://postgres:postgres@localhost:5432/mydb";
|
|
174
184
|
|
|
175
185
|
async function main() {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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();
|
|
199
213
|
}
|
|
200
214
|
|
|
201
215
|
main().catch((err) => {
|
|
202
|
-
|
|
203
|
-
|
|
216
|
+
console.error("Error:", err);
|
|
217
|
+
process.exit(1);
|
|
204
218
|
});
|
|
205
219
|
```
|
|
206
220
|
|
|
@@ -223,6 +237,7 @@ flash studio --browser=false
|
|
|
223
237
|
```
|
|
224
238
|
|
|
225
239
|
**Studio Features:**
|
|
240
|
+
|
|
226
241
|
- 📊 **Data Browser**: View and edit table data with inline editing
|
|
227
242
|
- 💻 **SQL Editor**: Execute queries with CodeMirror syntax highlighting
|
|
228
243
|
- 🎨 **Schema Visualization**: Interactive database diagram with React + ReactFlow
|
|
@@ -331,6 +346,7 @@ flash <command> --help
|
|
|
331
346
|
## ⚙️ Configuration
|
|
332
347
|
|
|
333
348
|
**flash.config.json**
|
|
349
|
+
|
|
334
350
|
```json
|
|
335
351
|
{
|
|
336
352
|
"version": "2",
|
|
@@ -344,7 +360,7 @@ flash <command> --help
|
|
|
344
360
|
},
|
|
345
361
|
"gen": {
|
|
346
362
|
"js": {
|
|
347
|
-
"enabled": true
|
|
363
|
+
"enabled": true
|
|
348
364
|
}
|
|
349
365
|
}
|
|
350
366
|
}
|
|
@@ -353,6 +369,7 @@ flash <command> --help
|
|
|
353
369
|
## 🎨 PostgreSQL ENUM Support
|
|
354
370
|
|
|
355
371
|
**Schema with ENUMs**
|
|
372
|
+
|
|
356
373
|
```sql
|
|
357
374
|
CREATE TYPE user_role AS ENUM ('admin', 'user', 'guest');
|
|
358
375
|
|
|
@@ -364,6 +381,7 @@ CREATE TABLE users (
|
|
|
364
381
|
```
|
|
365
382
|
|
|
366
383
|
**Query with ENUM**
|
|
384
|
+
|
|
367
385
|
```sql
|
|
368
386
|
-- name: GetUsersByRole :many
|
|
369
387
|
SELECT id, name, role FROM users
|
|
@@ -371,8 +389,9 @@ WHERE role = $1;
|
|
|
371
389
|
```
|
|
372
390
|
|
|
373
391
|
**Generated TypeScript**
|
|
392
|
+
|
|
374
393
|
```typescript
|
|
375
|
-
export type UserRole =
|
|
394
|
+
export type UserRole = "admin" | "user" | "guest";
|
|
376
395
|
|
|
377
396
|
export interface Users {
|
|
378
397
|
id: number | null;
|
|
@@ -396,6 +415,7 @@ $ flash apply
|
|
|
396
415
|
```
|
|
397
416
|
|
|
398
417
|
If a migration fails:
|
|
418
|
+
|
|
399
419
|
```bash
|
|
400
420
|
❌ Failed at migration: 20251103_bad_migration
|
|
401
421
|
Error: syntax error at or near "INVALID"
|
|
@@ -421,31 +441,35 @@ Create export before applying? (y/n): y
|
|
|
421
441
|
## 📤 Export Formats
|
|
422
442
|
|
|
423
443
|
### JSON Export
|
|
444
|
+
|
|
424
445
|
```bash
|
|
425
446
|
flash export --json
|
|
426
447
|
```
|
|
448
|
+
|
|
427
449
|
```json
|
|
428
450
|
{
|
|
429
451
|
"timestamp": "2025-11-03 16:30:00",
|
|
430
452
|
"version": "1.0",
|
|
431
453
|
"tables": {
|
|
432
|
-
"users": [
|
|
433
|
-
{"id": 1, "name": "Alice", "email": "alice@example.com"}
|
|
434
|
-
]
|
|
454
|
+
"users": [{ "id": 1, "name": "Alice", "email": "alice@example.com" }]
|
|
435
455
|
}
|
|
436
456
|
}
|
|
437
457
|
```
|
|
438
458
|
|
|
439
459
|
### CSV Export
|
|
460
|
+
|
|
440
461
|
```bash
|
|
441
462
|
flash export --csv
|
|
442
463
|
```
|
|
464
|
+
|
|
443
465
|
Creates directory with individual CSV files per table.
|
|
444
466
|
|
|
445
467
|
### SQLite Export
|
|
468
|
+
|
|
446
469
|
```bash
|
|
447
470
|
flash export --sqlite
|
|
448
471
|
```
|
|
472
|
+
|
|
449
473
|
Creates portable `.db` file.
|
|
450
474
|
|
|
451
475
|
## 🎨 FlashORM Studio
|
|
@@ -461,6 +485,7 @@ Open http://localhost:5555 (or your custom port)
|
|
|
461
485
|
**Features:**
|
|
462
486
|
|
|
463
487
|
### 1. Data Browser (`/`)
|
|
488
|
+
|
|
464
489
|
- View all tables in sidebar
|
|
465
490
|
- Click any table to view/edit data
|
|
466
491
|
- Double-click cells for inline editing
|
|
@@ -470,6 +495,7 @@ Open http://localhost:5555 (or your custom port)
|
|
|
470
495
|
- Foreign key hints
|
|
471
496
|
|
|
472
497
|
### 2. SQL Editor (`/sql`)
|
|
498
|
+
|
|
473
499
|
- Execute custom SQL queries
|
|
474
500
|
- CodeMirror editor with syntax highlighting
|
|
475
501
|
- Press Ctrl+Enter to run queries
|
|
@@ -478,6 +504,7 @@ Open http://localhost:5555 (or your custom port)
|
|
|
478
504
|
- Query history
|
|
479
505
|
|
|
480
506
|
### 3. Schema Visualization (`/schema`)
|
|
507
|
+
|
|
481
508
|
- Interactive database diagram
|
|
482
509
|
- React + ReactFlow rendering
|
|
483
510
|
- Automatic layout with Dagre algorithm
|
|
@@ -487,6 +514,7 @@ Open http://localhost:5555 (or your custom port)
|
|
|
487
514
|
- MiniMap for navigation
|
|
488
515
|
|
|
489
516
|
**Tech Stack:**
|
|
517
|
+
|
|
490
518
|
- Backend: Go Fiber v2.52.9
|
|
491
519
|
- Frontend: React 18.2.0, ReactFlow 12.8.4, CodeMirror 5.65.2
|
|
492
520
|
- All assets embedded in single binary
|
|
@@ -507,6 +535,7 @@ flash raw "SELECT COUNT(*) FROM orders"
|
|
|
507
535
|
```
|
|
508
536
|
|
|
509
537
|
**Features:**
|
|
538
|
+
|
|
510
539
|
- ✅ Beautiful table output for SELECT queries
|
|
511
540
|
- ✅ Multi-statement execution
|
|
512
541
|
- ✅ Transaction support
|
|
@@ -514,6 +543,7 @@ flash raw "SELECT COUNT(*) FROM orders"
|
|
|
514
543
|
- ✅ Formatted error messages
|
|
515
544
|
|
|
516
545
|
**Example Output:**
|
|
546
|
+
|
|
517
547
|
```bash
|
|
518
548
|
$ flash raw -q "SELECT id, name, email FROM users LIMIT 3"
|
|
519
549
|
|
|
@@ -535,13 +565,13 @@ $ flash raw -q "SELECT id, name, email FROM users LIMIT 3"
|
|
|
535
565
|
## 🔧 Programmatic API
|
|
536
566
|
|
|
537
567
|
```javascript
|
|
538
|
-
const flash = require(
|
|
568
|
+
const flash = require("flashorm");
|
|
539
569
|
|
|
540
570
|
// Execute commands
|
|
541
|
-
flash.exec(
|
|
571
|
+
flash.exec("status");
|
|
542
572
|
flash.exec('migrate "add users"');
|
|
543
|
-
flash.exec(
|
|
544
|
-
flash.exec(
|
|
573
|
+
flash.exec("apply");
|
|
574
|
+
flash.exec("studio"); // Launch Studio
|
|
545
575
|
|
|
546
576
|
// Get binary path
|
|
547
577
|
const binaryPath = flash.getBinaryPath();
|
|
@@ -550,6 +580,7 @@ const binaryPath = flash.getBinaryPath();
|
|
|
550
580
|
## 📚 Examples
|
|
551
581
|
|
|
552
582
|
Check out complete examples:
|
|
583
|
+
|
|
553
584
|
- [TypeScript Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/ts)
|
|
554
585
|
- [Go Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/go)
|
|
555
586
|
|
|
@@ -574,6 +605,7 @@ Check your `DATABASE_URL` in `.env` file.
|
|
|
574
605
|
### Studio Not Loading
|
|
575
606
|
|
|
576
607
|
Make sure port 5555 is not in use, or specify a different port:
|
|
608
|
+
|
|
577
609
|
```bash
|
|
578
610
|
flash studio --port 3000
|
|
579
611
|
```
|
|
@@ -598,4 +630,4 @@ flash studio --port 3000
|
|
|
598
630
|
|
|
599
631
|
MIT License - see [LICENSE](https://github.com/Lumos-Labs-HQ/flash/blob/main/LICENSE)
|
|
600
632
|
|
|
601
|
-
---
|
|
633
|
+
---
|
package/package.json
CHANGED