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.
- package/README.md +421 -294
- package/cli/commands/config.ts +7 -1
- package/cli/commands/connect.ts +1 -0
- package/cli/commands/create.ts +7 -7
- package/cli/commands/edit.ts +10 -0
- package/cli/commands/engines.ts +10 -188
- package/cli/commands/info.ts +7 -14
- package/cli/commands/list.ts +2 -9
- package/cli/commands/logs.ts +130 -0
- package/cli/commands/menu/backup-handlers.ts +798 -0
- package/cli/commands/menu/container-handlers.ts +832 -0
- package/cli/commands/menu/engine-handlers.ts +382 -0
- package/cli/commands/menu/index.ts +184 -0
- package/cli/commands/menu/shared.ts +26 -0
- package/cli/commands/menu/shell-handlers.ts +331 -0
- package/cli/commands/menu/sql-handlers.ts +197 -0
- package/cli/commands/menu/update-handlers.ts +94 -0
- package/cli/commands/run.ts +150 -0
- package/cli/commands/url.ts +19 -5
- package/cli/constants.ts +10 -0
- package/cli/helpers.ts +152 -0
- package/cli/index.ts +5 -2
- package/cli/ui/prompts.ts +3 -11
- package/config/defaults.ts +5 -29
- package/core/binary-manager.ts +2 -2
- package/core/container-manager.ts +3 -2
- package/core/dependency-manager.ts +0 -163
- package/core/error-handler.ts +0 -26
- package/core/platform-service.ts +60 -40
- package/core/start-with-retry.ts +3 -28
- package/core/transaction-manager.ts +0 -8
- package/engines/base-engine.ts +10 -0
- package/engines/mysql/binary-detection.ts +1 -1
- package/engines/mysql/index.ts +78 -2
- package/engines/postgresql/index.ts +49 -0
- package/package.json +1 -1
- package/types/index.ts +7 -4
- 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
package/types/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ContainerConfig = {
|
|
2
2
|
name: string
|
|
3
|
-
engine:
|
|
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
|
|
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:
|
|
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?:
|
|
147
|
+
engine?: Engine
|
|
145
148
|
version?: string
|
|
146
149
|
port?: number
|
|
147
150
|
}
|