celsql

package
v0.64.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package celsql compiles a CEL expression (a "cel"-flavored calculated search source, SD-9/FR-A6) into equivalent SQL text expressions — one for Postgres (fed to to_tsvector, SD-7) and one for the SQLite fallback (FR-B5) — after type-checking the CEL against the resource's proto message descriptor.

Why this package lives under cmd/ (WS-011 / FR-X1 graph isolation)

github.com/google/cel-go is a build-time-only concern: search sources are compiled to SQL during codegen and never at runtime. cel-go MUST NOT enter the devedge-sdk *root* module's runtime dependency graph (a downstream app that imports only .../server must stay light; see scripts/check-graph-isolation.sh).

The root package internal/aip is imported at runtime by middleware/redact, so the CEL compiler cannot live there. It lives here in the cmd module (github.com/infobloxopen/devedge-sdk/cmd), a separate nested module that already carries the codegen-only heavy dependencies (the CLI imports ent/gorm). The root module does not require cmd — cmd requires root — so cel-go reaches only the cmd build closure. This package is internal to cmd and is meant to be consumed ONLY by the cmd/protoc-gen-* plugins (wiring is a later task; this file is the standalone compiler).

Supported subset (and nothing more)

The compiler accepts exactly the constructs the DDI search shapes need and fails loud, naming the offending construct, on anything else — it never guesses SQL:

  • field references: msg.<field> → the quoted column
  • ternary cond ? a : b → CASE WHEN <cond> THEN a ELSE b END
  • map-literal lookup {k:v, ...}[key] → CASE <key> WHEN k THEN v ... END
  • string concat a + b → a || b
  • string ops .lowerAscii(), .replace(f, t) → lower(...), replace(...)
  • message / map / tags access msg.m.f, m[k] → Postgres ->>/#>> , SQLite json_extract
  • equality / boolean conditions (only inside a ternary/map condition): ==, !=, &&, ||, ! → =, <>, AND, OR, NOT

Arithmetic, comparisons other than ==/!=, comprehensions (.map/.filter/.exists), list/struct literals, and any function outside {replace, lowerAscii} are rejected.

Index

Constants

View Source
const RootVar = "msg"

RootVar is the CEL variable bound to the resource message. Field references in a search source are written against it, e.g. `msg.display_name`.

Variables

This section is empty.

Functions

func CompileCEL

func CompileCEL(expr string, md protoreflect.MessageDescriptor) (postgresExpr, sqliteExpr string, err error)

CompileCEL type-checks expr against md, then compiles the supported subset into an equivalent Postgres text expression (suitable as a to_tsvector argument) and an equivalent SQLite-fallback text expression. It returns a descriptive error — naming the unsupported construct — for any CEL outside the supported subset, rather than emitting wrong or guessed SQL.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL