dbr

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dbr provides the dbr functions for handling with databases. This package is wrapping package of "https://github.com/gocraft/dbr/v2".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder = dbr.Builder

Builder is a type alias of dbr.Builder.

type Connection

type Connection interface {
	NewSession(event EventReceiver) Session
	SetConnMaxLifetime(d time.Duration)
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
}

Connection represents the interface to handle connection of database.

type DBR

type DBR interface {
	Open(driver, dsn string, log EventReceiver) (Connection, error)
	Eq(col string, val interface{}) Builder
}

DBR repreesnts the interface to create connection to MySQL.

func New

func New() DBR

New returns the new db struct.

type DeleteStmt

type DeleteStmt interface {
	ExecContext(ctx context.Context) (sql.Result, error)
	Where(query interface{}, value ...interface{}) DeleteStmt
}

DeleteStmt represents the interface to execute delete data.

type EventReceiver

type EventReceiver = dbr.EventReceiver

EventReceiver is a type alias of dbr.EventReceiver.

type InsertStmt

type InsertStmt interface {
	Columns(column ...string) InsertStmt
	ExecContext(ctx context.Context) (sql.Result, error)
	Record(structValue interface{}) InsertStmt
}

InsertStmt represents the interface to insert data to database.

type MockConn

type MockConn struct {
	NewSessionFunc         func(event EventReceiver) Session
	SetConnMaxLifetimeFunc func(d time.Duration)
	SetMaxIdleConnsFunc    func(n int)
	SetMaxOpenConnsFunc    func(n int)
}

func (*MockConn) NewSession

func (c *MockConn) NewSession(event EventReceiver) Session

func (*MockConn) SetConnMaxLifetime

func (c *MockConn) SetConnMaxLifetime(d time.Duration)

func (*MockConn) SetMaxIdleConns

func (c *MockConn) SetMaxIdleConns(n int)

func (*MockConn) SetMaxOpenConns

func (c *MockConn) SetMaxOpenConns(n int)

type MockDBR

type MockDBR struct {
	OpenFunc func(driver, dsn string, log EventReceiver) (Connection, error)
	EqFunc   func(col string, val interface{}) Builder
}

func (*MockDBR) Eq

func (d *MockDBR) Eq(col string, val interface{}) Builder

func (*MockDBR) Open

func (d *MockDBR) Open(driver, dsn string, log EventReceiver) (Connection, error)

type MockDelete

type MockDelete struct {
	ExecContextFunc func(ctx context.Context) (sql.Result, error)
	WhereFunc       func(query interface{}, value ...interface{}) DeleteStmt
}

func (*MockDelete) ExecContext

func (s *MockDelete) ExecContext(ctx context.Context) (sql.Result, error)

func (*MockDelete) Where

func (s *MockDelete) Where(query interface{}, value ...interface{}) DeleteStmt

type MockInsert

type MockInsert struct {
	ColumnsFunc     func(column ...string) InsertStmt
	ExecContextFunc func(ctx context.Context) (sql.Result, error)
	RecordFunc      func(structValue interface{}) InsertStmt
}

func (*MockInsert) Columns

func (s *MockInsert) Columns(column ...string) InsertStmt

func (*MockInsert) ExecContext

func (s *MockInsert) ExecContext(ctx context.Context) (sql.Result, error)

func (*MockInsert) Record

func (s *MockInsert) Record(structValue interface{}) InsertStmt

type MockSelect

type MockSelect struct {
	FromFunc        func(table interface{}) SelectStmt
	WhereFunc       func(query interface{}, value ...interface{}) SelectStmt
	LimitFunc       func(n uint64) SelectStmt
	LoadContextFunc func(ctx context.Context, value interface{}) (int, error)
}

func (*MockSelect) From

func (s *MockSelect) From(table interface{}) SelectStmt

func (*MockSelect) Limit

func (s *MockSelect) Limit(n uint64) SelectStmt

func (*MockSelect) LoadContext

func (s *MockSelect) LoadContext(ctx context.Context, value interface{}) (int, error)

func (*MockSelect) Where

func (s *MockSelect) Where(query interface{}, value ...interface{}) SelectStmt

type MockSession

type MockSession struct {
	SelectFunc      func(column ...string) SelectStmt
	BeginFunc       func() (Tx, error)
	CloseFunc       func() error
	PingContextFunc func(ctx context.Context) error
}

func (*MockSession) Begin

func (s *MockSession) Begin() (Tx, error)

func (*MockSession) Close

func (s *MockSession) Close() error

func (*MockSession) PingContext

func (s *MockSession) PingContext(ctx context.Context) error

func (*MockSession) Select

func (s *MockSession) Select(column ...string) SelectStmt

type MockTx

type MockTx struct {
	CommitFunc                  func() error
	RollbackFunc                func() error
	RollbackUnlessCommittedFunc func()
	InsertBySqlFunc             func(query string, value ...interface{}) InsertStmt
	InsertIntoFunc              func(table string) InsertStmt
	SelectFunc                  func(column ...string) SelectStmt
	DeleteFromFunc              func(table string) DeleteStmt
}

func (*MockTx) Commit

func (t *MockTx) Commit() error

func (*MockTx) DeleteFrom

func (t *MockTx) DeleteFrom(table string) DeleteStmt

func (*MockTx) InsertBySql

func (t *MockTx) InsertBySql(query string, value ...interface{}) InsertStmt

func (*MockTx) InsertInto

func (t *MockTx) InsertInto(table string) InsertStmt

func (*MockTx) Rollback

func (t *MockTx) Rollback() error

func (*MockTx) RollbackUnlessCommitted

func (t *MockTx) RollbackUnlessCommitted()

func (*MockTx) Select

func (t *MockTx) Select(column ...string) SelectStmt

type NullEventReceiver

type NullEventReceiver = dbr.NullEventReceiver

NullEventReceiver is a type alias of dbr.NullEventReceiver.

type SelectStmt

type SelectStmt interface {
	From(table interface{}) SelectStmt
	Where(query interface{}, value ...interface{}) SelectStmt
	Limit(n uint64) SelectStmt
	LoadContext(ctx context.Context, value interface{}) (int, error)
}

SelectStmt represents the interface to get data from database.

type Session

type Session interface {
	Select(column ...string) SelectStmt
	Begin() (Tx, error)
	Close() error
	PingContext(ctx context.Context) error
}

Session represents the interface to handle session.

func NewSession

func NewSession(conn Connection, event EventReceiver) Session

NewSession creates the session with event and returns the Session interface.

type TracingEventReceiver

type TracingEventReceiver = dbr.TracingEventReceiver

TracingEventReceiver is a type alias of dbr.TracingEventReceiver.

type Tx

type Tx interface {
	Commit() error
	Rollback() error
	RollbackUnlessCommitted()
	InsertBySql(query string, value ...interface{}) InsertStmt
	InsertInto(table string) InsertStmt
	Select(column ...string) SelectStmt
	DeleteFrom(table string) DeleteStmt
}

Tx represents the interface to handle transaction.

Jump to

Keyboard shortcuts

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