Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
main
terraform-provider-bookstore
# libcel2db should be compiled and added.
example/service/libcel2db.a
Empty file added BUILD.bazel
Empty file.
15 changes: 14 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,17 @@ go install github.com/aep-dev/api-linter/cmd/api-linter@latest
The standard GoLang toolchain is used, with the addition of protobuf for
compiling the resource definition.
1. `./scripts/regenerate-all.sh`
2. `go build main.go`
2. `go build main.go`

## Importing cel2db

Today, the CEL <-> SQL translation in the example service requireds [cel2db](https://github.com/aep-dev/cel2db), written in Rust and therefore not compatible with the standard `go get` approach to managing dependencies.

This will be streamlined in the future, but for now, do the following (bazel and rust build tooling is required):

```bash
git clone git@github.com:aep-dev/cel2db.git
cd ./cel2db
bazel build //cel2db:cel2db_static
cp bazel-bin/cel2db/libcel2db.a ${AEPC_REPO}/example/service/
```
16 changes: 16 additions & 0 deletions example/service/cel.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package service

// required for cel2db.

// extern char *cel_to_sql(const char *cel_expr, const char *sql_dialect);
// #cgo LDFLAGS: -L ${SRCDIR} -lcel2db
import "C"

import (
"errors"

"github.com/aep-dev/aepc/pkg/cel2ansisql"
"github.com/google/cel-go/cel"
)

func convertCELToSQL(expr string) (string, error) {
condition := C.cel_to_sql(C.CString(expr), C.CString("sqlite"))
if condition == nil {
return "", errors.New("failed to convert CEL to SQL")
}
return C.GoString(condition), nil
}

func convertCELToSQL2(expr string) (string, error) {
if expr == "" {
return "", nil
}
Expand Down
5 changes: 5 additions & 0 deletions example/service/cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func TestCELToSQL(t *testing.T) {
input: "description.startsWith('tomorrow')",
expected: "description LIKE CONCAT('tomorrow', '%')",
},
{
name: "arithemtic",
input: "1 + 2",
expected: "1 + 2",
},
{
name: "empty",
input: "",
Expand Down
Loading