-
Notifications
You must be signed in to change notification settings - Fork 9
/
column.go
81 lines (65 loc) · 1.28 KB
/
column.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
/*
* Copyright 2018. bigpigeon. All rights reserved.
* Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.
*/
package toyorm
import (
"fmt"
"reflect"
)
type Column interface {
Column() string // sql column declaration
}
type BrickColumn struct {
alias string
column string
}
func (c BrickColumn) Column() string {
if c.alias != "" {
return fmt.Sprintf("%s.%s", c.alias, c.column)
}
return string(c.column)
}
type BrickColumnList []*BrickColumn
func (l BrickColumnList) ToColumnList() []Column {
columns := make([]Column, len(l))
for i := range l {
columns[i] = *l[i]
}
return columns
}
type ColumnName interface {
Column
Name() string
}
type ScanField struct {
name string
column string
}
type ColumnValue interface {
Column
Value() reflect.Value
}
type BrickColumnValue struct {
BrickColumn
value reflect.Value
}
func (v BrickColumnValue) Value() reflect.Value {
return v.value
}
type BrickColumnValueList []*BrickColumnValue
func (l BrickColumnValueList) ToValueList() []ColumnValue {
values := make([]ColumnValue, len(l))
for i := range l {
values[i] = l[i]
}
return values
}
type modelFieldValue struct {
Field
value reflect.Value
}
func (s *modelFieldValue) Value() reflect.Value {
return s.value
}