Documentation ¶
Index ¶
- Constants
- Variables
- func ExecTrans(ctx context.Context, builder standard.IBuilder, trans ...Task) error
- func GetConnect(typeName typeName) standard.Connecter
- func SetLogger(log Logger)
- type CommonReq
- type Connecter
- type Dao
- func (d *Dao) Add(ctx context.Context, value Tabler) error
- func (d *Dao) Delete(ctx context.Context, param IQuery) error
- func (d *Dao) Filter(build standard.IBuilder, condition *CommonReq) standard.IBuilder
- func (d *Dao) Find(ctx context.Context, param IQuery, result Tabler) error
- func (d *Dao) Get(ctx context.Context, param IQuery, result interface{}) error
- func (d *Dao) GetCommonReq() *CommonReq
- func (d *Dao) Update(ctx context.Context, param IQuery, update map[string]interface{}) error
- type IDao
- type IFilter
- type IQuery
- type Logger
- type Tabler
- type Task
- type TransError
Constants ¶
View Source
const ( Database typeName = "database" Gorm typeName = "gorm" )
Variables ¶
View Source
var ( // DBs map[DB_NAME]*gorm.DB DbWrapper map[string]*standard.Wrapper )
View Source
var LogFormatter = func(values ...interface{}) (messages []interface{}) { if len(values) > 1 { var ( sql string formattedValues []string level = values[0] currentTime = "[" + time.Now().Format("2006-01-02 15:04:05") + "]" source = fmt.Sprintf("(%v)", values[1]) ) messages = []interface{}{source, currentTime} if len(values) == 2 { currentTime = currentTime[1:] source = fmt.Sprintf("%v", values[1]) messages = []interface{}{currentTime, source} } if level == "sql" { messages = append(messages, fmt.Sprintf(" [%.2fms]", float64(values[2].(time.Duration).Nanoseconds()/1e4)/100.0)) for _, value := range values[4].([]interface{}) { indirectValue := reflect.Indirect(reflect.ValueOf(value)) if indirectValue.IsValid() { value = indirectValue.Interface() if t, ok := value.(time.Time); ok { if t.IsZero() { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", "0000-00-00 00:00:00")) } else { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", t.Format("2006-01-02 15:04:05"))) } } else if b, ok := value.([]byte); ok { if str := string(b); isPrintable(str) { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", str)) } else { formattedValues = append(formattedValues, "'<binary>'") } } else if r, ok := value.(driver.Valuer); ok { if value, err := r.Value(); err == nil && value != nil { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", value)) } else { formattedValues = append(formattedValues, "NULL") } } else { switch value.(type) { case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, bool: formattedValues = append(formattedValues, fmt.Sprintf("%v", value)) default: formattedValues = append(formattedValues, fmt.Sprintf("'%v'", value)) } } } else { formattedValues = append(formattedValues, "NULL") } } if numericPlaceHolderRegexp.MatchString(values[3].(string)) { sql = values[3].(string) for index, value := range formattedValues { placeholder := fmt.Sprintf(`\$%d([^\d]|$)`, index+1) sql = regexp.MustCompile(placeholder).ReplaceAllString(sql, value+"$1") } } else { formattedValuesLength := len(formattedValues) for index, value := range sqlRegexp.Split(values[3].(string), -1) { sql += value if index < formattedValuesLength { sql += formattedValues[index] } } } messages = append(messages, sql) messages = append(messages, fmt.Sprintf("[%v]", strconv.FormatInt(values[5].(int64), 10)+" rows affected or returned ")) } else { messages = append(messages, "\033") messages = append(messages, values[2:]...) messages = append(messages, "\033") } } return }
Functions ¶
Types ¶
type Dao ¶
type Dao struct { *CommonReq // contains filtered or unexported fields }
func (*Dao) GetCommonReq ¶
type IDao ¶
type IDao interface { // Tabler // Connecter IQuery // IFilter // 添加 Add(ctx context.Context, value Tabler) error // 更新 Update(ctx context.Context, param IQuery, update map[string]interface{}) error // 删除 Delete(ctx context.Context, param IQuery) error // 查询单条 Find(ctx context.Context, param IQuery, result Tabler) error // 查询多条 Get(ctx context.Context, param IQuery, result interface{}) error // 查询 Where(query interface{}, args ...interface{}) standard.IBuilder // get builder GetBuilder() standard.IBuilder // set builder SetBuilder(build standard.IBuilder) IDao }
数据dao标准
type IFilter ¶
type IFilter interface { BuildFilterQuery(filter IQuery) standard.IBuilder Filter(build standard.IBuilder, condition *CommonReq) standard.IBuilder }
数据库过滤标准
type TransError ¶
func (TransError) Error ¶
func (t TransError) Error() string
Click to show internal directories.
Click to hide internal directories.