-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
52 lines (40 loc) · 761 Bytes
/
db.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
45
46
47
48
49
50
51
52
package conv
import (
"database/sql"
"time"
)
const MYSQL_TIME_FORMAT = "2006-01-02 15:04:05"
func ConvertFloat(input sql.NullFloat64) float64 {
var floatVal float64 = 0
if input.Valid {
floatVal = input.Float64
}
return floatVal
}
func ConvertInt(input sql.NullInt64) int64 {
var intVal int64 = 0
if input.Valid {
intVal = input.Int64
}
return intVal
}
func FormatTimePointer(input *time.Time) interface{} {
if input == nil {
return nil
}
return input.Format(MYSQL_TIME_FORMAT)
}
func ConvertBool(input sql.NullBool) (output *bool) {
output = nil
if input.Valid {
output = &input.Bool
}
return
}
func ConvertString(input sql.NullString) (output string) {
output = ""
if input.Valid {
output = input.String
}
return
}