-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbool.go
53 lines (42 loc) · 829 Bytes
/
bool.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
package jsons
import (
"database/sql/driver"
"encoding/json"
"errors"
"gorm.io/gorm/schema"
"gorm.io/gorm"
)
func (b Bool) Value() (driver.Value, error) {
return json.Marshal(b)
}
func (b *Bool) Scan(v interface{}) error {
if v == nil {
*b = false
return nil
}
switch val := v.(type) {
case []byte:
return json.Unmarshal(val, b)
case string:
return json.Unmarshal([]byte(val), b)
}
return errors.New("invalid scan bool source")
}
func (Bool) GormDBDataType(*gorm.DB, *schema.Field) string {
return "json"
}
func (b Bool) Raw() Raw {
return b.JSONValue().Raw()
}
func (b Bool) Bool() bool {
return bool(b)
}
func (b Bool) JSON() []byte {
return b.JSONValue().JSON()
}
func (b Bool) JSONValue() Value {
return value(b)
}
func (b Bool) JSONString() string {
return b.JSONValue().JSONString()
}