-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursor.go
44 lines (36 loc) · 1.04 KB
/
cursor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gora
import (
"git.eaciitapp.com/sebar/dbflex/drivers/rdbms"
"github.com/eaciit/toolkit"
)
// Cursor represent cursor object. Inherits Cursor object of rdbms drivers and implementation of dbflex.ICursor
type Cursor struct {
rdbms.Cursor
fieldNames []string
fieldTypes []string
}
func (c *Cursor) Serialize(dest interface{}) error {
var err error
mobj := toolkit.M{}
toolkit.Serde(dest, &mobj, "")
values := c.Values()
for idx, fieldName := range c.fieldNames {
//fmt.Println(idx, ":", fieldName, ":", c.fieldTypes[idx], "=", values[idx])
switch c.fieldTypes[idx] {
case "int":
mobj.Set(fieldName, toolkit.ToInt(values[idx], toolkit.RoundingAuto))
case "float64":
f64 := toolkit.ToFloat64(values[idx], 4, toolkit.RoundingAuto)
mobj.Set(fieldName, f64)
case "time.Time":
mobj.Set(fieldName, values[idx])
default:
mobj.Set(fieldName, values[idx])
}
}
err = toolkit.Serde(mobj, dest, "")
if err != nil {
return toolkit.Error(err.Error() + toolkit.Sprintf(" object: %s", toolkit.JsonString(mobj)))
}
return nil
}