-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtable.go
55 lines (44 loc) · 1.05 KB
/
table.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
package sqlingo
// Table is the interface of a generated table.
type Table interface {
GetName() string
GetSQL(scope scope) string
GetFields() []Field
}
type actualTable interface {
Table
GetFieldsSQL() string
GetFullFieldsSQL() string
}
type table struct {
Table
name string
sqlDialects dialectArray
}
func (t table) GetName() string {
return t.name
}
func (t table) GetSQL(scope scope) string {
return t.sqlDialects[scope.Database.dialect]
}
func (t table) getOperatorPriority() int {
return 0
}
// NewTable creates a reference to a table. It should only be called from generated code.
func NewTable(name string) Table {
return table{name: name, sqlDialects: quoteIdentifier(name)}
}
type derivedTable struct {
name string
selectStatus selectStatus
}
func (t derivedTable) GetName() string {
return t.name
}
func (t derivedTable) GetSQL(scope scope) string {
sql, _ := t.selectStatus.GetSQL()
return "(" + sql + ") AS " + t.name
}
func (t derivedTable) GetFields() []Field {
return activeSelectBase(&t.selectStatus).fields
}