drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: return a object instead of a array if insert value is a object not array

Open
#1,237 32 comments 161 reactions 0 assignees View on GitHub
enhancement qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

Hi, I want to create a row, so I code this.

```ts
const model = await this.db.drizzle
.insert(schema.user)
.values({
authCode,
...userDto,
password: hashSync(userDto.password, 10),
})
.returning()

return model[0]
```

I added a `.returning` to get the new model. But I got `model[]`, to I should destruct it first. `model[0]` is the data I want. But I insert just a single object, so the expected result should be an object, which can save one step of writing.

This is the expected behaviour.

```ts
const model = await this.db.drizzle
.insert(schema.user)
.values({
authCode,
...userDto,
password: hashSync(userDto.password, 10),
})
.returning()

return model
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.