db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBErrCodeOK         = 0 // DBErrCodeOK ok
	DBErrCodeException  = 1 // DBErrCodeException exception
	DBErrCodeExists     = 2 // DBErrCodeExists exists
	DBErrCodeNotFound   = 3 // DBErrCodeNotFound not found
	DBErrCodeAuthorized = 4 // DBErrCodeAuthorized authorized
	DBErrCodeNotConnect = 5 // DBErrCodeNotConnect connect error
)

DB error code

Variables

This section is empty.

Functions

func ErrSQLNoRows

func ErrSQLNoRows(err error) bool

ErrSQLNoRows check norows error

func ReleaseConfigDB

func ReleaseConfigDB(dbx *DB)

ReleaseConfigDB free db connect

func ReleaseDB

func ReleaseDB()

ReleaseDB free db connect

func ReplyToReplyData

func ReplyToReplyData(reply Reply) *tyr.ReplyData

ReplyToReplyData db reply to response

func SetDbConfig

func SetDbConfig(cfg Config)

SetDbConfig set

Types

type Config

type Config struct {
	Driver       string
	DNS          string
	MaxOpenConns int
	MaxIdle      int
	MaxLifetime  time.Duration
}

Config config

type DB

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

DB define

func NewConfigDB

func NewConfigDB(config Config) (dbx *DB, err error)

NewConfigDB new DB dynamic object

func NewDB

func NewDB() *DB

NewDB new DB object

func (*DB) BeginTrans

func (d *DB) BeginTrans() (err error)

BeginTrans begin trans

func (*DB) Close

func (d *DB) Close()

Close close database connect

func (*DB) Commit

func (d *DB) Commit() error

Commit commit

func (*DB) Connect

func (d *DB) Connect() (err error)

Connect connect to database

func (*DB) Insert

func (d *DB) Insert(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)

Insert insert into

func (*DB) InsertReply

func (d *DB) InsertReply(query string, args interface{}) (reply Reply)

InsertReply insert and return DbReply

func (*DB) Limit

func (d *DB) Limit(page, pagesize int) string

Limit MySQL limit

func (*DB) Rollback

func (d *DB) Rollback() error

Rollback rollback

func (*DB) Row

func (d *DB) Row(dest interface{}, query string, args interface{}) error

Row get row

func (*DB) Rows

func (d *DB) Rows(dest interface{}, query string, args interface{}) error

Rows get rows

func (*DB) TransExec

func (d *DB) TransExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)

TransExec trans execute

func (*DB) TransUpdate

func (d *DB) TransUpdate(query string, args interface{}) (reply Reply)

TransUpdate trans update

func (*DB) Update

func (d *DB) Update(query string, args interface{}) (RowsAffected int64, err error)

Update update/delete

func (*DB) UpdateReply

func (d *DB) UpdateReply(query string, args interface{}) (reply Reply)

UpdateReply update/delete and return DbReply

type Reply

type Reply struct {
	OK           bool
	Err          error
	LastErr      error
	ErrCode      int
	LastID       int64
	RowsAffected int64
}

Reply db exec return insert/update/delete

func ReplyFaild

func ReplyFaild(errCode int, err, errText error) (reply Reply)

ReplyFaild exec faild

func ReplyOk

func ReplyOk(rowsAffected, lastID int64) Reply

ReplyOk exec ok

Jump to

Keyboard shortcuts

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