Documentation
¶
Index ¶
- Constants
- Variables
- func CloseOnError(ctx context.Context, db DB, err error)
- func ExternalBool(value bool) interface{}
- func ExternalFloat64(value float64) interface{}
- func ExternalInt(value int) interface{}
- func ExternalInt16(value int16) interface{}
- func ExternalInt32(value int32) interface{}
- func ExternalInt64(value int64) interface{}
- func ExternalInt8(value int8) interface{}
- func ExternalString(value string) interface{}
- func ExternalTime(value time.Time) interface{}
- func ExternalUint(value uint) interface{}
- func ExternalUint16(value uint16) interface{}
- func ExternalUint32(value uint32) interface{}
- func ExternalUint64(value uint64) interface{}
- func ExternalUint8(value uint8) interface{}
- func Heartbeart(ctx context.Context, db DB, interval time.Duration) error
- func Register(driver string, adapter Adapter)
- func ToContext(ctx context.Context, scope Scope) context.Context
- type Activator
- type Adapter
- type Args
- type Array
- type Arrays
- type Auditor
- type Composer
- type DB
- type DSC
- type DSN
- type DbId
- type Fetcher
- type HalfMetrics
- type IsolationLevel
- type Metrics
- type NullBool
- type NullFloat64
- type NullInt
- type NullInt16
- type NullInt32
- type NullInt64
- type NullInt8
- type NullString
- type NullTime
- type NullUint
- type NullUint16
- type NullUint32
- type NullUint64
- type NullUint8
- type Repository
- type Result
- type Row
- type Rows
- type Scanner
- type Scope
- type Stmt
- type Tracer
- type Tx
- type TxOptions
Constants ¶
const (
MaxDeadlockDuration = time.Second
)
Variables ¶
var ( ErrNoRows = data.ErrNoMatch ErrTxDone = sql.ErrTxDone ErrUnknownDriver = errors.New("unknown driver") ErrCaptureLock = errors.New("timeout of latch") ErrReleaseLock = errors.New("can not release lock") ErrReleaseInvalid = errors.New("unknown latch or invalid thread") )
var (
DefaultTime = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
)
Functions ¶
func ExternalBool ¶
func ExternalBool(value bool) interface{}
func ExternalFloat64 ¶
func ExternalFloat64(value float64) interface{}
func ExternalInt ¶
func ExternalInt(value int) interface{}
func ExternalInt16 ¶
func ExternalInt16(value int16) interface{}
func ExternalInt32 ¶
func ExternalInt32(value int32) interface{}
func ExternalInt64 ¶
func ExternalInt64(value int64) interface{}
func ExternalInt8 ¶
func ExternalInt8(value int8) interface{}
func ExternalString ¶
func ExternalString(value string) interface{}
func ExternalTime ¶
func ExternalUint ¶
func ExternalUint(value uint) interface{}
func ExternalUint16 ¶
func ExternalUint16(value uint16) interface{}
func ExternalUint32 ¶
func ExternalUint32(value uint32) interface{}
func ExternalUint64 ¶
func ExternalUint64(value uint64) interface{}
func ExternalUint8 ¶
func ExternalUint8(value uint8) interface{}
Types ¶
type Activator ¶
func OpenExclusive ¶
Open exclusive access for required database If control is not null, than for latch opens with heartbeard.
type Adapter ¶
type Adapter interface {
// Get driver name
Driver() string
//Get database name
DatabaseName(db DB) (name string, err error)
// Make connection string for open database
MakeConnectionString(dsn *DSN) string
// Check error for deadlock criteria
IsDeadlock(db DB, err error) bool
// Acquire local lock
LockLocal(ctx context.Context, tx Tx, latch string, timeout int) error
// Release local lock
UnlockLocal(ctx context.Context, tx Tx, latch string) error
// Acquire local lock
LockGlobal(ctx context.Context, tx Tx, latch string, timeout int) error
// Release local lock
UnlockGlobal(ctx context.Context, tx Tx, latch string) error
}
type Composer ¶
type Composer interface {
Add(delta int)
Done()
Abort() <-chan struct{}
}
Composer is interface for coordinate threads
type DB ¶
type DB interface {
Scope
Composer
Close(ctx context.Context) error
Driver() driver.Driver
Ping() error
Slave() DB
Master() DB
Prepare(query string) (Stmt, error)
PrepareContext(ctx context.Context, query string) (Stmt, error)
SetMaxIdleConns(n int)
SetMaxOpenConns(n int)
SetConnMaxLifetime(d time.Duration)
IsCluster() bool
GetMetrics() Metrics
Audit(auditor interface{}) error
Interface(detective func(interface{}) interface{}) (interface{}, bool)
DSC() DSC
// contains filtered or unexported methods
}
DB is a logical database with multiple underlying physical databases forming a single master multiple slaves topology. Reads and writes are automatically directed to the correct physical db.
type DSC ¶
DataSource nodes cluster (first node is master)
func (DSC) OpenForTest ¶
Exclusive open database for escape any concurrency.
type DSN ¶
type DSN struct {
Host string `json:"host"` // Host address
Port uint16 `json:"port"` // Host port
Database string `json:"database"` // Database name
Username string `json:"username"` // User name
Password string `json:"password"` // User password
Params map[string]string `json:"params"` // Other parameters
}
Single dataSource node
type HalfMetrics ¶
type IsolationLevel ¶
type IsolationLevel int
IsolationLevel is the transaction isolation level used in TxOptions.
const ( LevelDefault IsolationLevel = iota LevelReadUncommitted LevelReadCommitted LevelWriteCommitted LevelRepeatableRead LevelSnapshot LevelSerializable LevelLinearizable )
Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned.
See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
type Metrics ¶
type Metrics struct {
Query HalfMetrics `json:"query"`
Exec HalfMetrics `json:"exec"`
Transact HalfMetrics `json:"transact"`
}
Metrics of database
func (*Metrics) GetMetrics ¶
type NullBool ¶
NullBool represents a bool that may be null. NullBool implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullBool) MarshalJSON ¶
func (*NullBool) UnmarshalJSON ¶
type NullFloat64 ¶
NullFloat64 represents a float64 that may be null. NullFloat64 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (NullFloat64) External ¶
func (n NullFloat64) External() interface{}
func (NullFloat64) Internal ¶
func (n NullFloat64) Internal() driver.Value
func (*NullFloat64) MarshalJSON ¶
func (n *NullFloat64) MarshalJSON() ([]byte, error)
func (*NullFloat64) Scan ¶
func (n *NullFloat64) Scan(value interface{}) error
func (*NullFloat64) UnmarshalJSON ¶
func (n *NullFloat64) UnmarshalJSON(data []byte) error
type NullInt ¶
NullInt represents an int that may be null. NullInt implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullInt) MarshalJSON ¶
func (*NullInt) UnmarshalJSON ¶
type NullInt16 ¶
NullInt16 represents an int16 that may be null. NullInt16 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullInt16) MarshalJSON ¶
func (*NullInt16) UnmarshalJSON ¶
type NullInt32 ¶
NullInt32 represents an int32 that may be null. NullInt32 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullInt32) MarshalJSON ¶
func (*NullInt32) UnmarshalJSON ¶
type NullInt64 ¶
NullInt64 represents an int64 that may be null. NullInt64 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullInt64) MarshalJSON ¶
func (*NullInt64) UnmarshalJSON ¶
type NullInt8 ¶
NullInt8 represents an int8 that may be null. NullInt8 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullInt8) MarshalJSON ¶
func (*NullInt8) UnmarshalJSON ¶
type NullString ¶
NullString represents a string that may be null. NullString implements the Scanner interface so it can be used as a scan destination:
var s NullString
err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&s)
...
if s.Valid {
// use s.String
} else {
// NULL value
}
func (NullString) External ¶
func (n NullString) External() interface{}
func (NullString) Internal ¶
func (n NullString) Internal() driver.Value
func (*NullString) MarshalJSON ¶
func (n *NullString) MarshalJSON() ([]byte, error)
func (*NullString) Scan ¶
func (n *NullString) Scan(value interface{}) error
func (*NullString) UnmarshalJSON ¶
func (n *NullString) UnmarshalJSON(data []byte) error
type NullTime ¶
NullTime represents a time that may be null. NullTime implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullTime) MarshalJSON ¶
func (*NullTime) UnmarshalJSON ¶
type NullUint ¶
NullUInt represents an uInt that may be null. NullUInt implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullUint) MarshalJSON ¶
func (*NullUint) UnmarshalJSON ¶
type NullUint16 ¶
NullUInt16 represents an uInt16 that may be null. NullUInt16 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (NullUint16) External ¶
func (n NullUint16) External() interface{}
func (NullUint16) Internal ¶
func (n NullUint16) Internal() driver.Value
func (*NullUint16) MarshalJSON ¶
func (n *NullUint16) MarshalJSON() ([]byte, error)
func (*NullUint16) Scan ¶
func (n *NullUint16) Scan(value interface{}) error
func (*NullUint16) UnmarshalJSON ¶
func (n *NullUint16) UnmarshalJSON(data []byte) error
type NullUint32 ¶
NullUInt32 represents an uInt32 that may be null. NullUInt32 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (NullUint32) External ¶
func (n NullUint32) External() interface{}
func (NullUint32) Internal ¶
func (n NullUint32) Internal() driver.Value
func (*NullUint32) MarshalJSON ¶
func (n *NullUint32) MarshalJSON() ([]byte, error)
func (*NullUint32) Scan ¶
func (n *NullUint32) Scan(value interface{}) error
func (*NullUint32) UnmarshalJSON ¶
func (n *NullUint32) UnmarshalJSON(data []byte) error
type NullUint64 ¶
NullUInt64 represents an uInt64 that may be null. NullUInt64 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (NullUint64) External ¶
func (n NullUint64) External() interface{}
func (NullUint64) Internal ¶
func (n NullUint64) Internal() driver.Value
func (*NullUint64) MarshalJSON ¶
func (n *NullUint64) MarshalJSON() ([]byte, error)
func (*NullUint64) Scan ¶
func (n *NullUint64) Scan(value interface{}) error
func (*NullUint64) UnmarshalJSON ¶
func (n *NullUint64) UnmarshalJSON(data []byte) error
type NullUint8 ¶
NullUInt8 represents an uInt8 that may be null. NullUInt8 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
func (*NullUint8) MarshalJSON ¶
func (*NullUint8) UnmarshalJSON ¶
type Repository ¶
type Repository interface {
// Find actual scope
Scope(ctx context.Context) Scope
// Get database
Database() DB
// Execute transaction
Transaction(
ctx context.Context,
action func(ctx context.Context) error,
) error
}
func NewRepository ¶
func NewRepository( db DB, ) Repository
type Rows ¶
type Rows interface {
Err() error
Next() bool
Columns() ([]string, error)
Close() error
Scan(dest ...interface{}) error
}
Record set
type Scope ¶
type Scope interface {
Begin() (Tx, error)
BeginTx(ctx context.Context, opts *TxOptions) (Tx, error)
Exec(query string, args ...interface{}) (Result, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
Query(query string, args ...interface{}) (Rows, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
QueryRow(query string, args ...interface{}) Row
QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
DbId() DbId
Adapter() Adapter
}
Scope is abstract processor
type Stmt ¶
type Stmt interface {
Close() error
Exec(args ...interface{}) (Result, error)
ExecContext(ctx context.Context, args ...interface{}) (Result, error)
Query(args ...interface{}) (Rows, error)
QueryContext(ctx context.Context, args ...interface{}) (Rows, error)
QueryRow(args ...interface{}) Row
QueryRowContext(ctx context.Context, args ...interface{}) Row
}
Stmt is an aggregate prepared statement. It holds a prepared statement for each underlying physical db.