-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_info.go
40 lines (33 loc) · 911 Bytes
/
table_info.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
package pgtalk
import (
"fmt"
"io"
)
// TableInfo describes a table in the database.
type TableInfo struct {
Name string
Schema string // e.g. public
Alias string
// Columns are all known columns for this table ;initialized by the generated package
Columns []ColumnAccessor
}
// FullName returns the fully qualified name of the table.
func (t TableInfo) FullName() string {
return fmt.Sprintf("%s.%s", t.Schema, t.Name)
}
func (t TableInfo) SQLOn(w io.Writer) {
fmt.Fprintf(w, "%s.%s %s", t.Schema, t.Name, t.Alias)
}
func (t TableInfo) Equals(o TableInfo) bool {
return t.Name == o.Name && t.Schema == o.Schema && t.Alias == o.Alias
}
func (t TableInfo) String() string {
return fmt.Sprintf("table(%s.%s %s)", t.Schema, t.Name, t.Alias)
}
func (t TableInfo) WithAlias(aliasName string) TableInfo {
if aliasName == "" {
panic("alias cannot be empty")
}
t.Alias = aliasName
return t
}