drizzle-team / drizzle-team/drizzle-orm

[BUG]: $returningId returns an empty array unless primaryKey() is put directly on the column

Open
#4,302 0 comments 6 reactions 0 assignees View on GitHub
bug db/mysql qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.40.1

### What version of `drizzle-kit` are you using?

0.30.5

### Other packages

_No response_

### Describe the Bug

DB: mysql
orm: 0.40.1
kit: 0.30.5

$returningId() should return the inserted row's ID, but it returns an empty array unless primaryKey() is added to the column directly, instead of in the callback.

The following works fine.

```
export const table = mysqlTable("table", {
id: serial().notNull().primaryKey()
},
(table) => [
primaryKey({ columns: [table.id], name: "id"}),
]);

```
This does not work
```

export const table = mysqlTable("table", {
id: serial().notNull()
},
(table) => [
primaryKey({ columns: [table.id], name: "id"}),
]);
```

Not a huge problem, just add primaryKey to the column right? Well, not if you constantly pull the schema from the DB. The generated schema will not add primaryKey to the column directly, only in the callback function, so you have to manually add it to all columns every time you pull the schema.

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.