Simple adapter interface and implementations for different PostgreSQL drivers for Go.
package pgadapter
import (
"context"
"errors"
)
var (
// ErrNoRows is the driver-agnostic error returned when no record is found
ErrNoRows = errors.New("sql: no rows in result set")
// ErrManyRows is the driver-agnostic error returned when more than one record is found
// while only one was expected
ErrManyRows = errors.New("sql: more than one row in result set")
)
// Adapter represents DB access layer interface for different PostgreSQL drivers
type Adapter interface {
Exec(ctx context.Context, query string, args ...interface{}) error
SelectOne(ctx context.Context, dst interface{}, query string, args ...interface{}) error
}
go get -u -v github.com/vgarvardt/go-pg-adapter
The package bundles the following adapter implementations:
database/sql.DB
(e.g.github.com/lib/pq
) -github.com/vgarvardt/go-pg-adapter/sqladapter.New()
database/sql.Conn
(e.g.github.com/lib/pq
) -github.com/vgarvardt/go-pg-adapter/sqladapter.NewConn()
github.com/jmoiron/sqlx.DB
-github.com/vgarvardt/go-pg-adapter/sqladapter.NewX()
github.com/jackc/pgx.Conn
(pgx v3) -github.com/vgarvardt/go-pg-adapter/pgx3adapter.NewConn()
github.com/jackc/pgx.ConnPool
(pgx v3) -github.com/vgarvardt/go-pg-adapter/pgx3adapter.NewConnPool()
github.com/jackc/pgx/v4.Conn
(pgx v4) -github.com/vgarvardt/go-pg-adapter/pgx4adapter.NewConn()
github.com/jackc/pgx/v4/pgxpool.Pool
(pgx v4) -github.com/vgarvardt/go-pg-adapter/pgx4adapter.NewPool()
Copyright (c) 2020 Vladimir Garvardt