dbx

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2018 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoChanges = stdErrors.New("nothing to migrate.")

ErrNoChanges means that the migration process didn't change execute any file

Functions

This section is empty.

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database represents a connection to a SQL database

func New

func New() *Database

New creates a new Database instance without logging

func NewWithLogger

func NewWithLogger(logger log.Logger) *Database

NewWithLogger creates a new Database instance with logging or panic

func (*Database) Begin

func (db *Database) Begin() (*Trx, error)

Begin returns a new SQL transaction

func (*Database) Close

func (db *Database) Close() error

Close connection to database

func (*Database) Connection added in v0.16.0

func (db *Database) Connection() *sql.DB

Connection returns current database connection

func (*Database) Migrate

func (db *Database) Migrate(path string) error

Migrate the database to latest version

func (*Database) Seed

func (db *Database) Seed()

Seed clean and insert new seed data for testing

func (*Database) SetLogger added in v0.14.0

func (db *Database) SetLogger(logger log.Logger)

SetLogger replaces current database Logger

type FieldInfo added in v0.9.0

type FieldInfo struct {
	FieldName  []string
	ColumnName string
}

FieldInfo is a simple struct to map Column -> Field

type NullInt

type NullInt struct {
	sql.NullInt64
}

NullInt representa a nullable integer

func (NullInt) MarshalJSON

func (r NullInt) MarshalJSON() ([]byte, error)

MarshalJSON interface redefinition

type NullString

type NullString struct {
	sql.NullString
}

NullString representa a nullable string

func (NullString) MarshalJSON

func (r NullString) MarshalJSON() ([]byte, error)

MarshalJSON interface redefinition

type NullTime

type NullTime struct {
	pq.NullTime
}

NullTime representa a nullable time.Time

func (NullTime) MarshalJSON

func (r NullTime) MarshalJSON() ([]byte, error)

MarshalJSON interface redefinition

type RowMapper added in v0.9.0

type RowMapper struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RowMapper is responsible for mapping a sql.Rows into a Struct (model)

func NewRowMapper added in v0.9.0

func NewRowMapper() *RowMapper

NewRowMapper creates a new instance of RowMapper

func (*RowMapper) Map added in v0.9.0

func (m *RowMapper) Map(dest interface{}, columns []string, scanner func(dest ...interface{}) error) error

Map values from scanner (usually sql.Rows.Scan) into dest based on columns

type Trx

type Trx struct {
	// contains filtered or unexported fields
}

Trx represents a Database transaction

func (*Trx) Commit

func (trx *Trx) Commit() error

Commit current transaction

func (*Trx) Count

func (trx *Trx) Count(command string, args ...interface{}) (int, error)

Count returns number of rows

func (*Trx) Execute

func (trx *Trx) Execute(command string, args ...interface{}) (int64, error)

Execute given SQL command

func (*Trx) Exists

func (trx *Trx) Exists(command string, args ...interface{}) (bool, error)

Exists returns true if at least one record is found

func (*Trx) Get

func (trx *Trx) Get(data interface{}, command string, args ...interface{}) error

Get first row and bind to given data

func (*Trx) NoLogs added in v0.14.0

func (trx *Trx) NoLogs()

NoLogs disable logs for this transaction

func (*Trx) QueryIntArray

func (trx *Trx) QueryIntArray(command string, args ...interface{}) ([]int, error)

QueryIntArray executes given SQL command and return first column as int

func (*Trx) ResumeLogs added in v0.17.0

func (trx *Trx) ResumeLogs()

ResumeLogs resume logs for this transaction

func (*Trx) Rollback

func (trx *Trx) Rollback() error

Rollback current transaction

func (*Trx) Scalar added in v0.4.0

func (trx *Trx) Scalar(data interface{}, command string, args ...interface{}) error

Scalar returns first row and first column

func (*Trx) Select

func (trx *Trx) Select(data interface{}, command string, args ...interface{}) error

Select all matched rows bind to given data

func (*Trx) SetLogger added in v0.14.0

func (trx *Trx) SetLogger(logger log.Logger)

SetLogger replaces current transaction Logger

type TypeMapper added in v0.9.0

type TypeMapper struct {
	Type   reflect.Type
	Fields map[string]FieldInfo
}

TypeMapper holds information about how to map SQL ResultSet to a Struct

func NewTypeMapper added in v0.9.0

func NewTypeMapper(t reflect.Type) TypeMapper

NewTypeMapper creates a new instance of TypeMapper for given reflect.Type

Jump to

Keyboard shortcuts

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