ch some
This commit is contained in:
42
internal/shared/sql.go
Normal file
42
internal/shared/sql.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const UserDisplaySQL = `COALESCE(NULLIF(TRIM(CONCAT_WS(' ', u.first_name, u.last_name)), ''), NULLIF(u.name, ''), u.username, '')`
|
||||
|
||||
const UserInfoSQL = UserDisplaySQL + `, COALESCE(u.username, ''), COALESCE(u.phone, ''), COALESCE(u.email, '')`
|
||||
|
||||
func PrefixedColumns(alias string, cols []string) string {
|
||||
parts := make([]string, len(cols))
|
||||
for i, col := range cols {
|
||||
parts[i] = alias + "." + col
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
}
|
||||
|
||||
func UnmarshalLocalized(raw []byte, dest *LocalizedText) error {
|
||||
if len(raw) == 0 {
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(raw, dest)
|
||||
}
|
||||
|
||||
func OptionalTime(t *FlexibleTime) *time.Time {
|
||||
if t == nil || t.IsZero() {
|
||||
return nil
|
||||
}
|
||||
tt := t.Time()
|
||||
return &tt
|
||||
}
|
||||
|
||||
func OptionalInt64(n *FlexibleInt64) *int64 {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
v := n.Int64()
|
||||
return &v
|
||||
}
|
||||
Reference in New Issue
Block a user