How do I make .returning() return only the inserted value instead of array
Here I have
createResource
to insert a single record. The result from .returning is an array. I am using neon postgres db10 Replies
In the return type, it also shows as array
It returns an array composed only of the records you've inserted in that query, no? If you know that there will be one record, since that is what you're inserting, just
return createdResource[0]!
okay, the return type is not specified in the docs. made me think something was wrong
I see, values is meant to take in (spread) array inside, so it works as intended, though I agree that it might be not very clear at the first glance.
I like to do the following, when I know I just return 1 element
Ah i see
With some sqlite drivers, you can add
.get()
to the query to specify that it's single or no records returned, that's what I usually do..returning()
always returns an array regardlessYep
thanks