-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.go
More file actions
46 lines (42 loc) · 797 Bytes
/
type.go
File metadata and controls
46 lines (42 loc) · 797 Bytes
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
45
46
package qsql
import (
"fmt"
"strconv"
"time"
)
// 通用的字符串查询
type DBData string
func (d *DBData) Scan(i interface{}) error {
if i == nil {
*d = ""
return nil
}
switch i.(type) {
case int64:
*d = DBData(strconv.FormatInt(i.(int64), 10))
case float64:
*d = DBData(strconv.FormatFloat(i.(float64), 'f', -1, 64))
case []byte:
*d = DBData(string(i.([]byte)))
case string:
*d = DBData(i.(string))
case bool:
*d = DBData(fmt.Sprintf("%t", i))
case time.Time:
*d = DBData(i.(time.Time).Format(time.RFC3339))
default:
*d = DBData(fmt.Sprint(i))
}
return nil
}
func (d *DBData) String() string {
return string(*d)
}
func MakeDBData(l int) []interface{} {
r := make([]interface{}, l)
for i := 0; i < l; i++ {
d := DBData("")
r[i] = &d
}
return r
}