dbdesk-studio 0.1.2 → 0.1.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 (3) hide show
  1. package/README.md +38 -2
  2. package/dist/cli.js +77 -9
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -23,7 +23,29 @@ npx dbdesk-studio
23
23
 
24
24
  ## Quick Start
25
25
 
26
- After running `dbdesk-studio`, the web interface will start at `http://localhost:3000`
26
+ After running `dbdesk-studio`, the web interface will start at `http://localhost:9876`
27
+
28
+ ### Quick Connect with URI
29
+
30
+ You can connect directly to a database using a connection URI:
31
+
32
+ ```bash
33
+ # PostgreSQL
34
+ npx dbdesk-studio --uri "postgresql://user:password@localhost:5432/mydb"
35
+
36
+ # MySQL
37
+ npx dbdesk-studio --uri "mysql://user:password@localhost:3306/mydb"
38
+
39
+ # With SSL
40
+ npx dbdesk-studio --uri "postgresql://user:password@localhost:5432/mydb?sslmode=require"
41
+ ```
42
+
43
+ This will start the studio and automatically open your browser connected to the specified database.
44
+
45
+ > ⚠️ **Security Note:** Passing credentials directly in the command line may expose them in shell history and process listings. For sensitive environments, consider:
46
+ > - Using environment variables: `--uri "$DATABASE_URL"`
47
+ > - Omitting the password and entering it in the UI
48
+ > - Using `.pgpass` or similar credential files for your database
27
49
 
28
50
  ## Features
29
51
 
@@ -45,13 +67,27 @@ After running `dbdesk-studio`, the web interface will start at `http://localhost
45
67
  # Start the studio
46
68
  dbdesk-studio
47
69
 
70
+ # Connect directly with a URI
71
+ dbdesk-studio --uri "postgresql://user:pass@localhost:5432/mydb"
72
+
48
73
  # The web interface opens automatically
49
74
  # Default: http://localhost:9876
50
75
  ```
51
76
 
77
+ ## CLI Options
78
+
79
+ ```
80
+ --uri <connection-string> Database connection URI (opens directly to connection)
81
+ Supports: postgresql://, postgres://, mysql://
82
+ --backend-port <port> Backend server port (default: 6789)
83
+ --frontend-port <port> Frontend server port (default: 9876)
84
+ --backend-url <url> Backend URL for frontend (default: http://localhost:6789)
85
+ --help, -h Show help message
86
+ ```
87
+
52
88
  ## Configuration
53
89
 
54
- Set database connection details in the UI or use environment variables.
90
+ Set database connection details directly in the web interface.
55
91
 
56
92
  ## License
57
93
 
package/dist/cli.js CHANGED
@@ -9,7 +9,8 @@ const __dirname = dirname(__filename);
9
9
  const DEFAULT_CONFIG = {
10
10
  backendPort: 6789,
11
11
  frontendPort: 9876,
12
- backendUrl: 'http://localhost:6789'
12
+ backendUrl: 'http://localhost:6789',
13
+ uri: undefined
13
14
  };
14
15
  function parseArgs() {
15
16
  const args = process.argv.slice(2);
@@ -33,9 +34,25 @@ function parseArgs() {
33
34
  config.backendUrl = url;
34
35
  i++;
35
36
  }
36
- else if (args[i] === '--help' || args[i] === '-h') {
37
- printHelp();
38
- process.exit(0);
37
+ else if (args[i] === '--uri') {
38
+ const next = args[i + 1];
39
+ if (!next || next.startsWith('-')) {
40
+ console.error('Error: --uri requires a value.');
41
+ printHelp();
42
+ process.exit(1);
43
+ }
44
+ config.uri = next;
45
+ i++;
46
+ }
47
+ else {
48
+ const arg = args[i];
49
+ if (arg && arg.startsWith('--uri=')) {
50
+ config.uri = arg.slice('--uri='.length);
51
+ }
52
+ else if (arg === '--help' || arg === '-h') {
53
+ printHelp();
54
+ process.exit(0);
55
+ }
39
56
  }
40
57
  }
41
58
  return config;
@@ -45,13 +62,17 @@ function printHelp() {
45
62
  Usage: dbdesk-studio [options]
46
63
 
47
64
  Options:
48
- --backend-port <port> Backend server port (default: 6789)
49
- --frontend-port <port> Frontend server port (default: 9876)
50
- --backend-url <url> Backend URL for frontend (default: http://localhost:6789)
51
- --help, -h Show this help message
65
+ --uri <connection-string> Database connection URI (opens directly to connection)
66
+ Supports: postgresql://, postgres://, mysql://
67
+ --backend-port <port> Backend server port (default: 6789)
68
+ --frontend-port <port> Frontend server port (default: 9876)
69
+ --backend-url <url> Backend URL for frontend (default: http://localhost:6789)
70
+ --help, -h Show this help message
52
71
 
53
72
  Examples:
54
73
  dbdesk-studio
74
+ dbdesk-studio --uri "postgresql://user:pass@localhost:5432/mydb"
75
+ dbdesk-studio --uri="mysql://user:pass@localhost:3306/mydb"
55
76
  dbdesk-studio --backend-port 4000 --frontend-port 8080
56
77
  dbdesk-studio --backend-url http://api.example.com
57
78
  `);
@@ -179,11 +200,58 @@ async function main() {
179
200
  startBackend(config),
180
201
  startFrontend(config)
181
202
  ]);
182
- console.log(`dbdesk-studio running at http://localhost:${config.frontendPort}`);
203
+ const baseUrl = `http://localhost:${config.frontendPort}`;
204
+ // If URI is provided, create connection via backend API first
205
+ if (config.uri) {
206
+ console.log('dbdesk-studio running...');
207
+ console.log('Creating connection from URI...');
208
+ try {
209
+ const connectionId = await createConnectionFromUri(config.uri, config.backendPort);
210
+ const appUrl = `${baseUrl}/connections/${connectionId}`;
211
+ console.log(`Connection created! Opening ${baseUrl}/connections/<id>`);
212
+ openBrowser(appUrl);
213
+ }
214
+ catch (err) {
215
+ console.error('Failed to create connection from URI:', err instanceof Error ? err.message : err);
216
+ console.log(`You can still access the studio at ${baseUrl}`);
217
+ openBrowser(baseUrl);
218
+ }
219
+ }
220
+ else {
221
+ console.log(`dbdesk-studio running at ${baseUrl}`);
222
+ }
183
223
  }
184
224
  catch (err) {
185
225
  console.error('❌ Failed to start services:', err);
186
226
  process.exit(1);
187
227
  }
188
228
  }
229
+ async function createConnectionFromUri(uri, backendPort) {
230
+ const response = await fetch(`http://localhost:${backendPort}/api/connections/from-uri`, {
231
+ method: 'POST',
232
+ headers: {
233
+ 'Content-Type': 'application/json'
234
+ },
235
+ body: JSON.stringify({ uri })
236
+ });
237
+ if (!response.ok) {
238
+ const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
239
+ throw new Error(errorData.error || `HTTP ${response.status}`);
240
+ }
241
+ const profile = await response.json();
242
+ return profile.id;
243
+ }
244
+ function openBrowser(url) {
245
+ const platform = process.platform;
246
+ if (platform === 'darwin') {
247
+ spawn('open', [url], { stdio: 'ignore', detached: true }).unref();
248
+ }
249
+ else if (platform === 'win32') {
250
+ // 'start' is a cmd.exe builtin, not an executable
251
+ spawn('cmd.exe', ['/c', 'start', '""', url], { stdio: 'ignore', detached: true }).unref();
252
+ }
253
+ else {
254
+ spawn('xdg-open', [url], { stdio: 'ignore', detached: true }).unref();
255
+ }
256
+ }
189
257
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbdesk-studio",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Database management studio with a web interface",
5
5
  "type": "module",
6
6
  "bin": {
@@ -35,4 +35,4 @@
35
35
  "type": "git",
36
36
  "url": "https://github.com/zexahq/dbdesk-studio.git"
37
37
  }
38
- }
38
+ }