spindb 0.12.3 → 0.13.4

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.
Files changed (43) hide show
  1. package/README.md +239 -30
  2. package/cli/commands/backup.ts +35 -9
  3. package/cli/commands/backups.ts +259 -0
  4. package/cli/commands/connect.ts +92 -0
  5. package/cli/commands/create.ts +28 -17
  6. package/cli/commands/engines.ts +109 -18
  7. package/cli/commands/menu/backup-handlers.ts +567 -81
  8. package/cli/commands/menu/container-handlers.ts +112 -18
  9. package/cli/commands/menu/engine-handlers.ts +372 -69
  10. package/cli/commands/menu/index.ts +6 -6
  11. package/cli/commands/menu/shell-handlers.ts +71 -13
  12. package/cli/commands/menu/sql-handlers.ts +4 -3
  13. package/cli/commands/run.ts +37 -21
  14. package/cli/constants.ts +2 -0
  15. package/cli/helpers.ts +312 -20
  16. package/cli/index.ts +2 -1
  17. package/cli/ui/prompts.ts +182 -14
  18. package/config/backup-formats.ts +168 -0
  19. package/config/engine-defaults.ts +14 -0
  20. package/config/os-dependencies.ts +110 -15
  21. package/core/backup-restore.ts +346 -0
  22. package/core/config-manager.ts +0 -4
  23. package/core/container-manager.ts +6 -1
  24. package/core/dependency-manager.ts +21 -0
  25. package/core/port-manager.ts +2 -2
  26. package/engines/base-engine.ts +9 -0
  27. package/engines/index.ts +3 -1
  28. package/engines/mongodb/binary-detection.ts +64 -0
  29. package/engines/mongodb/index.ts +80 -13
  30. package/engines/mongodb/restore.ts +40 -8
  31. package/engines/mongodb/version-validator.ts +5 -3
  32. package/engines/mysql/backup.ts +9 -5
  33. package/engines/mysql/binary-detection.ts +96 -22
  34. package/engines/mysql/index.ts +79 -16
  35. package/engines/postgresql/index.ts +12 -0
  36. package/engines/redis/backup.ts +358 -0
  37. package/engines/redis/binary-detection.ts +442 -0
  38. package/engines/redis/index.ts +927 -0
  39. package/engines/redis/restore.ts +380 -0
  40. package/engines/redis/version-validator.ts +133 -0
  41. package/engines/sqlite/index.ts +1 -1
  42. package/package.json +5 -3
  43. package/types/index.ts +12 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  **The first npm CLI for running local databases without Docker.**
9
9
 
10
- Spin up PostgreSQL, MySQL, SQLite, and MongoDB instances for local development. No Docker daemon, no container networking, no volume mounts. Just databases running on localhost, ready in seconds.
10
+ Spin up PostgreSQL, MySQL, SQLite, MongoDB, and Redis instances for local development. No Docker daemon, no container networking, no volume mounts. Just databases running on localhost, ready in seconds.
11
11
 
12
12
  ---
13
13
 
@@ -145,7 +145,7 @@ SpinDB downloads PostgreSQL server binaries automatically:
145
145
  - **macOS/Linux:** Pre-compiled binaries from the zonky.io project, hosted on Maven Central
146
146
  - **Windows:** Official binaries from EnterpriseDB (EDB)
147
147
 
148
- **Why download binaries instead of using system PostgreSQL?** You might want PostgreSQL 14 for one project and 18 for another. SpinDB lets you run different versions side-by-side without conflicts.
148
+ **Why download binaries instead of using system PostgreSQL?** The [zonky.io project](https://github.com/zonkyio/embedded-postgres-binaries) provides pre-configured, portable PostgreSQL binaries—just extract and run. This lets you run PostgreSQL 14 for one project and 18 for another, side-by-side, without conflicts. No other database engine has an equivalent portable distribution.
149
149
 
150
150
  **Client tools required:** You still need `psql`, `pg_dump`, and `pg_restore` installed on your system for some operations (connecting, backups, restores). SpinDB can install these for you:
151
151
 
@@ -162,7 +162,7 @@ spindb deps install --engine postgresql
162
162
  | Default user | `root` |
163
163
  | Binary source | System installation |
164
164
 
165
- Unlike PostgreSQL, SpinDB uses your system's MySQL installation. This is because MySQL doesn't have a nice cross-platform binary distribution like zonky.io provides for PostgreSQL.
165
+ Unlike PostgreSQL, SpinDB uses your system's MySQL installation. While Oracle provides MySQL binary downloads, they require system libraries and configuration—there's no "unzip and run" distribution like zonky.io provides for PostgreSQL. For most local development, a single system-installed MySQL version works well.
166
166
 
167
167
  ```bash
168
168
  # macOS
@@ -219,7 +219,7 @@ spindb connect mydb --litecli
219
219
  | Default user | None (no auth by default) |
220
220
  | Binary source | System installation |
221
221
 
222
- Like MySQL, SpinDB uses your system's MongoDB installation. MongoDB binaries aren't available as a single cross-platform download, so you'll need to install MongoDB via your package manager.
222
+ Like MySQL, SpinDB uses your system's MongoDB installation. While MongoDB provides official binary downloads, they require additional configuration and system dependencies. SpinDB relies on your package manager to handle this setup.
223
223
 
224
224
  ```bash
225
225
  # macOS
@@ -240,20 +240,57 @@ MongoDB uses JavaScript for queries instead of SQL. When using `spindb run`, pas
240
240
 
241
241
  ```bash
242
242
  # Insert a document
243
- spindb run mydb --sql "db.users.insertOne({name: 'Alice', email: 'alice@example.com'})"
243
+ spindb run mydb -c "db.users.insertOne({name: 'Alice', email: 'alice@example.com'})"
244
244
 
245
245
  # Query documents
246
- spindb run mydb --sql "db.users.find().pretty()"
246
+ spindb run mydb -c "db.users.find().pretty()"
247
247
 
248
248
  # Run a JavaScript file
249
249
  spindb run mydb --file ./scripts/seed.js
250
250
  ```
251
251
 
252
- ### Planned Engines
252
+ #### Redis
253
253
 
254
- | Engine | Type | Status |
255
- |--------|------|--------|
256
- | Redis | In-memory key-value | Planned for v1.2 |
254
+ | | |
255
+ |---|---|
256
+ | Versions | 6, 7, 8 |
257
+ | Default port | 6379 |
258
+ | Default user | None (no auth by default) |
259
+ | Binary source | System installation |
260
+
261
+ Like MySQL and MongoDB, SpinDB uses your system's Redis installation. Redis provides embeddable binaries, but system packages are more reliable for handling dependencies and platform-specific setup.
262
+
263
+ ```bash
264
+ # macOS
265
+ brew install redis
266
+
267
+ # Ubuntu/Debian
268
+ sudo apt install redis-server redis-tools
269
+
270
+ # Windows (Chocolatey)
271
+ choco install redis
272
+
273
+ # Check if SpinDB can find Redis
274
+ spindb deps check --engine redis
275
+ ```
276
+
277
+ Redis uses numbered databases (0-15) instead of named databases. When using `spindb run`, pass Redis commands:
278
+
279
+ ```bash
280
+ # Set a key
281
+ spindb run myredis -c "SET mykey myvalue"
282
+
283
+ # Get a key
284
+ spindb run myredis -c "GET mykey"
285
+
286
+ # Run a Redis command file
287
+ spindb run myredis --file ./scripts/seed.redis
288
+
289
+ # Use iredis for enhanced shell experience
290
+ spindb connect myredis --iredis
291
+ ```
292
+
293
+ **Note:** Redis doesn't support remote dump/restore. Creating containers from remote Redis connection strings is not supported. Use `backup` and `restore` commands for data migration.
257
294
 
258
295
  ---
259
296
 
@@ -267,7 +304,7 @@ spindb run mydb --file ./scripts/seed.js
267
304
  spindb create mydb # PostgreSQL (default)
268
305
  spindb create mydb --engine mysql # MySQL
269
306
  spindb create mydb --engine sqlite # SQLite (file-based)
270
- spindb create mydb --version 16 # Specific PostgreSQL version
307
+ spindb create mydb --db-version 16 # Specific PostgreSQL version
271
308
  spindb create mydb --port 5433 # Custom port
272
309
  spindb create mydb --database my_app # Custom database name
273
310
  spindb create mydb --no-start # Create without starting
@@ -291,10 +328,10 @@ spindb create mydb --from "postgresql://user:pass@host:5432/production"
291
328
 
292
329
  | Option | Description |
293
330
  |--------|-------------|
294
- | `--engine`, `-e` | Database engine (`postgresql`, `mysql`, `sqlite`) |
295
- | `--version`, `-v` | Engine version |
331
+ | `--engine`, `-e` | Database engine (`postgresql`, `mysql`, `sqlite`, `mongodb`, `redis`) |
332
+ | `--db-version` | Engine version (e.g., 17 for PostgreSQL, 8 for Redis) |
296
333
  | `--port`, `-p` | Port number (not applicable for SQLite) |
297
- | `--database`, `-d` | Primary database name |
334
+ | `--database`, `-d` | Primary database name (Redis uses 0-15) |
298
335
  | `--path` | File path for SQLite databases |
299
336
  | `--max-connections` | Maximum database connections (default: 200) |
300
337
  | `--from` | Restore from backup file or connection string |
@@ -355,16 +392,20 @@ spindb connect mydb --install-mycli
355
392
  spindb connect mydb --install-tui
356
393
  ```
357
394
 
358
- #### `run` - Execute SQL/scripts
395
+ #### `run` - Execute SQL/scripts/commands
359
396
 
360
397
  ```bash
361
- spindb run mydb script.sql # Run a SQL file
362
- spindb run mydb --sql "SELECT * FROM users" # Run inline SQL
363
- spindb run mydb seed.sql --database my_app # Target specific database
398
+ spindb run mydb script.sql # Run a SQL file
399
+ spindb run mydb -c "SELECT * FROM users" # Run inline SQL
400
+ spindb run mydb seed.sql --database my_app # Target specific database
364
401
 
365
402
  # MongoDB uses JavaScript instead of SQL
366
- spindb run mydb seed.js # Run a JavaScript file
367
- spindb run mydb --sql "db.users.find().pretty()" # Run inline JavaScript
403
+ spindb run mydb seed.js # Run a JavaScript file
404
+ spindb run mydb -c "db.users.find().pretty()" # Run inline JavaScript
405
+
406
+ # Redis uses Redis commands
407
+ spindb run myredis -c "SET foo bar" # Run inline command
408
+ spindb run myredis seed.redis # Run command file
368
409
  ```
369
410
 
370
411
  #### `url` - Get connection string
@@ -388,17 +429,24 @@ spindb backup mydb --output ./backups/ # Custom directory
388
429
  spindb backup mydb --database my_app # Backup specific database
389
430
  ```
390
431
 
391
- Backup formats:
432
+ Backup formats (vary by engine):
392
433
 
393
434
  ```bash
394
- spindb backup mydb --format sql # Plain SQL (.sql)
395
- spindb backup mydb --format dump # Compressed (.dump for PG, .sql.gz for MySQL)
435
+ spindb backup mydb --format sql # Plain SQL (.sql) or text commands (.redis)
436
+ spindb backup mydb --format dump # Binary format (.dump for PG, .sql.gz for MySQL, .rdb for Redis)
396
437
 
397
438
  # Shorthand
398
439
  spindb backup mydb --sql
399
440
  spindb backup mydb --dump
400
441
  ```
401
442
 
443
+ Format by engine:
444
+ - PostgreSQL: `.sql` (plain SQL) / `.dump` (pg_dump custom)
445
+ - MySQL: `.sql` (plain SQL) / `.sql.gz` (compressed SQL)
446
+ - SQLite: `.sql` (plain SQL) / `.sqlite` (binary copy)
447
+ - MongoDB: `.bson` (BSON dump) / `.archive` (compressed archive)
448
+ - Redis: `.redis` (text commands) / `.rdb` (RDB snapshot)
449
+
402
450
  <details>
403
451
  <summary>All options</summary>
404
452
 
@@ -414,6 +462,27 @@ spindb backup mydb --dump
414
462
 
415
463
  </details>
416
464
 
465
+ #### `backups` - List backup files
466
+
467
+ ```bash
468
+ spindb backups # List backups in current directory
469
+ spindb backups ./data # List backups in specific directory
470
+ spindb backups --all # Include ~/.spindb/backups
471
+ spindb backups --limit 50 # Show more results
472
+ spindb backups --json # JSON output
473
+ ```
474
+
475
+ <details>
476
+ <summary>All options</summary>
477
+
478
+ | Option | Description |
479
+ |--------|-------------|
480
+ | `--all`, `-a` | Include backups from `~/.spindb/backups` |
481
+ | `--limit`, `-n` | Limit number of results (default: 20) |
482
+ | `--json`, `-j` | Output as JSON |
483
+
484
+ </details>
485
+
417
486
  #### `restore` - Restore from backup
418
487
 
419
488
  ```bash
@@ -447,6 +516,78 @@ spindb info mydb
447
516
 
448
517
  </details>
449
518
 
519
+ #### Backup & Restore Format Reference
520
+
521
+ Each engine has specific backup formats and restore behaviors:
522
+
523
+ <details>
524
+ <summary>PostgreSQL</summary>
525
+
526
+ | Format | Extension | Tool | Notes |
527
+ |--------|-----------|------|-------|
528
+ | SQL | `.sql` | pg_dump | Plain text SQL, human-readable |
529
+ | Custom | `.dump` | pg_dump -Fc | Compressed, supports parallel restore |
530
+
531
+ **Restore behavior:** Creates new database or replaces existing. Uses `pg_restore` for `.dump`, `psql` for `.sql`.
532
+
533
+ </details>
534
+
535
+ <details>
536
+ <summary>MySQL</summary>
537
+
538
+ | Format | Extension | Tool | Notes |
539
+ |--------|-----------|------|-------|
540
+ | SQL | `.sql` | mysqldump | Plain text SQL |
541
+ | Compressed | `.sql.gz` | mysqldump + gzip | Gzip compressed SQL |
542
+
543
+ **Restore behavior:** Creates new database or replaces existing. Pipes to `mysql` client.
544
+
545
+ </details>
546
+
547
+ <details>
548
+ <summary>SQLite</summary>
549
+
550
+ | Format | Extension | Tool | Notes |
551
+ |--------|-----------|------|-------|
552
+ | SQL | `.sql` | .dump | Plain text SQL |
553
+ | Binary | `.sqlite` | File copy | Exact copy of database file |
554
+
555
+ **Restore behavior:** Creates new file or replaces existing.
556
+
557
+ </details>
558
+
559
+ <details>
560
+ <summary>MongoDB</summary>
561
+
562
+ | Format | Extension | Tool | Notes |
563
+ |--------|-----------|------|-------|
564
+ | BSON | `.bson` | mongodump | Binary JSON per collection |
565
+ | Archive | `.archive` | mongodump --archive | Single compressed file |
566
+
567
+ **Restore behavior:** Creates new database or replaces existing. Uses `mongorestore`.
568
+
569
+ </details>
570
+
571
+ <details>
572
+ <summary>Redis</summary>
573
+
574
+ | Format | Extension | Tool | Notes |
575
+ |--------|-----------|------|-------|
576
+ | RDB | `.rdb` | BGSAVE | Binary snapshot, requires restart |
577
+ | Text | `.redis` | Custom | Human-readable Redis commands |
578
+
579
+ **Text format detection:** Files are detected as Redis text commands if they contain valid Redis commands (SET, HSET, DEL, etc.), regardless of file extension. This allows restoring files like `users.txt` or `data` without renaming.
580
+
581
+ **Restore behavior:**
582
+ - **RDB (`.rdb`):** Requires stopping Redis, copies file to data directory, restart loads data
583
+ - **Text (`.redis`):** Pipes commands to running Redis instance. Prompts for:
584
+ - **Replace all:** Runs `FLUSHDB` first (clean slate)
585
+ - **Merge:** Adds/updates keys, keeps existing keys not in backup
586
+
587
+ **Note:** Redis uses numbered databases (0-15) that always exist. "Create new database" is not applicable.
588
+
589
+ </details>
590
+
450
591
  ### Container Management
451
592
 
452
593
  #### `list` - List all containers
@@ -596,7 +737,7 @@ SpinDB supports enhanced database shells that provide features like auto-complet
596
737
  | MySQL | `mysql` | `mycli` | `usql` |
597
738
  | SQLite | `sqlite3` | `litecli` | `usql` |
598
739
  | MongoDB | `mongosh` | - | `usql` |
599
- | Redis (planned) | `redis-cli` | `iredis` | - |
740
+ | Redis | `redis-cli` | `iredis` | - |
600
741
 
601
742
  **pgcli / mycli** provide:
602
743
  - Intelligent auto-completion (tables, columns, keywords)
@@ -658,7 +799,7 @@ Native processes mean instant startup and no virtualization overhead.
658
799
  └── mydb.sqlite # Created with: spindb create mydb -e sqlite
659
800
  ```
660
801
 
661
- ### How Data Persists
802
+ ### Data Persistence
662
803
 
663
804
  SpinDB runs databases as **native processes** on your machine. When you start a container:
664
805
 
@@ -676,21 +817,68 @@ When you stop a container:
676
817
 
677
818
  **Your data is never deleted unless you explicitly delete the container.**
678
819
 
820
+ #### Persistence by Engine
821
+
822
+ Each database engine has its own persistence mechanism:
823
+
824
+ | Engine | Mechanism | Durability |
825
+ |--------|-----------|------------|
826
+ | PostgreSQL | Write-Ahead Logging (WAL) | Every commit is immediately durable |
827
+ | MySQL | InnoDB transaction logs | Every commit is immediately durable |
828
+ | SQLite | File-based transactions | Every commit is immediately durable |
829
+ | MongoDB | WiredTiger with journaling | Writes journaled before acknowledged |
830
+ | Redis | RDB snapshots | Periodic snapshots (see below) |
831
+
832
+ **PostgreSQL, MySQL, MongoDB:** These engines use transaction logs or journaling. Every committed write is guaranteed to survive a crash or unexpected shutdown.
833
+
834
+ **SQLite:** As a file-based database, SQLite writes directly to disk on each commit. No server process means no risk of losing in-flight data.
835
+
836
+ **Redis:** SpinDB configures Redis with RDB (Redis Database) snapshots:
837
+ - Save after 900 seconds if at least 1 key changed
838
+ - Save after 300 seconds if at least 10 keys changed
839
+ - Save after 60 seconds if at least 10,000 keys changed
840
+
841
+ This means Redis may lose up to ~60 seconds of writes on an unexpected crash. For local development, this trade-off (speed over strict durability) is typically acceptable. If you need stronger guarantees, use `spindb backup` before stopping work.
842
+
679
843
  ### Binary Sources
680
844
 
681
845
  **PostgreSQL:** Server binaries are downloaded automatically:
682
846
  - **macOS/Linux:** From [zonky.io/embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres-binaries), hosted on Maven Central
683
847
  - **Windows:** From [EnterpriseDB (EDB)](https://www.enterprisedb.com/download-postgresql-binaries), official PostgreSQL distributions
684
848
 
685
- **MySQL:** Uses your system's MySQL installation. SpinDB detects binaries from Homebrew (macOS), apt/pacman (Linux), or Chocolatey/winget/Scoop (Windows).
849
+ **MySQL/MongoDB/Redis:** Uses your system installation. SpinDB detects binaries from Homebrew (macOS), apt/pacman (Linux), or Chocolatey/winget/Scoop (Windows).
850
+
851
+ ### Why Precompiled Binaries for PostgreSQL, but System Installs for Others?
852
+
853
+ This isn't a preference—it's a practical reality of what's available.
854
+
855
+ **PostgreSQL has an excellent embedded binary distribution.** The [zonky.io](https://github.com/zonkyio/embedded-postgres-binaries) project maintains minimal, self-contained PostgreSQL server binaries specifically designed for embedding:
856
+
857
+ - Cross-platform (macOS Intel/ARM, Linux x64/ARM, Windows)
858
+ - Hosted on Maven Central (highly reliable CDN)
859
+ - ~45 MB per version
860
+ - Actively maintained with new PostgreSQL releases
861
+
862
+ This makes multi-version support trivial: need PostgreSQL 14 for a legacy project and 18 for a new one? SpinDB downloads both, and they run side-by-side without conflicts.
863
+
864
+ **No equivalent exists for MySQL, MongoDB, or Redis.** None of these databases have a comparable embedded binary project:
865
+
866
+ - **MySQL:** Oracle distributes MySQL as large installers with system dependencies, not embeddable binaries. There's no "zonky.io for MySQL."
867
+ - **MongoDB:** Server binaries are several hundred MB and aren't designed for portable distribution.
868
+ - **Redis:** While Redis is small (~6-12 MB), there's no official portable distribution. Community Windows ports exist, but macOS/Linux rely on system packages.
869
+
870
+ For these databases, system packages (Homebrew, apt, choco) are the most reliable option. They handle dependencies, platform quirks, and security updates. SpinDB simply orchestrates what's already installed.
871
+
872
+ **Does this limit multi-version support?** Yes, for MySQL/MongoDB/Redis you get whatever version your package manager provides. In practice, this is rarely a problem—developers seldom need multiple versions of these databases simultaneously. If zonky.io-style distributions emerged for other databases, SpinDB could adopt them.
686
873
 
687
874
  ---
688
875
 
689
876
  ## Limitations
690
877
 
691
- - **Client tools required** - `psql` and `mysql` must be installed separately for some operations
878
+ - **Client tools required** - `psql`, `mysql`, `mongosh`, and `redis-cli` must be installed separately for some operations (connecting, backups, restores)
692
879
  - **Local only** - Databases bind to `127.0.0.1`; remote connections planned for v1.1
693
- - **MySQL requires system install** - Unlike PostgreSQL, we don't download MySQL binaries
880
+ - **Single version for MySQL/MongoDB/Redis** - Unlike PostgreSQL, MySQL, MongoDB, and Redis use system installations, so you're limited to one version per machine (see [Why Precompiled Binaries for PostgreSQL?](#why-precompiled-binaries-for-postgresql-but-system-installs-for-others))
881
+ - **Redis remote dump not supported** - Redis doesn't support creating containers from remote connection strings. Use backup/restore for data migration.
694
882
 
695
883
  ---
696
884
 
@@ -704,15 +892,28 @@ See [TODO.md](TODO.md) for the full roadmap.
704
892
  - Secrets management (macOS Keychain)
705
893
 
706
894
  ### v1.2 - Additional Engines
707
- - Redis (in-memory key-value)
708
- - MongoDB (document database)
709
895
  - MariaDB as standalone engine
896
+ - CockroachDB (distributed SQL)
710
897
 
711
898
  ### v1.3 - Advanced Features
712
899
  - Container templates
713
900
  - Scheduled backups
714
901
  - Import from Docker
715
902
 
903
+ ### Possible Future Engines
904
+
905
+ These engines are under consideration but not yet on the roadmap. Community interest and feasibility will determine priority:
906
+
907
+ | Engine | Type | Notes |
908
+ |--------|------|-------|
909
+ | **DuckDB** | Embedded analytical | File-based like SQLite, popular for data/analytics work |
910
+ | **libSQL** | Embedded relational | SQLite fork by Turso with replication and edge support |
911
+ | **Valkey** | Key-value store | Redis fork (post-license change), growing adoption |
912
+ | **Meilisearch** | Search engine | Developer-friendly search, good binary distribution |
913
+ | **Elasticsearch/OpenSearch** | Search engine | Full-text search, common in web applications |
914
+ | **Neo4j** | Graph database | Most popular graph database |
915
+ | **InfluxDB** | Time-series | IoT, metrics, and monitoring use cases |
916
+
716
917
  ---
717
918
 
718
919
  ## Troubleshooting
@@ -775,6 +976,14 @@ SpinDB wouldn't be possible without:
775
976
 
776
977
  ---
777
978
 
979
+ ## Related Work
980
+
981
+ We're actively contributing to the broader embedded database ecosystem:
982
+
983
+ - **[hostdb](https://github.com/robertjbass/hostdb)** - A companion project providing downloadable database binaries (Redis, MySQL/MariaDB, etc.) as GitHub releases. This will enable SpinDB to offer multi-version support for additional engines beyond PostgreSQL.
984
+
985
+ ---
986
+
778
987
  ## License
779
988
 
780
989
  [PolyForm Noncommercial 1.0.0](LICENSE)
@@ -29,11 +29,39 @@ function generateDefaultFilename(
29
29
  }
30
30
 
31
31
  function getExtension(format: 'sql' | 'dump', engine: string): string {
32
+ // Handle 'sql' format (human-readable option)
32
33
  if (format === 'sql') {
33
- return '.sql'
34
+ // MongoDB uses BSON directory format for 'sql' choice
35
+ return engine === 'mongodb' ? '' : '.sql'
36
+ }
37
+
38
+ // Handle 'dump' format (binary/compressed option)
39
+ switch (engine) {
40
+ case 'mysql':
41
+ return '.sql.gz'
42
+ case 'sqlite':
43
+ return '.sqlite'
44
+ case 'mongodb':
45
+ return '.archive'
46
+ case 'redis':
47
+ return '.rdb'
48
+ case 'postgresql':
49
+ default:
50
+ return '.dump'
34
51
  }
35
- // MySQL dump is gzipped SQL, PostgreSQL dump is custom format
36
- return engine === 'mysql' ? '.sql.gz' : '.dump'
52
+ }
53
+
54
+ function getFormatDescription(format: 'sql' | 'dump', engine: string): string {
55
+ if (engine === 'redis') {
56
+ return 'RDB snapshot'
57
+ }
58
+ if (engine === 'mongodb') {
59
+ return format === 'sql' ? 'BSON directory' : 'archive'
60
+ }
61
+ if (engine === 'sqlite') {
62
+ return format === 'sql' ? 'SQL' : 'binary'
63
+ }
64
+ return format === 'sql' ? 'SQL' : 'dump'
37
65
  }
38
66
 
39
67
  export const backupCommand = new Command('backup')
@@ -195,8 +223,9 @@ export const backupCommand = new Command('backup')
195
223
  const outputDir = options.output || process.cwd()
196
224
  const outputPath = join(outputDir, `${filename}${extension}`)
197
225
 
226
+ const formatDesc = getFormatDescription(format, engineName)
198
227
  const backupSpinner = createSpinner(
199
- `Creating ${format === 'sql' ? 'SQL' : 'dump'} backup of "${databaseName}"...`,
228
+ `Creating ${formatDesc} backup of "${databaseName}"...`,
200
229
  )
201
230
  backupSpinner.start()
202
231
 
@@ -222,11 +251,8 @@ export const backupCommand = new Command('backup')
222
251
  console.log()
223
252
  console.log(uiSuccess('Backup complete'))
224
253
  console.log()
225
- console.log(chalk.gray(' File:'), chalk.cyan(result.path))
226
- console.log(
227
- chalk.gray(' Size:'),
228
- chalk.white(formatBytes(result.size)),
229
- )
254
+ console.log(chalk.gray(' Saved to:'), chalk.cyan(result.path))
255
+ console.log(chalk.gray(' Size:'), chalk.white(formatBytes(result.size)))
230
256
  console.log(chalk.gray(' Format:'), chalk.white(result.format))
231
257
  console.log()
232
258
  }