Skip to content

Commit 2d81048

Browse files
authored
Merge pull request #6 from vgarvardt/patch/use-adapter-package
Use adapter package instead of bundling adapters
2 parents 7055b72 + 8e0574b commit 2d81048

File tree

12 files changed

+320
-570
lines changed

12 files changed

+320
-570
lines changed

Gopkg.lock

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
name = "github.com/jmoiron/sqlx"
4646
version = "1.2.0"
4747

48-
[[constraint]]
49-
name = "github.com/vgarvardt/pgx-helpers"
50-
version = "0.1.0"
51-
5248
[[constraint]]
5349
name = "github.com/stretchr/testify"
5450
version = "1.3.0"
51+
52+
[[constraint]]
53+
name = "github.com/vgarvardt/go-pg-adapter"
54+
version = "0.1.1"

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ $ go get -u -v github.com/vgarvardt/go-oauth2-pg
1010

1111
## PostgreSQL drivers
1212

13-
The store accepts an adapter interface that interacts with the DB. The package is bundled with the following adapter implementations
14-
15-
- `database/sql` (e.g. [`github.com/lib/pq`](https://github.com/lib/pq)) - `github.com/vgarvardt/go-oauth2-pg/sql_adapter.New()`
16-
- [`github.com/jmoiron/sqlx.DB`](https://github.com/jmoiron/sqlx) - `github.com/vgarvardt/go-oauth2-pg/sql_adapter.NewX()`
17-
- [`github.com/jackc/pgx.Conn`](https://github.com/jackc/pgx) - `github.com/vgarvardt/go-oauth2-pg/pgx_adapter.NewConn()`
18-
- [`github.com/jackc/pgx.ConnPool`](https://github.com/jackc/pgx) - `github.com/vgarvardt/go-oauth2-pg/pgx_adapter.NewConnPool()`
13+
The store accepts an adapter interface that interacts with the DB. Adapter and implementations are extracted to separate package [`github.com/vgarvardt/go-pg-adapter`](https://github.com/vgarvardt/go-pg-adapter) for easier maintenance.
1914

2015
## Usage example
2116

@@ -28,7 +23,7 @@ import (
2823

2924
"github.com/jackc/pgx"
3025
pg "github.com/vgarvardt/go-oauth2-pg"
31-
pgxAdapter "github.com/vgarvardt/go-oauth2-pg/pgx_adapter"
26+
"github.com/vgarvardt/go-pg-adapter/pgxadapter"
3227
"gopkg.in/oauth2.v3/manage"
3328
)
3429

@@ -39,7 +34,7 @@ func main() {
3934
manager := manage.NewDefaultManager()
4035

4136
// use PostgreSQL token store with pgx.Connection adapter
42-
adapter := pgxAdapter.NewConn(pgxConn)
37+
adapter := pgxadapter.NewConn(pgxConn)
4338
tokenStore, _ := pg.NewTokenStore(adapter, pg.WithTokenStoreGCInterval(time.Minute))
4439
defer tokenStore.Close()
4540

client_store.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"os"
77

88
"github.com/json-iterator/go"
9+
"github.com/vgarvardt/go-pg-adapter"
910
"gopkg.in/oauth2.v3"
1011
"gopkg.in/oauth2.v3/models"
1112
)
1213

1314
// ClientStore PostgreSQL client store
1415
type ClientStore struct {
15-
adapter Adapter
16+
adapter pgadapter.Adapter
1617
tableName string
1718
logger Logger
1819

@@ -28,7 +29,7 @@ type ClientStoreItem struct {
2829
}
2930

3031
// NewClientStore creates PostgreSQL store instance
31-
func NewClientStore(adapter Adapter, options ...ClientStoreOption) (*ClientStore, error) {
32+
func NewClientStore(adapter pgadapter.Adapter, options ...ClientStoreOption) (*ClientStore, error) {
3233
store := &ClientStore{
3334
adapter: adapter,
3435
tableName: "oauth2_clients",

pg.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package pg
22

3-
import "errors"
4-
5-
// ErrNoRows is the driver-agnostic error returned when no record is found
6-
var ErrNoRows = errors.New("sql: no rows in result set")
7-
8-
// Adapter represents DB access layer interface for different PostgreSQL drivers
9-
type Adapter interface {
10-
Exec(query string, args ...interface{}) error
11-
SelectOne(dst interface{}, query string, args ...interface{}) error
12-
}
13-
143
// Logger is the PostgreSQL store logger interface
154
type Logger interface {
165
Printf(format string, v ...interface{})

pgx_adapter/adapter.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)