Documentation ¶
Overview ¶
Package sqltypes contains the types used to convert rego queries into SQL. The rego ast is converted into these types to better control the SQL generation. It allows writing the SQL generation for types in an easier to read way.
Index ¶
- func IsPrimitive(n Node) bool
- func RegoVarPath(path []string, terms []*ast.Term) ([]*ast.Term, error)
- type ASTArray
- type AstBoolean
- type AstNumber
- type AstString
- type BooleanNode
- func And(source RegoSource, terms ...BooleanNode) BooleanNode
- func Bool(t bool) BooleanNode
- func BoolParenthesis(value BooleanNode) BooleanNode
- func Equality(notEquals bool, a, b Node) BooleanNode
- func MemberOf(needle, haystack Node) BooleanNode
- func Or(source RegoSource, terms ...BooleanNode) BooleanNode
- type Node
- type RegoSource
- type SQLGenerator
- type SupportsContainedIn
- type SupportsContains
- type SupportsEquality
- type VariableConverter
- type VariableMatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPrimitive ¶
Types ¶
type ASTArray ¶
type ASTArray struct { Source RegoSource Value []Node }
func (ASTArray) ContainsSQL ¶
func (a ASTArray) ContainsSQL(cfg *SQLGenerator, needle Node) (string, error)
func (ASTArray) SQLString ¶
func (a ASTArray) SQLString(cfg *SQLGenerator) string
type AstBoolean ¶
type AstBoolean struct { Source RegoSource Value bool }
AstBoolean is a literal true/false value.
func (AstBoolean) EqualsSQLString ¶
func (b AstBoolean) EqualsSQLString(cfg *SQLGenerator, not bool, other Node) (string, error)
func (AstBoolean) IsBooleanNode ¶
func (AstBoolean) IsBooleanNode()
func (AstBoolean) SQLString ¶
func (b AstBoolean) SQLString(_ *SQLGenerator) string
func (AstBoolean) UseAs ¶
func (AstBoolean) UseAs() Node
type AstNumber ¶
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 (AstNumber) EqualsSQLString ¶
func (AstNumber) SQLString ¶
func (n AstNumber) SQLString(_ *SQLGenerator) string
type AstString ¶
type AstString struct { Source RegoSource Value string }
func (AstString) EqualsSQLString ¶
func (AstString) SQLString ¶
func (s AstString) SQLString(_ *SQLGenerator) string
type BooleanNode ¶
type BooleanNode interface { Node IsBooleanNode() }
BooleanNode is a node that returns a true/false when evaluated.
func And ¶
func And(source RegoSource, terms ...BooleanNode) BooleanNode
func Bool ¶
func Bool(t bool) BooleanNode
func BoolParenthesis ¶
func BoolParenthesis(value BooleanNode) BooleanNode
BoolParenthesis wraps the given boolean node in parens. This is useful for grouping and avoiding ambiguity. This does not work for mathematical parenthesis to change order of operations.
func Equality ¶
func Equality(notEquals bool, a, b Node) BooleanNode
func MemberOf ¶
func MemberOf(needle, haystack Node) BooleanNode
func Or ¶
func Or(source RegoSource, terms ...BooleanNode) BooleanNode
type Node ¶
type Node interface { SQLString(cfg *SQLGenerator) string // UseAs is a helper function to allow a node to be used as a different // Node in operators. For example, a variable is really just a "string", so // having the Equality operator check for "String" or "StringVar" is just // excessive. Instead, we can just have the variable implement this function. UseAs() Node }
func AlwaysFalseNode ¶
AlwaysFalseNode is mainly used for unit testing to make a Node immediately.
type RegoSource ¶
type RegoSource string
type SQLGenerator ¶
type SQLGenerator struct {
// contains filtered or unexported fields
}
func NewSQLGenerator ¶
func NewSQLGenerator() *SQLGenerator
func (*SQLGenerator) AddError ¶
func (g *SQLGenerator) AddError(err error)
func (*SQLGenerator) Errors ¶
func (g *SQLGenerator) Errors() []error
type SupportsContainedIn ¶
type SupportsContainedIn interface {
ContainedInSQL(cfg *SQLGenerator, other Node) (string, error)
}
SupportsContainedIn is the inverse of SupportsContains. It is implemented from the "needle" rather than the haystack.
type SupportsContains ¶
type SupportsContains interface {
ContainsSQL(cfg *SQLGenerator, other Node) (string, error)
}
SupportsContains is an interface that can be implemented by types that support "me.Contains(other)". This is `internal_member2` in the rego.
type SupportsEquality ¶
type SupportsEquality interface { // EqualsSQLString intentionally returns an error. This is so if // left = right is not supported, we can try right = left. EqualsSQLString(cfg *SQLGenerator, not bool, other Node) (string, error) }
SupportsEquality is an interface that can be implemented by types that support equality with other types. We defer to other types to implement this as it is much easier to implement this in the context of the type.
type VariableConverter ¶
type VariableConverter struct {
// contains filtered or unexported fields
}
func NewVariableConverter ¶
func NewVariableConverter() *VariableConverter
func (*VariableConverter) ConvertVariable ¶
func (vc *VariableConverter) ConvertVariable(rego ast.Ref) (Node, bool)
func (*VariableConverter) RegisterMatcher ¶
func (vc *VariableConverter) RegisterMatcher(m ...VariableMatcher) *VariableConverter
type VariableMatcher ¶
func AlwaysFalse ¶
func AlwaysFalse(m VariableMatcher) VariableMatcher
AlwaysFalse overrides the inner node with a constant "false".
func StringVarMatcher ¶
func StringVarMatcher(sqlString string, regoPath []string) VariableMatcher