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 db
No description
10 Replies
Tekipeps
Tekipeps3w ago
In the return type, it also shows as array
No description
Sword Molester
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]!
Tekipeps
Tekipeps3w ago
okay, the return type is not specified in the docs. made me think something was wrong
No description
Sword Molester
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.
kbemaster
kbemaster3w ago
I like to do the following, when I know I just return 1 element
const [insertedValue] = db.insert(table).values(someValue).returning()
const [insertedValue] = db.insert(table).values(someValue).returning()
Tekipeps
Tekipeps3w ago
Ah i see
Sword Molester
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.
Tekipeps
Tekipeps3w ago
.returning() always returns an array regardless
Sword Molester
Yep
Tekipeps
Tekipeps3w ago
thanks
Want results from more Discord servers?
Add your server
More Posts
feedback on my database design (specially with relationships)I'm designing my database, and I'm very bad at relationships, so I would like it if someone could giDeeply nested "with" param in query is failingI'm trying to query with deeply nested with param and getting weird error. Am I doing anything wrong$inferSelect and $inferInsert doesn't return table typesHey There, Im Using Koa.js having issues with inserting as the types arent correctly referenced fromType Hinting $inferSelectHi Drizzle Team, I have the following tables set up with Postgres and Drizzle. There is a `reviews`drizzle postgis geometry always geometry(point)Hello, i am currently testing out the basic postGis support and it would be nice if i can get it worNodeNext Module Resolution Causes `drizzle-kit generate` to fail.Hiiiiii 👋 , I'm having trouble using the kit with `"moduleResuolution": "NodeNext"`. Basicaly that Trouble assigning enum as input for sqlite database.I have an enum in typescript ``` export enum InsuranceStatus { INSURANCE_NOT_REQUIRED = "insuraUse results of a column to pass where conditions elsewhere in the query?I have a field that stores filters that I parse into the SQL conditions for a where clause. Or at leIs there a way to check/constrain a column?I am building a Top 25 college football voting system for my website and I keep going back and forthHow to achieve the same in drizzle ORM ?```sql SELECT 'TOTAL_COURSES' AS name , COUNT(id) FROM course WHERE deleted_at IS NULL UNION ALL SEL