15
15
package client
16
16
17
17
import (
18
+ "bytes"
18
19
"fmt"
19
20
20
21
"github.com/go-sql-driver/mysql"
21
22
)
22
23
23
- func CreateMySQLConfig (user , password string , mysqlServiceHost string ,
24
- mysqlServicePort string , dbName string , mysqlGroupConcatMaxLen string , mysqlExtraParams map [string ]string ,
24
+ const (
25
+ MYSQL_TEXT_FORMAT string = "longtext not null"
26
+ MYSQL_EXIST_ERROR string = "database exists"
27
+
28
+ PGX_TEXT_FORMAT string = "text"
29
+ PGX_EXIST_ERROR string = "already exists"
30
+ )
31
+
32
+ func CreateMySQLConfig (user , password , mysqlServiceHost , mysqlServicePort ,
33
+ dbName , mysqlGroupConcatMaxLen string , mysqlExtraParams map [string ]string ,
25
34
) * mysql.Config {
26
35
params := map [string ]string {
27
36
"charset" : "utf8" ,
@@ -44,3 +53,26 @@ func CreateMySQLConfig(user, password string, mysqlServiceHost string,
44
53
AllowNativePasswords : true ,
45
54
}
46
55
}
56
+
57
+ func CreatePostgreSQLConfig (user , password , postgresHost , dbName string , postgresPort uint16 ,
58
+ ) string {
59
+ var b bytes.Buffer
60
+ if dbName != "" {
61
+ fmt .Fprintf (& b , "database=%s " , dbName )
62
+ }
63
+ if user != "" {
64
+ fmt .Fprintf (& b , "user=%s " , user )
65
+ }
66
+ if password != "" {
67
+ fmt .Fprintf (& b , "password=%s " , password )
68
+ }
69
+ if postgresHost != "" {
70
+ fmt .Fprintf (& b , "host=%s " , postgresHost )
71
+ }
72
+ if postgresPort != 0 {
73
+ fmt .Fprintf (& b , "port=%d " , postgresPort )
74
+ }
75
+ fmt .Fprint (& b , "sslmode=disable" )
76
+
77
+ return b .String ()
78
+ }
0 commit comments