spindb 0.6.0 → 0.7.3

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 (38) hide show
  1. package/README.md +421 -294
  2. package/cli/commands/config.ts +7 -1
  3. package/cli/commands/connect.ts +1 -0
  4. package/cli/commands/create.ts +7 -7
  5. package/cli/commands/edit.ts +10 -0
  6. package/cli/commands/engines.ts +10 -188
  7. package/cli/commands/info.ts +7 -14
  8. package/cli/commands/list.ts +2 -9
  9. package/cli/commands/logs.ts +130 -0
  10. package/cli/commands/menu/backup-handlers.ts +798 -0
  11. package/cli/commands/menu/container-handlers.ts +832 -0
  12. package/cli/commands/menu/engine-handlers.ts +382 -0
  13. package/cli/commands/menu/index.ts +184 -0
  14. package/cli/commands/menu/shared.ts +26 -0
  15. package/cli/commands/menu/shell-handlers.ts +331 -0
  16. package/cli/commands/menu/sql-handlers.ts +197 -0
  17. package/cli/commands/menu/update-handlers.ts +94 -0
  18. package/cli/commands/run.ts +150 -0
  19. package/cli/commands/url.ts +19 -5
  20. package/cli/constants.ts +10 -0
  21. package/cli/helpers.ts +152 -0
  22. package/cli/index.ts +5 -2
  23. package/cli/ui/prompts.ts +3 -11
  24. package/config/defaults.ts +5 -29
  25. package/core/binary-manager.ts +2 -2
  26. package/core/container-manager.ts +3 -2
  27. package/core/dependency-manager.ts +0 -163
  28. package/core/error-handler.ts +0 -26
  29. package/core/platform-service.ts +60 -40
  30. package/core/start-with-retry.ts +3 -28
  31. package/core/transaction-manager.ts +0 -8
  32. package/engines/base-engine.ts +10 -0
  33. package/engines/mysql/binary-detection.ts +1 -1
  34. package/engines/mysql/index.ts +78 -2
  35. package/engines/postgresql/index.ts +49 -0
  36. package/package.json +1 -1
  37. package/types/index.ts +7 -4
  38. package/cli/commands/menu.ts +0 -2670
@@ -457,6 +457,55 @@ export class PostgreSQLEngine extends BaseEngine {
457
457
  ): Promise<BackupResult> {
458
458
  return createBackup(container, outputPath, options)
459
459
  }
460
+
461
+ /**
462
+ * Run a SQL file or inline SQL statement against the database
463
+ * CLI wrapper: psql -h 127.0.0.1 -p {port} -U postgres -d {db} -f {file}
464
+ * CLI wrapper: psql -h 127.0.0.1 -p {port} -U postgres -d {db} -c "{sql}"
465
+ */
466
+ async runScript(
467
+ container: ContainerConfig,
468
+ options: { file?: string; sql?: string; database?: string },
469
+ ): Promise<void> {
470
+ const { port } = container
471
+ const db = options.database || container.database || 'postgres'
472
+ const psqlPath = await this.getPsqlPath()
473
+
474
+ const args = [
475
+ '-h',
476
+ '127.0.0.1',
477
+ '-p',
478
+ String(port),
479
+ '-U',
480
+ defaults.superuser,
481
+ '-d',
482
+ db,
483
+ ]
484
+
485
+ if (options.file) {
486
+ args.push('-f', options.file)
487
+ } else if (options.sql) {
488
+ args.push('-c', options.sql)
489
+ } else {
490
+ throw new Error('Either file or sql option must be provided')
491
+ }
492
+
493
+ return new Promise((resolve, reject) => {
494
+ const proc = spawn(psqlPath, args, { stdio: 'inherit' })
495
+
496
+ proc.on('error', (err: NodeJS.ErrnoException) => {
497
+ reject(err)
498
+ })
499
+
500
+ proc.on('close', (code) => {
501
+ if (code === 0) {
502
+ resolve()
503
+ } else {
504
+ reject(new Error(`psql exited with code ${code}`))
505
+ }
506
+ })
507
+ })
508
+ }
460
509
  }
461
510
 
462
511
  export const postgresqlEngine = new PostgreSQLEngine()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spindb",
3
- "version": "0.6.0",
3
+ "version": "0.7.3",
4
4
  "description": "Spin up local database containers without Docker. A DBngin-like CLI for PostgreSQL and MySQL.",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type ContainerConfig = {
2
2
  name: string
3
- engine: EngineName
3
+ engine: Engine
4
4
  version: string
5
5
  port: number
6
6
  database: string
@@ -14,7 +14,10 @@ export type ContainerConfig = {
14
14
  * Supported database engine names
15
15
  * Extendable for future engines (sqlite, etc.)
16
16
  */
17
- export type EngineName = 'postgresql' | 'mysql'
17
+ export enum Engine {
18
+ PostgreSQL = 'postgresql',
19
+ MySQL = 'mysql',
20
+ }
18
21
 
19
22
  export type ProgressCallback = (progress: {
20
23
  stage: string
@@ -22,7 +25,7 @@ export type ProgressCallback = (progress: {
22
25
  }) => void
23
26
 
24
27
  export type InstalledBinary = {
25
- engine: string
28
+ engine: Engine
26
29
  version: string
27
30
  platform: string
28
31
  arch: string
@@ -141,7 +144,7 @@ export type SpinDBConfig = {
141
144
  }
142
145
  // Default settings
143
146
  defaults?: {
144
- engine?: EngineName
147
+ engine?: Engine
145
148
  version?: string
146
149
  port?: number
147
150
  }