123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package db
- import "git.chuangxin1.com/cx/myth"
- // Reply db exec return insert/update/delete
- type Reply struct {
- OK bool
- Err error
- LastErr error
- ErrCode int
- LastID int64
- RowsAffected int64
- }
- // Ok check reply true/false
- func (r Reply) Ok() bool {
- return r.OK
- }
- // ReplyOk exec ok
- func ReplyOk(rowsAffected, lastID int64) Reply {
- var reply Reply
- reply.OK = true
- reply.ErrCode = 0
- reply.LastID = lastID
- reply.RowsAffected = rowsAffected
- return reply
- }
- // ReplyFaild exec faild
- func ReplyFaild(errCode int, err, errText error) (reply Reply) {
- reply.OK = false
- reply.ErrCode = errCode
- reply.LastID = -1
- reply.RowsAffected = -1
- reply.Err = err
- reply.LastErr = errText
- return
- }
- // ReplyToReplyData db reply to response
- func ReplyToReplyData(reply Reply) *myth.ReplyData {
- status := myth.ErrOk
- if !reply.OK {
- switch reply.ErrCode {
- case ErrException:
- status = myth.ErrException
- case ErrExists:
- status = myth.ErrDataExists
- case ErrNotFound:
- status = myth.ErrDataNotFound
- case ErrDataNotFound:
- status = myth.ErrDataNotFound
- case ErrAuthorized:
- status = myth.ErrUnAuthorized
- case ErrNotConnect:
- status = myth.ErrNotFound
- case ErrExpired:
- status = myth.ErrNotAllowed
- case ErrInsufficientBalance:
- status = myth.ErrNotAllowed
- case ErrCreditLimit:
- status = myth.ErrNotAllowed
- default:
- status = myth.ErrException
- }
- return myth.ReplyErr(status, reply.LastErr.Error())
- }
- return myth.ReplyOk()
- }
|