-
Notifications
You must be signed in to change notification settings - Fork 0
/
const.go
36 lines (31 loc) · 873 Bytes
/
const.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
package squl
import (
stdfmt "fmt"
"strconv"
"github.com/google/uuid"
fmt "golang.org/x/xerrors"
"github.com/trivigy/squl/internal/global"
)
// Const describes a constant primitive value.
type Const struct {
Value interface{}
}
func (r *Const) dump(counter *ordinalMarker) (string, error) {
switch val := r.Value.(type) {
case uuid.UUID:
return stdfmt.Sprintf("'%s'", val.String()), nil
case string:
return stdfmt.Sprintf("'%s'", val), nil
case int, int8, int16, int32, int64,
uint, uint8, uint16, uint32, uint64:
return stdfmt.Sprintf("%d", val), nil
case float32:
return strconv.FormatFloat(float64(val), 'f', -1, 32), nil
case float64:
return strconv.FormatFloat(val, 'f', -1, 64), nil
case Node:
return val.dump(counter)
default:
return "", fmt.Errorf(global.ErrFmt, pkg.Name(), fmt.Errorf("unknown type (%T) for %q", val, val))
}
}