edgedb / edgedb-go

The official Go client library for EdgeDB
https://pkg.go.dev/github.com/edgedb/edgedb-go
Apache License 2.0
168 stars 11 forks source link

How works code generator //go:generate edgeql-go #316

Closed GenarLoya closed 3 months ago

GenarLoya commented 3 months ago

Describe the bug I am using code generator, following instructions in this page Edgeql Codegen, and investigating how it works go:generate, I have a little idea.

My question is, the code generator can receive querys with embed parameters? By example:

insert Movie {
    title := $title
}

using this, receive this error:

edgeql-go: failed to setup query: error introspecting query "/home/genarold/proyects/go/edgedb-go-fc/select9.edgeql": edgedb.QueryError: missing a type cast before the parameter
query:2:14

    title := $title
             ^ error
gen.go:3: running "edgeql-go": exit status 1

Reproduction I use this proyect structure

├── dbschema
│   ├── default.esdl
│   └── migrations
│       ├── 00001-m1uwekr.edgeql
│       ├── 00002-m1repjt.edgeql
│       └── 00003-m1vl3xa.edgeql
├── edgedb.toml
├── gen.go
├── go.mod
├── go.sum
├── insert.edgeql
└── main.go

gen.go have this code, for use as generate trigger:

package main

//go:generate edgeql-go

for generate code i run go generate or edgeql-go

Expected behavior Use embed parameters in edgeql files for generate functions with all go static types features

Versions:

scotttrinh commented 3 months ago

The issue is in the error message:

missing a type cast before the parameter

EdgeQL requires that all parameters have a type cast, so that would be (assuming a string type here):

insert Movie {
    title := <str>$title
}

Feel free to reopen if you run into any other issues or get any cryptic error messages trying to get this to work.

GenarLoya commented 3 months ago

Thank you