MCPcopy Index your code
hub / github.com/coder/coder / ContainsSQL

Method ContainsSQL

coderd/rbac/regosql/sqltypes/array.go:30–44  ·  view source on GitHub ↗
(cfg *SQLGenerator, needle Node)

Source from the content-addressed store, hash-verified

28func (ASTArray) UseAs() Node { return ASTArray{} }
29
30func (a ASTArray) ContainsSQL(cfg *SQLGenerator, needle Node) (string, error) {
31 // If we have no elements in our set, then our needle is never in the set.
32 if len(a.Value) == 0 {
33 return "false", nil
34 }
35
36 // This condition supports any contains function if the needle type is
37 // the same as the ASTArray element type.
38 if reflect.TypeOf(a.MyType().UseAs()) != reflect.TypeOf(needle.UseAs()) {
39 return "ArrayContainsError", xerrors.Errorf("array contains %q: type mismatch (%T, %T)",
40 a.Source, a.MyType(), needle)
41 }
42
43 return fmt.Sprintf("%s = ANY(%s)", needle.SQLString(cfg), a.SQLString(cfg)), nil
44}
45
46func (a ASTArray) SQLString(cfg *SQLGenerator) string {
47 switch a.MyType().UseAs().(type) {

Callers

nothing calls this directly

Calls 5

MyTypeMethod · 0.95
SQLStringMethod · 0.95
UseAsMethod · 0.65
SQLStringMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected