-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
33 lines (30 loc) · 870 Bytes
/
utils.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
package q
import "github.com/wxy365/basal/opt"
// GetColFqn returns full qualified name of column, prefer using the column alias
func GetColFqn(ctx *RenderCtx, column IColumn) string {
escaper := ctx.dbType.escaper()
colName := escaper(column.Alias().OrElse(column.Name()))
return opt.Map(
column.namespace(),
func(ns string) string {
return escaper(ns) + "." + colName
},
).OrElse(colName)
}
// GetColFqnNamePreferred returns full qualified name of column, prefer using the column name
func GetColFqnNamePreferred(ctx *RenderCtx, column IColumn) string {
escaper := ctx.dbType.escaper()
colName := column.Name()
if colName == "" {
colName = column.Alias().Get()
}
if colName != "*" {
colName = escaper(colName)
}
return opt.Map(
column.namespace(),
func(ns string) string {
return escaper(ns) + "." + colName
},
).OrElse(colName)
}