db

package
v0.0.0-...-a7a9960 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2015 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Placeholders

func Placeholders(tableFields []string) string

func Revision

func Revision(object interface{}) uint64

func Start

func Start(host string, port int, user, password, name string) error

Types

type Database

type Database interface {
	Begin() (Transaction, error)
	Close() error
	Driver() driver.Driver
	Exec(query string, args ...interface{}) (sql.Result, error)
	Ping() error
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
}

We are using an interface to allow overwriting DB with a custom type. Useful for the integration tests where we don't want to open many transactions

var (
	DB Database

	Driver = "postgres"
)

type Row

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

type SQLer

type SQLer interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Could be a connection or a transaction

type Transaction

type Transaction interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Rollback() error
	Commit() error
}

We are using this transaction to avoid commiting twice when reusing a transaction for the integration tests

Jump to

Keyboard shortcuts

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