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

Query pass slice #228

Closed MainTobias closed 1 year ago

MainTobias commented 2 years ago

I have yet to find a way to pass a slice of edgedb.UUIDs to *edgedb.Client.Query.

MainTobias commented 2 years ago
err = db.QuerySingle(ctx, `
        INSERT Restaurant {
            owner := <User>(Select User filter .id = <uuid>$0),
            managers := <User>(Select User filter .id = <uuid>$1),
        name := <str>$2,
        description := <str>$3
        }
        `, &c, randomUser(db, insertedUsers).ID,
            randomUserIDs(db, insertedUsers, 3),
            gofakeit.Company(),
            gofakeit.Adverb())
fmoor commented 2 years ago

Am I reading this correctly? It looks like you want to pas several User ids to $1 to select multiple managers? Passing sets as arguments is not supported so you need to change the query to make <uuid>$1 an array. I think something like this will work for the managers sub query.

select User filter contains(<array<uuid>>$1, .id)

This might be an alternative spelling.

select User filter .id in array_unpack(<array<uuid>>$1)
MainTobias commented 2 years ago

Thank you maybe there is a way to include that in the docs? I believe it might be helpful for new users.

fmoor commented 2 years ago

I'll have a look at adding it.

fmoor commented 1 year ago

added this to the docs in https://github.com/edgedb/edgedb-go/commit/7315ffdbf20cbff04b02f9a19db845e8cd42a4fe