File tree 2 files changed +35
-38
lines changed
2 files changed +35
-38
lines changed Original file line number Diff line number Diff line change 1
1
package helpers
2
2
3
3
import (
4
+ "fmt"
5
+ "net/url"
4
6
"os"
5
7
"path/filepath"
6
8
7
9
"github.com/pelletier/go-toml/v2"
8
10
11
+ "github.com/jorgerojas26/lazysql/drivers"
9
12
"github.com/jorgerojas26/lazysql/models"
10
13
)
11
14
@@ -26,14 +29,43 @@ func LoadConfig() (Config, error) {
26
29
return config , err
27
30
}
28
31
29
- for idx , cfg := range config .Connections {
30
- cfg .ParseURL ()
31
- config .Connections [idx ].URL = cfg .URL
32
+ for idx , conn := range config .Connections {
33
+ config .Connections [idx ].URL = ParseConfigURL (& conn )
32
34
}
33
35
34
36
return config , nil
35
37
}
36
38
39
+ // ParseConfigURL will manually parse config url if url empty
40
+ //
41
+ // it main purpose is for handling username & password with special characters
42
+ //
43
+ // only sqlserver for now
44
+ func ParseConfigURL (conn * models.Connection ) string {
45
+ if conn .URL != "" {
46
+ return conn .URL
47
+ }
48
+
49
+ // only sqlserver for now
50
+ if conn .Provider != drivers .DriverMSSQL {
51
+ return conn .URL
52
+ }
53
+
54
+ user := url .QueryEscape (conn .Username )
55
+ pass := url .QueryEscape (conn .Password )
56
+
57
+ return fmt .Sprintf (
58
+ "%s://%s:%s@%s:%s?database=%s%s" ,
59
+ conn .Provider ,
60
+ user ,
61
+ pass ,
62
+ conn .Hostname ,
63
+ conn .Port ,
64
+ conn .DBName ,
65
+ conn .URLParams ,
66
+ )
67
+ }
68
+
37
69
func LoadConnections () (connections []models.Connection , err error ) {
38
70
config , err := LoadConfig ()
39
71
if err != nil {
Original file line number Diff line number Diff line change 1
1
package models
2
2
3
3
import (
4
- "fmt"
5
- "net/url"
6
-
7
4
"github.com/rivo/tview"
8
5
)
9
6
@@ -25,38 +22,6 @@ type Connection struct {
25
22
Commands []* Command
26
23
}
27
24
28
- // ParseURL will manually parse url if url empty
29
- //
30
- // for handling username & password with special characters
31
- //
32
- // only sqlserver for now
33
- //
34
- // need to refactor if wanted to reuse driver list in drivers/constants.go
35
- func (c * Connection ) ParseURL () {
36
- if c .URL != "" {
37
- return
38
- }
39
-
40
- // only sqlserver for now
41
- if c .Provider != "sqlserver" {
42
- return
43
- }
44
-
45
- user := url .QueryEscape (c .Username )
46
- pass := url .QueryEscape (c .Password )
47
-
48
- c .URL = fmt .Sprintf (
49
- "%s://%s:%s@%s:%s?database=%s%s" ,
50
- c .Provider ,
51
- user ,
52
- pass ,
53
- c .Hostname ,
54
- c .Port ,
55
- c .DBName ,
56
- c .URLParams ,
57
- )
58
- }
59
-
60
25
type Command struct {
61
26
Command string
62
27
WaitForPort string
You can’t perform that action at this time.
0 commit comments