Skip to content

Commit

Permalink
Update pgx v3 to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Oct 2, 2024
1 parent 2999bea commit 1f7b9f3
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 134 deletions.
29 changes: 10 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@ on:
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
# Container operations, such as postgres, are only supported on Linux runners
# - macOS-latest
# - windows-latest
go:
- "1.21"
- "1.20"
- "1.19"
- "1.18"
- "1.17"
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
Expand All @@ -31,13 +21,14 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Checkout code
uses: actions/checkout@v4
go-version-file: go.mod
cache: false

- name: Lint
uses: golangci/golangci-lint-action@v4
Expand Down
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
linters:
enable:
- gofmt
- gosimple
- misspell
run:
timeout: 5m
issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ test: vet
vet:
go vet ./...

.PHONY: lint
lint:
golangci-lint run

.PHONY: db
db:
psql -U postgres -h localhost -d postgres -c 'CREATE USER qgtest;'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This library is still under heavy development, and might significantly change AP
## Test

```
docker-compose up -d
docker compose up -d
make db
make table
make test
Expand Down
37 changes: 37 additions & 0 deletions connector.go
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
}
21 changes: 15 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
module github.com/kanmu/qg

go 1.16
go 1.21

require (
github.com/hashicorp/go-version v1.3.0 // indirect
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/pgx v3.0.1-0.20170728201109-511b90478f17+incompatible
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/pkg/errors v0.8.0 // 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
)
186 changes: 178 additions & 8 deletions go.sum

Large diffs are not rendered by default.

Loading

0 comments on commit 1f7b9f3

Please sign in to comment.