diff --git a/frontend/src/components/ConnectionModal.tsx b/frontend/src/components/ConnectionModal.tsx index 534e58c..b6c0c3c 100644 --- a/frontend/src/components/ConnectionModal.tsx +++ b/frontend/src/components/ConnectionModal.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { Modal, Form, Input, InputNumber, Button, message, Checkbox, Divider, Select, Alert, Card, Row, Col, Typography } from 'antd'; +import { Modal, Form, Input, InputNumber, Button, message, Checkbox, Divider, Select, Alert, Card, Row, Col, Typography, Collapse } from 'antd'; import { DatabaseOutlined, ConsoleSqlOutlined, FileTextOutlined, CloudServerOutlined, AppstoreAddOutlined } from '@ant-design/icons'; import { useStore } from '../store'; import { MySQLConnect, MySQLGetDatabases } from '../../wailsjs/go/app/App'; @@ -42,7 +42,8 @@ const ConnectionModal: React.FC<{ open: boolean; onClose: () => void; initialVal sshPassword: initialValues.config.ssh?.password, sshKeyPath: initialValues.config.ssh?.keyPath, driver: (initialValues.config as any).driver, - dsn: (initialValues.config as any).dsn + dsn: (initialValues.config as any).dsn, + timeout: (initialValues.config as any).timeout || 30 }); setUseSSH(initialValues.config.useSSH || false); setDbType(initialValues.config.type); @@ -137,7 +138,8 @@ const ConnectionModal: React.FC<{ open: boolean; onClose: () => void; initialVal useSSH: !!values.useSSH, ssh: sshConfig, driver: values.driver, - dsn: values.dsn + dsn: values.dsn, + timeout: Number(values.timeout || 30) }; }; @@ -196,7 +198,7 @@ const ConnectionModal: React.FC<{ open: boolean; onClose: () => void; initialVal
{ if (testResult) setTestResult(null); // Clear result on change if (changed.useSSH !== undefined) setUseSSH(changed.useSSH); @@ -282,6 +284,26 @@ const ConnectionModal: React.FC<{ open: boolean; onClose: () => void; initialVal )} + + + + + + + ) + }]} + /> )} diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index fcf5511..5d44550 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -79,6 +79,7 @@ export namespace connection { ssh: SSHConfig; driver?: string; dsn?: string; + timeout?: number; static createFrom(source: any = {}) { return new ConnectionConfig(source); @@ -96,6 +97,7 @@ export namespace connection { this.ssh = this.convertValues(source["ssh"], SSHConfig); this.driver = source["driver"]; this.dsn = source["dsn"]; + this.timeout = source["timeout"]; } convertValues(a: any, classs: any, asMap: boolean = false): any { diff --git a/internal/connection/types.go b/internal/connection/types.go index 6cf65ac..5e29bed 100644 --- a/internal/connection/types.go +++ b/internal/connection/types.go @@ -21,6 +21,7 @@ type ConnectionConfig struct { SSH SSHConfig `json:"ssh"` Driver string `json:"driver,omitempty"` // For custom connection DSN string `json:"dsn,omitempty"` // For custom connection + Timeout int `json:"timeout,omitempty"` // Connection timeout in seconds (default: 30) } // QueryResult is the standard response format for Wails methods diff --git a/internal/db/mysql_impl.go b/internal/db/mysql_impl.go index a884cf2..6cf239a 100644 --- a/internal/db/mysql_impl.go +++ b/internal/db/mysql_impl.go @@ -30,8 +30,13 @@ func (m *MySQLDB) getDSN(config connection.ConnectionConfig) string { } } - return fmt.Sprintf("%s:%s@%s(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", - config.User, config.Password, protocol, address, database) + timeout := config.Timeout + if timeout <= 0 { + timeout = 30 + } + + return fmt.Sprintf("%s:%s@%s(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local&timeout=%ds", + config.User, config.Password, protocol, address, database, timeout) } func (m *MySQLDB) Connect(config connection.ConnectionConfig) error {