drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.47k stars 486 forks source link

[BUG]: The update method returns the updated information even when a non-existent key is used to update a value. #2472

Open motoi-dev opened 3 weeks ago

motoi-dev commented 3 weeks ago

What version of drizzle-orm are you using?

0.30.4

What version of drizzle-kit are you using?

0.20.14

Describe the Bug

As the title, the update method returns the updated information even when a non-existent key is used to update a value. For example, the below result is [{ updatedUserId: 2 }], however, age column does not exist.

curl -X 'PATCH' \
  'http://localhost:8787/users/2' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{"age": 2}'
import type { User } from './schema'
...

const app = new Hono()
app.patch(
  '/users',
  async (c) => {
    const userId = c.req.param('id')
    const body = await c.req.json<User>()
    const result = await db
      .update(users)
      .set(body)
      .where(eq(users.id, Number(userId)))
      .returning({ updatedUserId: users.id })

    console.log(result)

    return c.json({ ok })
  }
)
export const users = sqliteTable('users', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  name: text('name').unique(),
})

export type User = typeof users.$inferSelect

Expected behavior

Non-existent column error occurs.

Environment & setup

No response