-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.go
84 lines (73 loc) · 1.86 KB
/
utils.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2019 The Go-CUBRID-Driver Authors. All rights reserved.
//
// Package cubrid provides a CUBRID driver for Go's database/sql package.
//
// The driver should be used via the database/sql package:
//
// import "database/sql"
// import _ "github.com/CUBRID/cubrid-go"
package cubrid
import (
"database/sql/driver"
"time"
)
// NullTime represents a time.Time that may be NULL.
// NullTime implements the Scanner interface so
//
// This NullTime implementation is not driver-specific
type NullTime struct {
Time time.Time
Valid bool // Valid is true if Time is not NULL
}
type NullByte struct {
data []byte
Valid bool // Valid is true if Time is not NULL
}
// Scan implements the Scanner interface.
// The value type must be time.Time or string
func (nt *NullTime) Scan(value interface{}) (err error) {
if value == nil {
nt.Time, nt.Valid = time.Now(), false
return nil
}
nt.Valid = true
switch v := value.(type) {
case time.Time:
nt.Time = v
default:
nt.Time = time.Now()
}
return nil
}
// NullTime Value implements the driver Valuer interface.
func (nt NullTime) Value() (driver.Value, error) {
if !nt.Valid {
return nil, nil
}
return nt.Time, nil
}
// NullByte represents a []byte that may be NULL.
// NullByte implements the Scanner interface so
//
// This NullByte implementation is not driver-specific
func (nb *NullByte) Scan(value interface{}) (err error) {
if value == nil {
nb.data, nb.Valid = nil, false
return nil
}
nb.Valid = true
switch v := value.(type) {
case []byte:
nb.data = v
default:
nb.data = nil
}
return nil
}
// NullByte Value implements the driver Valuer interface.
func (nb NullByte) Value() (driver.Value, error) {
if !nb.Valid {
return nil, nil
}
return nb.data, nil
}