flashorm 1.0.0__tar.gz

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.
flashorm-1.0.0/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ MIT Non-Commercial License (MIT-NC)
2
+
3
+ Copyright (c) 2025 FlashORM
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the β€œSoftware”), to use,
7
+ copy, modify, merge, publish, and distribute copies of the Software for
8
+ personal, educational, or non-commercial purposes only, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ Commercial use of the Software (including use by any for-profit business or
15
+ organization) requires a separate commercial license from the author.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ recursive-include flashorm/bin *
@@ -0,0 +1,615 @@
1
+ Metadata-Version: 2.4
2
+ Name: flashorm
3
+ Version: 1.0.0
4
+ Summary: A powerful, database-agnostic ORM with multi-database support and type-safe code generation
5
+ Home-page: https://github.com/Lumos-Labs-HQ/flash
6
+ Author: Rana718
7
+ Author-email:
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/Lumos-Labs-HQ/flash
10
+ Project-URL: Repository, https://github.com/Lumos-Labs-HQ/flash
11
+ Project-URL: Issues, https://github.com/Lumos-Labs-HQ/flash/issues
12
+ Keywords: orm,database,migration,postgresql,mysql,sqlite,cli
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Requires-Python: >=3.7
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Dynamic: home-page
25
+ Dynamic: license-file
26
+ Dynamic: requires-python
27
+
28
+ # FlashORM
29
+
30
+ 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.
31
+
32
+ ## ✨ Features
33
+
34
+ - 🎨 **FlashORM Studio**: Visual database editor with React-based schema visualization
35
+ - πŸ—ƒοΈ **Multi-Database Support**: PostgreSQL, MySQL, SQLite
36
+ - πŸ”„ **Migration Management**: Create, apply, and track migrations
37
+ - πŸ”’ **Safe Migration System**: Transaction-based execution with automatic rollback
38
+ - πŸ“€ **Smart Export System**: Multiple formats (JSON, CSV, SQLite)
39
+ - πŸ”§ **Type-Safe Code Generation**: Generate fully typed JavaScript/TypeScript code
40
+ - ⚑ **Blazing Fast**: 2.5x faster than Drizzle, 10x faster than Prisma
41
+ - πŸ’» **Raw SQL Execution**: Execute SQL files or inline queries
42
+ - 🎯 **Prisma-like Commands**: Familiar CLI interface
43
+ - 🎨 **Enum Support**: Full PostgreSQL ENUM support
44
+
45
+ ## πŸ“Š Performance
46
+
47
+ | Operation | FlashORM | Drizzle | Prisma |
48
+ |-----------|-------|---------|--------|
49
+ | Insert 1000 Users | **158ms** | 224ms | 230ms |
50
+ | Insert 10 Cat + 5K Posts + 15K Comments | **2410ms** | 3028ms | 3977ms |
51
+ | Complex Query x500 | **4071ms** | 12500ms | 56322ms |
52
+ | Mixed Workload x1000 (75% read, 25% write) | **186ms** | 1174ms | 10863ms |
53
+ | Stress Test Simple Query x2000 | **122ms** | 160ms | 223ms |
54
+ | **TOTAL** | **6947ms** | **17149ms** | **71551ms** |
55
+
56
+ ## πŸš€ Installation
57
+
58
+ ```bash
59
+ pip install flashorm
60
+ ```
61
+
62
+ ## 🏁 Quick Start
63
+
64
+ ### 1. Initialize Project
65
+
66
+ ```bash
67
+ flash init --postgresql # or --mysql, --sqlite
68
+ ```
69
+
70
+ This creates:
71
+ ```
72
+ your-project/
73
+ β”œβ”€β”€ flash.config.json
74
+ β”œβ”€β”€ .env
75
+ └── db/
76
+ β”œβ”€β”€ schema/
77
+ β”‚ └── schema.sql
78
+ └── queries/
79
+ └── users.sql
80
+ ```
81
+
82
+ ### 2. Configure Database
83
+
84
+ ```bash
85
+ # .env file
86
+ DATABASE_URL=postgresql://user:password@localhost:5432/mydb
87
+ ```
88
+
89
+ ### 3. Define Schema
90
+
91
+ **db/schema/schema.sql**
92
+ ```sql
93
+ CREATE TABLE users (
94
+ id SERIAL PRIMARY KEY,
95
+ name VARCHAR(255) NOT NULL,
96
+ email VARCHAR(255) UNIQUE NOT NULL,
97
+ created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
98
+ updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
99
+ );
100
+ ```
101
+
102
+ ### 4. Write Queries
103
+
104
+ **db/queries/users.sql**
105
+ ```sql
106
+ -- name: GetUser :one
107
+ SELECT id, name, email, created_at, updated_at FROM users
108
+ WHERE id = $1 LIMIT 1;
109
+
110
+ -- name: CreateUser :one
111
+ INSERT INTO users (name, email)
112
+ VALUES ($1, $2)
113
+ RETURNING id, name, email, created_at, updated_at;
114
+
115
+ -- name: ListUsers :many
116
+ SELECT id, name, email, created_at, updated_at FROM users
117
+ ORDER BY created_at DESC;
118
+
119
+ -- name: UpdateUser :one
120
+ UPDATE users
121
+ SET name = $2, email = $3, updated_at = NOW()
122
+ WHERE id = $1
123
+ RETURNING id, name, email, created_at, updated_at;
124
+
125
+ -- name: DeleteUser :exec
126
+ DELETE FROM users WHERE id = $1;
127
+ ```
128
+
129
+ ### 5. Create Migration
130
+
131
+ ```bash
132
+ flash migrate "create users table"
133
+ ```
134
+
135
+ ### 6. Apply Migration
136
+
137
+ ```bash
138
+ flash apply
139
+ ```
140
+
141
+ ### 7. Generate Type-Safe Code
142
+
143
+ ```bash
144
+ flash gen
145
+ ```
146
+
147
+ **Generated Types (flash_gen/index.d.ts)**
148
+ ```typescript
149
+ // Code generated by FlashORM. DO NOT EDIT.
150
+
151
+ export interface Users {
152
+ id: number | null;
153
+ name: string;
154
+ email: string;
155
+ created_at: Date;
156
+ updated_at: Date;
157
+ }
158
+
159
+ export interface GetUserResult {
160
+ id: number | null;
161
+ name: string;
162
+ email: string;
163
+ created_at: Date;
164
+ updated_at: Date;
165
+ }
166
+
167
+ export class Queries {
168
+ constructor(db: any);
169
+
170
+ getUser(id: number): Promise<GetUserResult | null>;
171
+ createUser(name: string, email: string): Promise<Users | null>;
172
+ listUsers(): Promise<Users[]>;
173
+ updateUser(id: number, name: string, email: string): Promise<Users | null>;
174
+ deleteUser(id: number): Promise<void>;
175
+ }
176
+
177
+ export function New(db: any): Queries;
178
+ ```
179
+
180
+ ### 8. Use in Your Code
181
+
182
+ **index.ts**
183
+ ```typescript
184
+ import { Pool } from 'pg';
185
+ import { New } from './flash_gen/database';
186
+
187
+ const DATABASE_URL = process.env.DATABASE_URL || 'postgresql://postgres:postgres@localhost:5432/mydb';
188
+
189
+ async function main() {
190
+ const pool = new Pool({
191
+ connectionString: DATABASE_URL,
192
+ });
193
+
194
+ const db = New(pool);
195
+
196
+ // Create user - fully type-safe!
197
+ const newUser = await db.createUser('Alice', 'alice@example.com');
198
+ console.log('New user:', newUser);
199
+
200
+ // Get user by ID
201
+ const user = await db.getUser(newUser.id);
202
+ console.log('Found user:', user);
203
+
204
+ // List all users
205
+ const users = await db.listUsers();
206
+ console.log('All users:', users);
207
+
208
+ // Update user
209
+ const updated = await db.updateUser(newUser.id, 'Alice Smith', 'alice.smith@example.com');
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)
227
+ flash studio
228
+
229
+ # Launch on custom port
230
+ flash studio --port 3000
231
+
232
+ # Connect to any database directly
233
+ flash studio --db "postgresql://user:pass@localhost:5432/mydb"
234
+
235
+ # Launch without opening browser
236
+ flash studio --browser=false
237
+ ```
238
+
239
+ **Studio Features:**
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
+ ```json
349
+ {
350
+ "version": "2",
351
+ "schema_path": "db/schema/schema.sql",
352
+ "queries": "db/queries/",
353
+ "migrations_path": "db/migrations",
354
+ "export_path": "db/export",
355
+ "database": {
356
+ "provider": "postgresql",
357
+ "url_env": "DATABASE_URL"
358
+ },
359
+ "gen": {
360
+ "js": {
361
+ "enabled": true,
362
+ }
363
+ }
364
+ }
365
+ ```
366
+
367
+ ## 🎨 PostgreSQL ENUM Support
368
+
369
+ **Schema with ENUMs**
370
+ ```sql
371
+ CREATE TYPE user_role AS ENUM ('admin', 'user', 'guest');
372
+
373
+ CREATE TABLE users (
374
+ id SERIAL PRIMARY KEY,
375
+ name VARCHAR(255) NOT NULL,
376
+ role user_role NOT NULL DEFAULT 'user'
377
+ );
378
+ ```
379
+
380
+ **Query with ENUM**
381
+ ```sql
382
+ -- name: GetUsersByRole :many
383
+ SELECT id, name, role FROM users
384
+ WHERE role = $1;
385
+ ```
386
+
387
+ **Generated TypeScript**
388
+ ```typescript
389
+ export type UserRole = 'admin' | 'user' | 'guest';
390
+
391
+ export interface Users {
392
+ id: number | null;
393
+ name: string;
394
+ role: UserRole;
395
+ }
396
+ ```
397
+
398
+ ## πŸ”’ Safe Migrations
399
+
400
+ Every migration runs in a transaction with automatic rollback on failure:
401
+
402
+ ```bash
403
+ $ flash apply
404
+ πŸ“¦ Applying 2 migration(s)...
405
+ [1/2] 20251103_create_users
406
+ βœ… Applied
407
+ [2/2] 20251103_add_email_index
408
+ βœ… Applied
409
+ βœ… All migrations applied successfully
410
+ ```
411
+
412
+ If a migration fails:
413
+ ```bash
414
+ ❌ Failed at migration: 20251103_bad_migration
415
+ Error: syntax error at or near "INVALID"
416
+ Transaction rolled back. Fix the error and run 'flash apply' again.
417
+ ```
418
+
419
+ ## πŸ›‘οΈ Conflict Detection
420
+
421
+ FlashORM automatically detects schema conflicts:
422
+
423
+ ```bash
424
+ ⚠️ Migration conflicts detected:
425
+ - Table 'users' already exists
426
+ - Column 'email' conflicts with existing column
427
+
428
+ Reset database to resolve conflicts? (y/n): y
429
+ Create export before applying? (y/n): y
430
+ πŸ“¦ Creating export...
431
+ βœ… Export created successfully
432
+ πŸ”„ Resetting database and applying all migrations...
433
+ ```
434
+
435
+ ## πŸ“€ Export Formats
436
+
437
+ ### JSON Export
438
+ ```bash
439
+ flash export --json
440
+ ```
441
+ ```json
442
+ {
443
+ "timestamp": "2025-11-03 16:30:00",
444
+ "version": "1.0",
445
+ "tables": {
446
+ "users": [
447
+ {"id": 1, "name": "Alice", "email": "alice@example.com"}
448
+ ]
449
+ }
450
+ }
451
+ ```
452
+
453
+ ### CSV Export
454
+ ```bash
455
+ flash export --csv
456
+ ```
457
+ Creates directory with individual CSV files per table.
458
+
459
+ ### SQLite Export
460
+ ```bash
461
+ flash export --sqlite
462
+ ```
463
+ Creates portable `.db` file.
464
+
465
+ ## 🎨 FlashORM Studio
466
+
467
+ Launch the visual database editor:
468
+
469
+ ```bash
470
+ flash studio
471
+ ```
472
+
473
+ Open http://localhost:5555 (or your custom port)
474
+
475
+ **Features:**
476
+
477
+ ### 1. Data Browser (`/`)
478
+ - View all tables in sidebar
479
+ - Click any table to view/edit data
480
+ - Double-click cells for inline editing
481
+ - Add/delete rows with intuitive modals
482
+ - Pagination (50 rows per page)
483
+ - Search across tables
484
+ - Foreign key hints
485
+
486
+ ### 2. SQL Editor (`/sql`)
487
+ - Execute custom SQL queries
488
+ - CodeMirror editor with syntax highlighting
489
+ - Press Ctrl+Enter to run queries
490
+ - Export results to CSV
491
+ - Resizable split-pane interface
492
+ - Query history
493
+
494
+ ### 3. Schema Visualization (`/schema`)
495
+ - Interactive database diagram
496
+ - React + ReactFlow rendering
497
+ - Automatic layout with Dagre algorithm
498
+ - Drag and drop tables
499
+ - Zoom and pan controls
500
+ - Foreign key relationship arrows
501
+ - MiniMap for navigation
502
+
503
+ **Tech Stack:**
504
+ - Backend: Go Fiber v2.52.9
505
+ - Frontend: React 18.2.0, ReactFlow 12.8.4, CodeMirror 5.65.2
506
+ - All assets embedded in single binary
507
+
508
+ ## πŸ’» Raw SQL Execution
509
+
510
+ Execute SQL files or inline queries:
511
+
512
+ ```bash
513
+ # Execute SQL file
514
+ flash raw script.sql
515
+
516
+ # Execute inline query
517
+ flash raw -q "SELECT * FROM users LIMIT 10"
518
+
519
+ # Auto-detection (file if exists, otherwise query)
520
+ flash raw "SELECT COUNT(*) FROM orders"
521
+ ```
522
+
523
+ **Features:**
524
+ - βœ… Beautiful table output for SELECT queries
525
+ - βœ… Multi-statement execution
526
+ - βœ… Transaction support
527
+ - βœ… Auto-detection of file vs query
528
+ - βœ… Formatted error messages
529
+
530
+ **Example Output:**
531
+ ```bash
532
+ $ flash raw -q "SELECT id, name, email FROM users LIMIT 3"
533
+
534
+ 🎯 Database: postgresql
535
+
536
+ ⚑ Executing query...
537
+ βœ… Query executed successfully
538
+ πŸ“Š 3 row(s) returned
539
+
540
+ β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
541
+ β”‚ id β”‚ name β”‚ email β”‚
542
+ β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
543
+ β”‚ 1 β”‚ Alice β”‚ alice@example.com β”‚
544
+ β”‚ 2 β”‚ Bob β”‚ bob@example.com β”‚
545
+ β”‚ 3 β”‚ Charlie β”‚ charlie@example.com β”‚
546
+ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
547
+ ```
548
+
549
+ ## πŸ”§ Programmatic API
550
+
551
+ ```javascript
552
+ const flash = require('flashorm');
553
+
554
+ // Execute commands
555
+ flash.exec('status');
556
+ flash.exec('migrate "add users"');
557
+ flash.exec('apply');
558
+ flash.exec('studio'); // Launch Studio
559
+
560
+ // Get binary path
561
+ const binaryPath = flash.getBinaryPath();
562
+ ```
563
+
564
+ ## πŸ“š Examples
565
+
566
+ Check out complete examples:
567
+ - [TypeScript Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/ts)
568
+ - [Go Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/go)
569
+
570
+ ## πŸ› Troubleshooting
571
+
572
+ ### Bun Postinstall Blocked
573
+
574
+ ```bash
575
+ bun pm trust flashorm
576
+ ```
577
+
578
+ ### Binary Not Found
579
+
580
+ ```bash
581
+ npm install -g flashorm --force
582
+ ```
583
+
584
+ ### Database Connection Failed
585
+
586
+ Check your `DATABASE_URL` in `.env` file.
587
+
588
+ ### Studio Not Loading
589
+
590
+ Make sure port 5555 is not in use, or specify a different port:
591
+ ```bash
592
+ flash studio --port 3000
593
+ ```
594
+
595
+ ## πŸ“– Documentation
596
+
597
+ - [Full Documentation](https://github.com/Lumos-Labs-HQ/flash)
598
+ - [How It Works](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/HOW_IT_WORKS.md)
599
+ - [Technology Stack](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/TECHNOLOGY_STACK.md)
600
+ - [Contributing](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/CONTRIBUTING.md)
601
+
602
+ ## 🌟 Key Highlights
603
+
604
+ - **Visual Database Editor**: Manage your database visually with FlashORM Studio
605
+ - **Raw SQL Support**: Execute SQL files or queries directly from CLI
606
+ - **Type-Safe**: Full TypeScript support with generated types
607
+ - **Fast**: 2.5x-10x faster than popular ORMs
608
+ - **Multi-DB**: PostgreSQL, MySQL, and SQLite support
609
+ - **Zero Config**: Works out of the box with sensible defaults
610
+
611
+ ## πŸ“„ License
612
+
613
+ MIT License - see [LICENSE](https://github.com/Lumos-Labs-HQ/flash/blob/main/LICENSE)
614
+
615
+ ---