flashorm 2.2.0b3__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.
@@ -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,603 @@
1
+ Metadata-Version: 2.4
2
+ Name: flashorm
3
+ Version: 2.2.0b3
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
+
44
+ ## πŸ“Š Performance
45
+
46
+ FlashORM significantly outperforms popular ORMs in real-world scenarios:
47
+
48
+ | Operation | FlashORM | SQLAlchemy |
49
+ | ------------------------------------------ | ---------- | ----------- |
50
+ | Insert 1000 Users | **16ms** | **299ms** |
51
+ | Insert 10 Cat + 5K Posts + 15K Comments | **440ms** | **1333ms** |
52
+ | Complex Query x500 | **1199ms** | **10627ms** |
53
+ | Mixed Workload x1000 (75% read, 25% write) | **248ms** | **645ms** |
54
+ | Stress Test Simple Query x2000 | **338ms** | **984ms** |
55
+ | **TOTAL** | **2241ms** | **13888ms** |
56
+
57
+ ## πŸš€ Installation
58
+
59
+ Install from PyPI (recommended):
60
+
61
+ ```bash
62
+ pip install flashorm
63
+ ```
64
+
65
+ ## 🏁 Quick Start
66
+
67
+ ### 1. Initialize Project
68
+
69
+ ```bash
70
+ flash init --postgresql # or --mysql, --sqlite
71
+ ```
72
+
73
+ This creates:
74
+
75
+ ```
76
+ your-project/
77
+ β”œβ”€β”€ flash.config.json
78
+ β”œβ”€β”€ .env
79
+ └── db/
80
+ β”œβ”€β”€ schema/
81
+ β”‚ └── schema.sql
82
+ └── queries/
83
+ └── users.sql
84
+ ```
85
+
86
+ ### 2. Configure Database
87
+
88
+ ```bash
89
+ # .env file
90
+ DATABASE_URL=postgresql://user:password@localhost:5432/mydb
91
+ ```
92
+
93
+ ### 3. Define Schema
94
+
95
+ **db/schema/schema.sql**
96
+
97
+ ```sql
98
+ CREATE TABLE users (
99
+ id SERIAL PRIMARY KEY,
100
+ name VARCHAR(255) NOT NULL,
101
+ email VARCHAR(255) UNIQUE NOT NULL,
102
+ created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
103
+ updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
104
+ );
105
+ ```
106
+
107
+ ### 4. Write Queries
108
+
109
+ **db/queries/users.sql**
110
+
111
+ ```sql
112
+ -- name: GetUser :one
113
+ SELECT id, name, email, created_at, updated_at FROM users
114
+ WHERE id = $1 LIMIT 1;
115
+
116
+ -- name: CreateUser :one
117
+ INSERT INTO users (name, email)
118
+ VALUES ($1, $2)
119
+ RETURNING id, name, email, created_at, updated_at;
120
+
121
+ -- name: ListUsers :many
122
+ SELECT id, name, email, created_at, updated_at FROM users
123
+ ORDER BY created_at DESC;
124
+
125
+ -- name: UpdateUser :one
126
+ UPDATE users
127
+ SET name = $2, email = $3, updated_at = NOW()
128
+ WHERE id = $1
129
+ RETURNING id, name, email, created_at, updated_at;
130
+
131
+ -- name: DeleteUser :exec
132
+ DELETE FROM users WHERE id = $1;
133
+ ```
134
+
135
+ ### 5. Create Migration
136
+
137
+ ```bash
138
+ flash migrate "create users table"
139
+ ```
140
+
141
+ ### 6. Apply Migration
142
+
143
+ ```bash
144
+ flash apply
145
+ ```
146
+
147
+ ### 7. Generate Type-Safe Code
148
+
149
+ ```bash
150
+ flash gen
151
+ ```
152
+
153
+ **Generated Table Types (flash_gen/models.py)**
154
+
155
+ ```py
156
+
157
+ # Code generated by FlashORM. DO NOT EDIT.
158
+
159
+ from dataclasses import dataclass
160
+ from typing import Optional, Literal
161
+ from datetime import datetime
162
+ from decimal import Decimal
163
+
164
+ @dataclass
165
+ class Users:
166
+ id: int
167
+ name: str
168
+ email: str
169
+ created_at: datetime
170
+ updated_at: datetime
171
+
172
+
173
+ ```
174
+
175
+ ### 8. Use in Your Code
176
+
177
+ **Async Example (default)**
178
+
179
+ ```python
180
+ import asyncio
181
+ import asyncpg
182
+ import os
183
+ from flash_gen.database import new
184
+
185
+ DATABASE_URL = os.getenv('DATABASE_URL', 'postgresql://postgres:postgres@localhost:5432/FlashORM_test')
186
+
187
+ async def main():
188
+ pool = await asyncpg.create_pool(DATABASE_URL)
189
+
190
+ db = new(pool)
191
+
192
+ newuser = await db.create_user('jack', 'jack@gmail.com')
193
+ print('New user:', newuser)
194
+
195
+ await pool.close()
196
+
197
+ if __name__ == '__main__':
198
+ asyncio.run(main())
199
+ ```
200
+
201
+ **Sync Example (set `"async": false` in config)**
202
+
203
+ ```python
204
+ import psycopg2
205
+ import os
206
+ from flash_gen.database import new
207
+
208
+ DATABASE_URL = os.getenv('DATABASE_URL', 'postgresql://postgres:postgres@localhost:5432/FlashORM_test')
209
+
210
+ def main():
211
+ conn = psycopg2.connect(DATABASE_URL)
212
+
213
+ db = new(conn)
214
+
215
+ newuser = db.create_user('jack', 'jack@gmail.com')
216
+ print('New user:', newuser)
217
+
218
+ conn.close()
219
+
220
+ if __name__ == '__main__':
221
+ main()
222
+ ```
223
+
224
+ ## πŸ“‹ All Commands
225
+
226
+ ### Visual Database Editor
227
+
228
+ ```bash
229
+ # Launch FlashORM Studio (web-based database editor)
230
+ flash studio
231
+
232
+ # Launch on custom port
233
+ flash studio --port 3000
234
+
235
+ # Connect to any database directly
236
+ flash studio --db "postgresql://user:pass@localhost:5432/mydb"
237
+
238
+ # Launch without opening browser
239
+ flash studio --browser=false
240
+ ```
241
+
242
+ **Studio Features:**
243
+
244
+ - πŸ“Š **Data Browser**: View and edit table data with inline editing
245
+ - πŸ’» **SQL Editor**: Execute queries with CodeMirror syntax highlighting
246
+ - 🎨 **Schema Visualization**: Interactive database diagram with React + ReactFlow
247
+ - πŸ” **Search & Filter**: Search across all tables
248
+ - ⚑ **Real-time Updates**: See changes immediately
249
+
250
+ ### Project Setup
251
+
252
+ ```bash
253
+ # Initialize new project
254
+ flash init --postgresql
255
+ flash init --mysql
256
+ flash init --sqlite
257
+ ```
258
+
259
+ ### Migrations
260
+
261
+ ```bash
262
+ # Create new migration
263
+ flash migrate "migration name"
264
+
265
+ # Create empty migration
266
+ flash migrate "custom migration" --empty
267
+
268
+ # Apply all pending migrations
269
+ flash apply
270
+
271
+ # Apply with force (skip confirmations)
272
+ flash apply --force
273
+
274
+ # Check migration status
275
+ flash status
276
+ ```
277
+
278
+ ### Code Generation
279
+
280
+ ```bash
281
+ # Generate type-safe code
282
+ flash gen
283
+ ```
284
+
285
+ ### Schema Management
286
+
287
+ ```bash
288
+ # Pull schema from existing database
289
+ flash pull
290
+
291
+ # Pull with backup
292
+ flash pull --backup
293
+
294
+ # Pull to custom file
295
+ flash pull --output custom-schema.sql
296
+ ```
297
+
298
+ ### Database Export
299
+
300
+ ```bash
301
+ # Export as JSON (default)
302
+ flash export
303
+ flash export --json
304
+
305
+ # Export as CSV
306
+ flash export --csv
307
+
308
+ # Export as SQLite
309
+ flash export --sqlite
310
+ ```
311
+
312
+ ### Database Operations
313
+
314
+ ```bash
315
+ # Reset database (destructive!)
316
+ flash reset
317
+
318
+ # Reset with force
319
+ flash reset --force
320
+
321
+ # Execute raw SQL file
322
+ flash raw script.sql
323
+ flash raw migrations/seed.sql
324
+
325
+ # Execute inline SQL query
326
+ flash raw -q "SELECT * FROM users WHERE active = true"
327
+ flash raw "SELECT COUNT(*) FROM orders"
328
+
329
+ # Force file mode
330
+ flash raw --file queries/complex.sql
331
+ ```
332
+
333
+ ### Help & Info
334
+
335
+ ```bash
336
+ # Launch FlashORM Studio
337
+ flash studio
338
+
339
+ # Show version
340
+ flash --version
341
+ flash -v
342
+
343
+ # Show help
344
+ flash --help
345
+ flash <command> --help
346
+ ```
347
+
348
+ ## βš™οΈ Configuration
349
+
350
+ **flash.config.json**
351
+
352
+ ```json
353
+ {
354
+ "version": "2",
355
+ "schema_path": "db/schema/schema.sql",
356
+ "queries": "db/queries/",
357
+ "migrations_path": "db/migrations",
358
+ "export_path": "db/export",
359
+ "database": {
360
+ "provider": "postgresql",
361
+ "url_env": "DATABASE_URL"
362
+ },
363
+ "gen": {
364
+
365
+ "python": {
366
+ "enabled": true,
367
+ "async": false
368
+ }
369
+ }
370
+ }
371
+ ```
372
+
373
+ **Python Generation Options:**
374
+
375
+ - `async`: Set to `true` for async/await code generation (default), `false` for synchronous code generation.
376
+
377
+ ## 🎨 PostgreSQL ENUM Support
378
+
379
+ **Schema with ENUMs**
380
+
381
+ ```sql
382
+ CREATE TYPE user_role AS ENUM ('admin', 'user', 'guest');
383
+
384
+ CREATE TABLE users (
385
+ id SERIAL PRIMARY KEY,
386
+ name VARCHAR(255) NOT NULL,
387
+ role user_role NOT NULL DEFAULT 'user'
388
+ );
389
+ ```
390
+
391
+ ## πŸ”’ Safe Migrations
392
+
393
+ Every migration runs in a transaction with automatic rollback on failure:
394
+
395
+ ```bash
396
+ $ flash apply
397
+ πŸ“¦ Applying 2 migration(s)...
398
+ [1/2] 20251103_create_users
399
+ βœ… Applied
400
+ [2/2] 20251103_add_email_index
401
+ βœ… Applied
402
+ βœ… All migrations applied successfully
403
+ ```
404
+
405
+ If a migration fails:
406
+
407
+ ```bash
408
+ ❌ Failed at migration: 20251103_bad_migration
409
+ Error: syntax error at or near "INVALID"
410
+ Transaction rolled back. Fix the error and run 'flash apply' again.
411
+ ```
412
+
413
+ ## πŸ›‘οΈ Conflict Detection
414
+
415
+ FlashORM automatically detects schema conflicts:
416
+
417
+ ```bash
418
+ ⚠️ Migration conflicts detected:
419
+ - Table 'users' already exists
420
+ - Column 'email' conflicts with existing column
421
+
422
+ Reset database to resolve conflicts? (y/n): y
423
+ Create export before applying? (y/n): y
424
+ πŸ“¦ Creating export...
425
+ βœ… Export created successfully
426
+ πŸ”„ Resetting database and applying all migrations...
427
+ ```
428
+
429
+ ## πŸ“€ Export Formats
430
+
431
+ ### JSON Export
432
+
433
+ ```bash
434
+ flash export --json
435
+ ```
436
+
437
+ ```json
438
+ {
439
+ "timestamp": "2025-11-03 16:30:00",
440
+ "version": "1.0",
441
+ "tables": {
442
+ "users": [{ "id": 1, "name": "Alice", "email": "alice@example.com" }]
443
+ }
444
+ }
445
+ ```
446
+
447
+ ### CSV Export
448
+
449
+ ```bash
450
+ flash export --csv
451
+ ```
452
+
453
+ Creates directory with individual CSV files per table.
454
+
455
+ ### SQLite Export
456
+
457
+ ```bash
458
+ flash export --sqlite
459
+ ```
460
+
461
+ Creates portable `.db` file.
462
+
463
+ ## 🎨 FlashORM Studio
464
+
465
+ Launch the visual database editor:
466
+
467
+ ```bash
468
+ flash studio
469
+ ```
470
+
471
+ Open http://localhost:5555 (or your custom port)
472
+
473
+ **Features:**
474
+
475
+ ### 1. Data Browser (`/`)
476
+
477
+ - View all tables in sidebar
478
+ - Click any table to view/edit data
479
+ - Double-click cells for inline editing
480
+ - Add/delete rows with intuitive modals
481
+ - Pagination (50 rows per page)
482
+ - Search across tables
483
+ - Foreign key hints
484
+
485
+ ### 2. SQL Editor (`/sql`)
486
+
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
+
496
+ - Interactive database diagram
497
+ - React + ReactFlow rendering
498
+ - Automatic layout with Dagre algorithm
499
+ - Drag and drop tables
500
+ - Zoom and pan controls
501
+ - Foreign key relationship arrows
502
+ - MiniMap for navigation
503
+
504
+ ## πŸ’» Raw SQL Execution
505
+
506
+ Execute SQL files or inline queries:
507
+
508
+ ```bash
509
+ # Execute SQL file
510
+ flash raw script.sql
511
+
512
+ # Execute inline query
513
+ flash raw -q "SELECT * FROM users LIMIT 10"
514
+
515
+ # Auto-detection (file if exists, otherwise query)
516
+ flash raw "SELECT COUNT(*) FROM orders"
517
+ ```
518
+
519
+ **Features:**
520
+
521
+ - βœ… Beautiful table output for SELECT queries
522
+ - βœ… Multi-statement execution
523
+ - βœ… Transaction support
524
+ - βœ… Auto-detection of file vs query
525
+ - βœ… Formatted error messages
526
+
527
+ **Example Output:**
528
+
529
+ ```bash
530
+ $ flash raw -q "SELECT id, name, email FROM users LIMIT 3"
531
+
532
+ 🎯 Database: postgresql
533
+
534
+ ⚑ Executing query...
535
+ βœ… Query executed successfully
536
+ πŸ“Š 3 row(s) returned
537
+
538
+ β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
539
+ β”‚ id β”‚ name β”‚ email β”‚
540
+ β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
541
+ β”‚ 1 β”‚ Alice β”‚ alice@example.com β”‚
542
+ β”‚ 2 β”‚ Bob β”‚ bob@example.com β”‚
543
+ β”‚ 3 β”‚ Charlie β”‚ charlie@example.com β”‚
544
+ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
545
+ ```
546
+
547
+ d
548
+
549
+ ## πŸ“š Examples
550
+
551
+ Check out complete examples:
552
+
553
+ - [Python Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/python)
554
+ - [TypeScript Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/ts)
555
+ - [Go Example](https://github.com/Lumos-Labs-HQ/flash/tree/main/example/go)
556
+
557
+ ## πŸ› Troubleshooting
558
+
559
+ ### Bun Postinstall Blocked
560
+
561
+ ```bash
562
+ bun pm trust flashorm
563
+ ```
564
+
565
+ ### Binary Not Found
566
+
567
+ ```bash
568
+ npm install -g flashorm --force
569
+ ```
570
+
571
+ ### Database Connection Failed
572
+
573
+ Check your `DATABASE_URL` in `.env` file.
574
+
575
+ ### Studio Not Loading
576
+
577
+ Make sure port 5555 is not in use, or specify a different port:
578
+
579
+ ```bash
580
+ flash studio --port 3000
581
+ ```
582
+
583
+ ## πŸ“– Documentation
584
+
585
+ - [Full Documentation](https://github.com/Lumos-Labs-HQ/flash)
586
+ - [How It Works](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/HOW_IT_WORKS.md)
587
+ - [Technology Stack](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/TECHNOLOGY_STACK.md)
588
+ - [Contributing](https://github.com/Lumos-Labs-HQ/flash/blob/main/docs/CONTRIBUTING.md)
589
+
590
+ ## 🌟 Key Highlights
591
+
592
+ - **Visual Database Editor**: Manage your database visually with FlashORM Studio
593
+ - **Raw SQL Support**: Execute SQL files or queries directly from CLI
594
+ - **Type-Safe**: Full TypeScript support with generated types
595
+ - **Fast**: 2.5x-10x faster than popular ORMs
596
+ - **Multi-DB**: PostgreSQL, MySQL, and SQLite support
597
+ - **Zero Config**: Works out of the box with sensible defaults
598
+
599
+ ## πŸ“„ License
600
+
601
+ MIT License - see [LICENSE](https://github.com/Lumos-Labs-HQ/flash/blob/main/LICENSE)
602
+
603
+ ---