db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	Debug        bool
	URL          string
	PoolSize     int
	IdleTimeout  int
	ConnLifetime time.Duration
}

Conf represents a database connection configuration

type Config

type Config struct {
	Master *Conf
	Slaves []*Conf
}

Config represents a configuration for this package

type SQL

type SQL interface {
	Close() error // Will close all open database connection.
	Writer() SQLExecutor
	Reader() SQLExecutor
	NewTransaction(ctx context.Context) (Transaction, error)
}

SQL can be use writer or read replica only.

func NewConnection

func NewConnection(config *Config) (sql SQL, err error)

NewConnection will create new connection for selected package.

type SQLExecutor

type SQLExecutor interface {
	Query(ctx context.Context, destination interface{}, query string, args ...interface{}) error
	Exec(ctx context.Context, query string, args ...interface{}) error
}

SQLExecutor should implements query and exec. You must select whether it use master or slave database.

type Transaction

type Transaction interface {
	Query(ctx context.Context, destination interface{}, query string, args ...interface{}) error
	Exec(ctx context.Context, query string, args ...interface{}) error
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

Transaction must always using writer/master database.

Jump to

Keyboard shortcuts

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