dbr

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// And creates AND from a list of conditions.
	And = dbr.And
	// Or creates OR from a list of conditions.
	Or = dbr.Or
	// Eq is `=`.
	// When value is nil, it will be translated to `IS NULL`.
	// When value is a slice, it will be translated to `IN`.
	// Otherwise it will be translated to `=`.
	Eq = dbr.Eq
	// Neq is `!=`.
	// When value is nil, it will be translated to `IS NOT NULL`.
	// When value is a slice, it will be translated to `NOT IN`.
	// Otherwise it will be translated to `!=`.
	Neq = dbr.Neq
	// Gt is `>`.
	Gt = dbr.Gt
	// Gte is '>='.
	Gte = dbr.Gte
	// Lt is '<'.
	Lt = dbr.Lt
	// Lte is `<=`.
	Lte = dbr.Lte
	// Like is `LIKE`, with an optional `ESCAPE` clause
	Like = dbr.Like
	// NotLike is `NOT LIKE`, with an optional `ESCAPE` clause
	NotLike = dbr.NotLike
	// Expr allows raw expression to be used when current SQL syntax is
	// not supported by gocraft/dbr.
	Expr = dbr.Expr
	// Union builds
	Union = dbr.Union
	// UnionAll builds
	UnionAll = dbr.UnionAll
)

export dbr expression function for convenience

Functions

func Middleware

func Middleware(db *DB) b.Middleware

Middleware inject dbr session to context

Types

type DB

type DB struct {
	*dbr.Session
}

DB session instance, base on dbr.Session

func Dbr

func Dbr(ctx context.Context) *DB

Dbr get dbr session from context

func New

func New(optionalDSN ...string) *DB

New dbr.Session if optionalDSN is omited, config from ENV will be used Supported ENV: MYSQL_DSN - dsn for connection MYSQL_MAX_IDLE - max idle connections for pool MYSQL_MAX_OPEN - max open connections for pool

func (*DB) Begin added in v1.0.4

func (db *DB) Begin() (*Tx, error)

Begin creates a transaction for the given session.

type Logger

type Logger struct {
	*bl.Logger
	*dbr.EventReceiver
}

Logger for dbr

func (*Logger) Event

func (l *Logger) Event(eventName string)

Event func

func (*Logger) EventErr

func (l *Logger) EventErr(eventName string, err error) error

EventErr func

func (*Logger) EventErrKv

func (l *Logger) EventErrKv(eventName string, err error, kvs map[string]string) error

EventErrKv func

func (*Logger) EventKv

func (l *Logger) EventKv(eventName string, kvs map[string]string)

EventKv func

func (*Logger) Timing

func (l *Logger) Timing(eventName string, nanoseconds int64)

Timing func

func (*Logger) TimingKv

func (l *Logger) TimingKv(eventName string, nanoseconds int64, kvs map[string]string)

TimingKv func

type Tx added in v1.0.4

type Tx struct {
	*dbr.Tx
}

Tx transaction instance, base on dbr.Tx

Jump to

Keyboard shortcuts

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