github.com/sereiner/library@v0.0.0-20200518095232-1fa3e640cc5f/db/db.result.go (about) 1 package db 2 3 import ( 4 "time" 5 6 "github.com/sereiner/library/types" 7 ) 8 9 type IQueryRow interface { 10 GetString(name string) string 11 GetInt(name string, def ...int) int 12 GetInt64(name string, def ...int64) int64 13 GetFloat32(name string, def ...float32) float32 14 GetFloat64(name string, def ...float64) float64 15 Has(name string) bool 16 GetMustString(name string) (string, bool) 17 GetMustInt(name string) (int, bool) 18 GetMustFloat32(name string) (float32, bool) 19 GetMustFloat64(name string) (float64, bool) 20 GetDatetime(name string, format ...string) (time.Time, error) 21 ToStruct(o interface{}) error 22 } 23 24 //QueryRow 查询的数据行 25 type QueryRow = types.XMap 26 27 //QueryRows 多行数据 28 type QueryRows []QueryRow 29 30 //ToStruct 将当前对象转换为指定的struct 31 func (q QueryRows) ToStruct(o interface{}) error { 32 return types.Map2Struct(q, o) 33 } 34 35 //IsEmpty 当前数据集是否为空 36 func (q QueryRows) IsEmpty() bool { 37 return q == nil || len(q) == 0 38 } 39 40 //Len 获取当前数据集的长度 41 func (q QueryRows) Len() int { 42 return len(q) 43 } 44 45 //Get 获取指定索引的数据 46 func (q QueryRows) Get(i int) QueryRow { 47 if q == nil || i >= len(q) || i < 0 { 48 return QueryRow{} 49 } 50 return q[i] 51 }