EqualsSQLString handles equality comparisons for UUID columns. Rego always produces string literals, so we accept AstString and cast the literal to ::uuid in the output SQL. This lets PG use native UUID indexes instead of falling back to text comparisons. nolint:revive
(cfg *SQLGenerator, not bool, other Node)
| 53 | // native UUID indexes instead of falling back to text comparisons. |
| 54 | // nolint:revive |
| 55 | func (u astUUIDVar) EqualsSQLString(cfg *SQLGenerator, not bool, other Node) (string, error) { |
| 56 | switch other.UseAs().(type) { |
| 57 | case AstString: |
| 58 | // The other side is a rego string literal like |
| 59 | // "8c0b9bdc-a013-4b14-a49b-5747bc335708". Emit a comparison |
| 60 | // that casts the literal to uuid so PG can use indexes: |
| 61 | // column = 'val'::uuid |
| 62 | // instead of the text-based: |
| 63 | // 'val' = COALESCE(column::text, '') |
| 64 | s, ok := other.(AstString) |
| 65 | if !ok { |
| 66 | return "", xerrors.Errorf("expected AstString, got %T", other) |
| 67 | } |
| 68 | if s.Value == "" { |
| 69 | // Empty string in rego means "no value". Compare the |
| 70 | // column against NULL since UUID columns represent |
| 71 | // absent values as NULL, not empty strings. |
| 72 | op := "IS NULL" |
| 73 | if not { |
| 74 | op = "IS NOT NULL" |
| 75 | } |
| 76 | return fmt.Sprintf("%s %s", u.ColumnString, op), nil |
| 77 | } |
| 78 | return fmt.Sprintf("%s %s '%s'::uuid", |
| 79 | u.ColumnString, equalsOp(not), s.Value), nil |
| 80 | case astUUIDVar: |
| 81 | return basicSQLEquality(cfg, not, u, other), nil |
| 82 | default: |
| 83 | return "", xerrors.Errorf("unsupported equality: %T %s %T", |
| 84 | u, equalsOp(not), other) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // ContainedInSQL implements SupportsContainedIn so that a UUID column |
| 89 | // can appear in membership checks like `col = ANY(ARRAY[...])`. The |
nothing calls this directly
no test coverage detected