-
Notifications
You must be signed in to change notification settings - Fork 1
/
table.go
42 lines (35 loc) · 787 Bytes
/
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
package sql
import (
"fmt"
)
type Table struct {
Database string
Name string
Alias string
}
func NewTable(database string, name string, alias string) *Table {
return &Table{
Database: database,
Name: name,
Alias: alias,
}
}
func (tb *Table) SQL() *SQL {
return NewSQL().From(tb)
}
func (tb *Table) As(alias string) *Table {
return NewTable(tb.Database, tb.Name, alias)
}
// String return from part of table
func (tb *Table) String() string {
if tb.Alias != "" {
return fmt.Sprintf("`%s`.`%s` AS `%s`", tb.Database, tb.Name, tb.Alias)
}
return fmt.Sprintf("`%s`.`%s`", tb.Database, tb.Name)
}
func (tb *Table) Prefix() string {
if tb.Alias != "" {
return fmt.Sprintf("`%s`", tb.Alias)
}
return fmt.Sprintf("`%s`.`%s`", tb.Database, tb.Name)
}