Skip to content

Commit eed1b36

Browse files
committed
Removing Connect and Connect2 methods from Conn, the only way to establish connection is with connection string, and calling NewConn, or better NewConnPool.
1 parent 88ccb4c commit eed1b36

File tree

5 files changed

+9
-16
lines changed

5 files changed

+9
-16
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Each row is array of values. Each column is array of ResultColumn objects.
106106

107107
Execute query with params:
108108
```go
109-
rst, err := conn.ExecuteSql("select au_id, au_lname, au_fname from authors where au_id = ?", "998-72-3567")
109+
rst, err := conn.ExecuteSql("select au_id, au_lname, au_fname from authors where au_id = ?", "998-72-3567")
110110
```
111111

112112

conn.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,12 @@ func (conn *Conn) addError(err string) {
8686
conn.Error += err
8787
}
8888

89-
//Connect to the database, returns new connection or error.
90-
func Connect(user, pwd, host, database string) (*Conn, error) {
91-
return connectWithCredentials(&credentials{user: user, pwd: pwd, host: host, database: database})
92-
}
93-
94-
//Connect to the database with mirroring support, returns new connection or error.
95-
func Connect2(user, pwd, host, mirrorHost, database string) (*Conn, error) {
96-
return connectWithCredentials(&credentials{user: user, pwd: pwd, host: host, database: database, mirrorHost: mirrorHost})
97-
}
98-
9989
//Connect to the database with connection string, returns new connection or error.
10090
//Example:
101-
// conn, err := ConnectWithConnectionString("host=myServerA;database=myDataBase;user=myUsername;pwd=myPassword;mirror=myMirror")
91+
// conn, err := NewConn("host=myServerA;database=myDataBase;user=myUsername;pwd=myPassword;mirror=myMirror")
10292
//
10393
//Mirror is optional, other params are mandatory.
104-
func ConnectWithConnectionString(connStr string) (*Conn, error) {
94+
func NewConn(connStr string) (*Conn, error) {
10595
return connectWithCredentials(NewCredentials(connStr))
10696
}
10797

conn_pool.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ type ConnPool struct {
4646
//There is always one connection in the pool.
4747
//
4848
//Returns err if fails to create initial connection.
49+
//Valid connection string examples:
50+
// "host=myServerA;database=myDataBase;user=myUsername;pwd=myPassword;"
51+
// "host=myServerA;database=myDataBase;user=myUsername;pwd=myPassword;mirror=myMirror"
4952
func NewConnPool(connStr string) (*ConnPool, error) {
5053
p := &ConnPool{
5154
connStr: connStr,
@@ -70,7 +73,7 @@ func NewConnPool(connStr string) (*ConnPool, error) {
7073
}
7174

7275
func (p *ConnPool) newConn() (*Conn, error) {
73-
conn, err := ConnectWithConnectionString(p.connStr)
76+
conn, err := NewConn(p.connStr)
7477
if err == nil {
7578
conn.belongsToPool = p
7679
//share stored procedure params cache between connections in the pool

conn_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ create procedure freetds_return_value as
5151
return -5`}
5252

5353
func ConnectToTestDb(t *testing.T) *Conn {
54-
conn, err := ConnectWithConnectionString(testDbConnStr(1))
54+
conn, err := NewConn(testDbConnStr(1))
5555
if err != nil {
5656
t.Errorf("can't connect to the test database")
5757
return nil

mssql_conn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type MssqlDriver struct{}
1515

1616
//implements Open for Driver interface from http://golang.org/src/pkg/database/sql/driver/driver.go
1717
func (d *MssqlDriver) Open(dsn string) (driver.Conn, error) {
18-
conn, err := ConnectWithConnectionString(dsn)
18+
conn, err := NewConn(dsn)
1919
if err != nil {
2020
return nil, err
2121
}

0 commit comments

Comments
 (0)