forked from moisespsena-go/aorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.go
59 lines (46 loc) · 1.05 KB
/
email.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
package types
import (
"database/sql/driver"
"fmt"
"reflect"
"github.com/go-aorm/aorm"
)
const EmailSize = uint16(255)
type (
Email string
EmailAssigner struct {
}
)
func init() {
aorm.Register(EmailAssigner{})
}
func (this Email) PrimaryGoValue() interface{} {
return string(this)
}
func (this Email) IsZero() bool {
return this == ""
}
func (EmailAssigner) Valuer(_ aorm.Dialector, value interface{}) driver.Valuer {
return aorm.ValuerFunc(func() (driver.Value, error) {
return string(value.(Email)), nil
})
}
func (EmailAssigner) Scaner(_ *aorm.Scope, dest *aorm.Field) aorm.Scanner {
return aorm.ScannerFunc(func(src interface{}) (err error) {
if src == nil {
dest.Field.SetString("")
return
}
dest.Field.SetString(src.(string))
return
})
}
func (EmailAssigner) SQLType(*aorm.StructField, aorm.Dialector) (string, string) {
return fmt.Sprintf("VARCHAR(%d)", EmailSize), ""
}
func (EmailAssigner) SQLSize(_ aorm.Dialector) int {
return int(EmailSize)
}
func (EmailAssigner) Type() reflect.Type {
return reflect.TypeOf(Email(""))
}