sqler

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package sqler wraps database/sql in interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Queryer
	Close() error
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	Ping(ctx context.Context) error
}

func WrapConn

func WrapConn(c SQLConn) Conn

type DB

type DB interface {
	Conn
	SetConnMaxLifetime(d time.Duration)
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
	Stats() sql.DBStats
	Unwrap() *sql.DB
}

func Open

func Open(driverName, dataSourceName string) (DB, error)

Open is a convenience function for calling sql.Open and wrapping the result with WrapDB.

func WrapDB

func WrapDB(db *sql.DB) DB

type Queryer

type Queryer interface {
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Prepare(ctx context.Context, query string) (Stmt, error)
	Query(ctx context.Context, query string, args ...interface{}) (Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) Row
}

func WrapQueryer

func WrapQueryer(q SQLQueryer) Queryer

type Row

type Row interface {
	Scan(dest ...interface{}) error
}

type Rows

type Rows interface {
	Close() error
	ColumnTypes() ([]*sql.ColumnType, error)
	Columns() ([]string, error)
	Err() error
	Next() bool
	NextResultSet() bool
	Scan(dest ...interface{}) error
}

type SQLConn

type SQLConn interface {
	SQLQueryer
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	Close() error
	PingContext(ctx context.Context) error
}

SQLConn is the common interface of *sql.DB and *sql.Conn.

type SQLQueryer

type SQLQueryer interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

SQLQueryer is the common interface of *sql.DB, *sql.Conn and *sql.Tx.

type Stmt

type Stmt interface {
	Close() error
	Exec(ctx context.Context, args ...interface{}) (sql.Result, error)
	Query(ctx context.Context, args ...interface{}) (Rows, error)
	QueryRow(ctx context.Context, args ...interface{}) Row
	Unwrap() *sql.Stmt
}

func WrapStmt

func WrapStmt(stmt *sql.Stmt) Stmt

type Tx

type Tx interface {
	Queryer
	Commit() error
	Rollback() error
	Stmt(ctx context.Context, stmt Stmt) Stmt
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL