db

package
v0.0.0-...-976baef Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const TypeMySQL = "mysql"

Variables

View Source
var ErrNotExists = errors.New("cannot update a non-existing entity")

ErrNotExists is returned when a query is executed on a non-existing entity.

Functions

func RollbackError

func RollbackError(tx *Tx, originalErr error) error

RollbackError rolls back a transaction and returns the provided error with a stack trace.

Types

type ColumnMap

type ColumnMap map[string]interface{}

ColumnMap is a map used to map column to their values.

type Connection

type Connection struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

func New

func New(driver, dataSource string, logger log.Logger) (*Connection, error)

New returns a new Connection instance.

func NewFromConnection

func NewFromConnection(conn *sqlx.DB, logger log.Logger) *Connection

NewFromConnection returns a new Connection for an existing sqlx instance.

func (*Connection) Begin

func (c *Connection) Begin() (*Tx, error)

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Connection

func (c *Connection) Connection() *sql.DB

func (*Connection) DriverName

func (c *Connection) DriverName() string

func (*Connection) Exec

func (c *Connection) Exec(query string, args ...interface{}) (Result, error)

func (*Connection) ExecContext

func (c *Connection) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)

func (*Connection) Get

func (c *Connection) Get(dest interface{}, query string, args ...interface{}) error

func (*Connection) GetContext

func (c *Connection) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*Connection) Query

func (c *Connection) Query(query string, args ...interface{}) (*Rows, error)

func (*Connection) QueryContext

func (c *Connection) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)

func (*Connection) Select

func (c *Connection) Select(dest interface{}, query string, args ...interface{}) error

func (*Connection) SelectContext

func (c *Connection) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*Connection) WithTx

func (c *Connection) WithTx(fn func(tx *Tx) error) error

WithTX runs a closure inside a transaction.

type Migrator

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

func NewMigrator

func NewMigrator(db *Connection, logger log.Logger, migrationsPath string) (*Migrator, error)

func (*Migrator) Down

func (m *Migrator) Down() error

func (*Migrator) Fresh

func (m *Migrator) Fresh() error

Fresh drops the current database structure and re-runs all migrations.

func (*Migrator) Up

func (m *Migrator) Up() error

func (*Migrator) Version

func (m *Migrator) Version() (version uint, dirty bool, err error)

type RawTime

type RawTime []byte

RawTime handles MySQL's TIME column type. @see https://github.com/go-sql-driver/mysql#timetime-support

func (RawTime) Time

func (t RawTime) Time() (null.Time, error)

type Result

type Result struct {
	sql.Result
}

type Row

type Row struct {
	*sqlx.Row
}

type Rows

type Rows struct {
	*sqlx.Rows
}

type Tx

type Tx struct {
	*sqlx.Tx
	Log log.Logger
}

func (*Tx) Commit

func (tx *Tx) Commit() error

func (*Tx) Exec

func (tx *Tx) Exec(query string, args ...interface{}) (Result, error)

func (*Tx) ExecContext

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Jump to

Keyboard shortcuts

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