Skip to content

Commit

Permalink
Merge pull request #2 from blahspam/master
Browse files Browse the repository at this point in the history
Remove scany and related functions
  • Loading branch information
blahspam authored Oct 8, 2020
2 parents 18b73e8 + 7d691da commit f0fefd0
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions hermes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package hermes

import (
"context"
"database/sql"
"errors"
"sync"

"github.com/georgysavva/scany/pgxscan"
"github.com/jackc/pgconn"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4"
Expand All @@ -31,6 +32,9 @@ type Conn interface {
// transaction.
Commit(ctx context.Context) error

// Rollback the transaction. Does nothing if Conn is a *pgxpool.Pool.
Rollback(ctx context.Context) error

// Close rolls back the transaction if this is a real transaction or rolls back to the
// savepoint if this is a pseudo nested transaction. For a *pgxpool.Pool, this call is
// ignored.
Expand All @@ -49,8 +53,6 @@ type Conn interface {
// Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)
Get(ctx context.Context, dest interface{}, sql string, arguments ...interface{}) error
Select(ctx context.Context, dest interface{}, sql string, arguments ...interface{}) error
Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
}
Expand Down Expand Up @@ -114,19 +116,14 @@ func (db *DB) Commit(context.Context) error {
return nil
}

// Close does nothing.
func (db *DB) Close(context.Context) error {
// Rollback does nothing
func (db *DB) Rollback(_ context.Context) error {
return nil
}

// Get a single record from the database
func (db *DB) Get(ctx context.Context, dest interface{}, sql string, args ...interface{}) error {
return pgxscan.Get(ctx, db.Pool, dest, sql, args...)
}

// Select a collection of records from the database
func (db *DB) Select(ctx context.Context, dest interface{}, sql string, args ...interface{}) error {
return pgxscan.Select(ctx, db.Pool, dest, sql, args...)
// Close does nothing.
func (db *DB) Close(context.Context) error {
return nil
}

// Tx wraps the pgx.Tx interface and provides the missing hermes function wrappers.
Expand Down Expand Up @@ -156,12 +153,12 @@ func (tx *Tx) Close(ctx context.Context) error {
return tx.Tx.Rollback(ctx)
}

// Get a single record from the database
func (tx *Tx) Get(ctx context.Context, dest interface{}, sql string, args ...interface{}) error {
return pgxscan.Get(ctx, tx.Tx, dest, sql, args...)
// NoRows returns true if the supplied error is one of the NoRows indicators
func NoRows(err error) bool {
return errors.Is(err, sql.ErrNoRows) || errors.Is(err, pgx.ErrNoRows)
}

// Select a collection of records from the database
func (tx *Tx) Select(ctx context.Context, dest interface{}, sql string, args ...interface{}) error {
return pgxscan.Select(ctx, tx.Tx, dest, sql, args...)
// RowScanner is a shared interface between pgx.Rows and pgx.Row
type RowScanner interface {
Scan(dest ...interface{}) error
}

0 comments on commit f0fefd0

Please sign in to comment.