-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ad4170
commit 464dadb
Showing
9 changed files
with
119 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package qg | ||
|
||
import ( | ||
"database/sql/driver" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/jackc/pgx/v4" | ||
"github.com/jackc/pgx/v4/stdlib" | ||
) | ||
|
||
func GetConnector(host string, port int, username string, password string, database string) (driver.Connector, error) { | ||
u := &url.URL{ | ||
Scheme: "postgres", | ||
Host: fmt.Sprintf("%s:%d", host, port), | ||
User: url.UserPassword(username, password), | ||
Path: database, | ||
} | ||
|
||
return GetConnectorFromURL(u) | ||
} | ||
|
||
func GetConnectorFromURL(u *url.URL) (driver.Connector, error) { | ||
return GetConnectorFromConnStr(u.String()) | ||
} | ||
|
||
func GetConnectorFromConnStr(connStr string) (driver.Connector, error) { | ||
cfg, err := pgx.ParseConfig(connStr) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
connector := stdlib.GetConnector(*cfg, stdlib.OptionAfterConnect(PrepareStatements)) | ||
|
||
return connector, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
module github.com/kanmu/qg | ||
|
||
go 1.16 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/jackc/pgconn v1.14.3 | ||
github.com/jackc/pgx/v4 v4.18.3 | ||
gopkg.in/guregu/null.v3 v3.0.2-0.20160228005316-41961cea0328 | ||
) | ||
|
||
require ( | ||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect | ||
github.com/jackc/pgconn v1.14.3 // indirect | ||
github.com/jackc/pgio v1.0.0 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgproto3/v2 v2.3.3 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect | ||
github.com/jackc/pgtype v1.14.0 // indirect | ||
github.com/lib/pq v1.10.3 // indirect | ||
github.com/shopspring/decimal v1.3.1 // indirect | ||
gopkg.in/guregu/null.v3 v3.0.2-0.20160228005316-41961cea0328 | ||
golang.org/x/crypto v0.20.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.