-
Notifications
You must be signed in to change notification settings - Fork 0
/
jnenum.go
62 lines (52 loc) · 1.22 KB
/
jnenum.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
package jnenum
import (
"database/sql"
"database/sql/driver"
"fmt"
)
// We need a special date format to support the date '0000-00-00' as we use it in welo
const EnumJa = "J"
const EnumNein = "N"
type JNEnum bool
var _ driver.Valuer = (*JNEnum)(nil)
//goland:noinspection GoMixedReceiverTypes
func (dbd JNEnum) String() string {
if dbd {
return EnumJa
}
return EnumNein
}
// Value returns the time as string.
//
//goland:noinspection GoMixedReceiverTypes
func (dbd JNEnum) Value() (driver.Value, error) {
//log.Print("valuing")
return dbd.String(), nil
}
//goland:noinspection GoMixedReceiverTypes
func (dbd JNEnum) Ja() bool {
return bool(dbd)
}
var _ sql.Scanner = (*JNEnum)(nil)
// Scan scans the time parsing it if necessary using timeFormat.
//
//goland:noinspection GoMixedReceiverTypes
func (dbd *JNEnum) Scan(src interface{}) (err error) {
//log.Print("scanning")
*dbd = false
switch src := src.(type) {
case string:
//log.Printf("scanning: string %q", src)
*dbd = src == EnumJa
return nil
case []byte:
//log.Printf("scanning: []byte %q", src)
*dbd = string(src) == EnumJa
return nil
case nil:
//log.Print("scanning: nil")
return nil
default:
return fmt.Errorf("unsupported data type: %T", src)
}
}