edgedb-go icon indicating copy to clipboard operation
edgedb-go copied to clipboard

Query pass slice

Open MainTobias opened this issue 2 years ago • 4 comments

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

MainTobias avatar Jun 25 '22 19:06 MainTobias

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())

MainTobias avatar Jun 25 '22 19:06 MainTobias

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)

fmoor avatar Jun 25 '22 22:06 fmoor

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

MainTobias avatar Jun 27 '22 10:06 MainTobias

I'll have a look at adding it.

fmoor avatar Jun 27 '22 16:06 fmoor

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

fmoor avatar Nov 03 '22 17:11 fmoor