sqldb

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2019 License: MIT Imports: 1 Imported by: 10

README

go-sqldb

Actions Status Go Report Card GoDoc

Implementations

Documentation

Overview

Package sqldb contains interfaces and strutures to deal with SQL database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	Queryable

	// SQL returns the sql.DB object
	SQL() *sql.DB

	// DSN returns the DNS used to connect to the database
	DSN() string

	// Close closes the database connection
	Close() error

	// Beginx starts a new transaction
	Beginx() (Tx, error)
}

Connection is an interface representing a database connection

type Queryable

type Queryable interface {
	// Get is used to retrieve a single row
	// An error (sql.ErrNoRows) is returned if the result set is empty.
	Get(dest interface{}, query string, args ...interface{}) error

	// NamedGet is a Get that accepts named params (ex where id=:user_id)
	NamedGet(dest interface{}, query string, args interface{}) error

	// Select is used to retrieve multiple rows
	Select(dest interface{}, query string, args ...interface{}) error

	// NamedSelect is a Select() that accepts named params (ex where id=:user_id)
	NamedSelect(dest interface{}, query string, args interface{}) error

	// Exec executes a SQL query and returns the number of rows affected
	Exec(query string, arg ...interface{}) (rowsAffected int64, err error)

	// NamedExec is an Exec that accepts named params (ex where id=:user_id)
	NamedExec(query string, arg interface{}) (rowAffected int64, err error)
}

Queryable represents

type Tx

type Tx interface {
	Queryable

	// Commit commits the transaction
	Commit() error

	// Rollback rollbacks the transaction
	Rollback() error
}

Tx is an interface representing a transaction

Jump to

Keyboard shortcuts

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