-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathnumber.go
More file actions
36 lines (29 loc) · 971 Bytes
/
number.go
File metadata and controls
36 lines (29 loc) · 971 Bytes
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 sqltypes
import (
"encoding/json"
"golang.org/x/xerrors"
)
type AstNumber struct {
Source RegoSource
// Value is intentionally vague as to if it's an integer or a float.
// This defers that decision to the user. Rego keeps all numbers in this
// type. If we were to source the type from something other than Rego,
// we might want to make a Float and Int type which keep the original
// precision.
Value json.Number
}
func Number(source RegoSource, v json.Number) Node {
return AstNumber{Value: v, Source: source}
}
func (AstNumber) UseAs() Node { return AstNumber{} }
func (n AstNumber) SQLString(_ *SQLGenerator) string {
return n.Value.String()
}
func (n AstNumber) EqualsSQLString(cfg *SQLGenerator, not bool, other Node) (string, error) {
switch other.UseAs().(type) {
case AstNumber:
return basicSQLEquality(cfg, not, n, other), nil
default:
return "", xerrors.Errorf("unsupported equality: %T %s %T", n, equalsOp(not), other)
}
}