Skip to content

Commit e6a7ed2

Browse files
committed
Combine column and value sql methods for direct selects
1 parent 0d3e909 commit e6a7ed2

File tree

11 files changed

+23
-60
lines changed

11 files changed

+23
-60
lines changed

attributes/a_bool.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ func (b Bool) GetKey() string {
1717
return b.Key
1818
}
1919

20-
func (b Bool) GetSelectDirectColumns() []string {
21-
return []string{b.ColumnName}
22-
}
23-
func (b Bool) GetSelectDirectVariables() []interface{} {
20+
func (b Bool) GetSelectDirect() ([]string, []interface{}) {
2421
var destination *bool
25-
return []interface{}{
22+
return []string{b.ColumnName}, []interface{}{
2623
&destination,
2724
}
2825
}

attributes/a_date.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ func (d Date) GetKey() string {
2020
return d.Key
2121
}
2222

23-
func (d Date) GetSelectDirectColumns() []string {
24-
return []string{d.ColumnName}
25-
}
26-
func (d Date) GetSelectDirectVariables() []interface{} {
23+
func (d Date) GetSelectDirect() ([]string, []interface{}) {
2724
var destination *time.Time
28-
return []interface{}{
25+
return []string{d.ColumnName}, []interface{}{
2926
&destination,
3027
}
3128
}

attributes/a_datetime.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ func (dt Datetime) GetKey() string {
1818
return dt.Key
1919
}
2020

21-
func (dt Datetime) GetSelectDirectColumns() []string {
22-
return []string{dt.ColumnName}
23-
}
24-
func (dt Datetime) GetSelectDirectVariables() []interface{} {
21+
func (dt Datetime) GetSelectDirect() ([]string, []interface{}) {
2522
var destination *time.Time
26-
return []interface{}{
23+
return []string{dt.ColumnName}, []interface{}{
2724
&destination,
2825
}
2926
}

attributes/a_decimal.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ func (d Decimal) GetKey() string {
1919
return d.Key
2020
}
2121

22-
func (d Decimal) GetSelectDirectColumns() []string {
23-
return []string{d.ColumnName}
24-
}
25-
func (d Decimal) GetSelectDirectVariables() []interface{} {
22+
func (d Decimal) GetSelectDirect() ([]string, []interface{}) {
2623
var destination *decimal.Decimal
27-
return []interface{}{
24+
return []string{d.ColumnName}, []interface{}{
2825
&destination,
2926
}
3027
}

attributes/a_integer.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ func (i Integer) GetKey() string {
1717
return i.Key
1818
}
1919

20-
func (i Integer) GetSelectDirectColumns() []string {
21-
return []string{i.ColumnName}
22-
}
23-
func (i Integer) GetSelectDirectVariables() []interface{} {
20+
func (i Integer) GetSelectDirect() ([]string, []interface{}) {
2421
var destination *int
25-
return []interface{}{
22+
return []string{i.ColumnName}, []interface{}{
2623
&destination,
2724
}
2825
}

attributes/a_text.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ func (t Text) GetKey() string {
2020
return t.Key
2121
}
2222

23-
func (t Text) GetSelectDirectColumns() []string {
24-
return []string{t.ColumnName}
25-
}
26-
func (t Text) GetSelectDirectVariables() []interface{} {
23+
func (t Text) GetSelectDirect() ([]string, []interface{}) {
2724
var destination *string
28-
return []interface{}{
25+
return []string{t.ColumnName}, []interface{}{
2926
&destination,
3027
}
3128
}

relationships/relationship.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ func pointerSetFromPage(val interface{}) PointerSet {
103103

104104
type RelationshipStub struct{}
105105

106-
func (stub RelationshipStub) GetSelectDirectColumns() []string {
107-
return []string{}
108-
}
109-
func (stub RelationshipStub) GetSelectDirectVariables() []interface{} {
110-
return []interface{}{}
111-
}
112106
func (stub RelationshipStub) GetSelectExtraColumns() []string {
113107
return []string{}
114108
}

schema/attribute.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package schema
33
type Attribute interface {
44
GetKey() string
55

6-
GetSelectDirectColumns() []string
7-
GetSelectDirectVariables() []interface{}
6+
GetSelectDirect() ([]string, []interface{})
87

98
GetOrderMap() map[string]string
109

schema/model.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,15 @@ type Model struct {
1616
Manager Manager
1717
}
1818

19-
func (m Model) FieldColumns() []string {
20-
var columns []string
21-
for _, attribute := range m.Attributes {
22-
columns = append(columns, attribute.GetSelectDirectColumns()...)
23-
}
24-
for _, relationship := range m.Relationships {
25-
columns = append(columns, relationship.GetSelectDirectColumns()...)
26-
}
27-
return columns
28-
}
29-
func (m Model) FieldVariables() []interface{} {
30-
var fields []interface{}
19+
func (m Model) DirectFields() ([]string, []interface{}) {
20+
var allColumns []string
21+
var allVars []interface{}
3122
for _, attribute := range m.Attributes {
32-
fields = append(fields, attribute.GetSelectDirectVariables()...)
23+
columns, vars := attribute.GetSelectDirect()
24+
allColumns = append(allColumns, columns...)
25+
allVars = append(allVars, vars...)
3326
}
34-
for _, relationship := range m.Relationships {
35-
fields = append(fields, relationship.GetSelectDirectVariables()...)
36-
}
37-
return fields
27+
return allColumns, allVars
3828
}
3929

4030
func (m Model) ExtraColumns() []string {

schema/relationship.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ type Relationship interface {
44
GetKey() string
55
GetType() string
66

7-
GetSelectDirectColumns() []string
8-
GetSelectDirectVariables() []interface{}
97
GetSelectExtraColumns() []string
108
GetSelectExtraVariables() []interface{}
119

0 commit comments

Comments
 (0)