mirror of
https://github.com/veops/oneterm.git
synced 2025-10-05 23:37:03 +08:00
35 lines
799 B
Go
35 lines
799 B
Go
package db
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/veops/oneterm/internal/model"
|
|
)
|
|
|
|
// getPostgreSQLConfig returns PostgreSQL client configuration
|
|
func getPostgreSQLConfig(ip string, port int, account *model.Account) DBClientConfig {
|
|
// Set PGPASSWORD environment variable instead of using -W
|
|
os.Setenv("PGPASSWORD", account.Password)
|
|
|
|
args := []string{
|
|
"-h", ip,
|
|
"-p", fmt.Sprintf("%d", port),
|
|
"-U", account.Account,
|
|
"postgres", // Default database name
|
|
}
|
|
|
|
// Add database name if specified in the account.Account field (username/database format)
|
|
parts := strings.Split(account.Account, "/")
|
|
if len(parts) > 1 {
|
|
args = append(args, "-d", parts[1])
|
|
}
|
|
|
|
return DBClientConfig{
|
|
Command: "psql",
|
|
Args: args,
|
|
ExitAliases: []string{"\\q", "exit", "quit"},
|
|
}
|
|
}
|