Bug When Trying To Increment A Field

this set the field to 0 instead of increasing by one it used to work in other routes
await db
.update(Artists)
.set({ songs: sql`${Artists.songs} = ${Artists.songs} + 1 ` })
.where(eq(Artists.id, id));
await db
.update(Artists)
.set({ songs: sql`${Artists.songs} = ${Artists.songs} + 1 ` })
.where(eq(Artists.id, id));
3 Replies
Andrii Sherman
try this one
await db
.update(Artists)
.set({ songs: sql`${Artists.songs} + 1`})
.where(eq(Artists.id, id));
await db
.update(Artists)
.set({ songs: sql`${Artists.songs} + 1`})
.where(eq(Artists.id, id));
George F.Ramzi
George F.RamziOP2y ago
it works thank you very much
jakeleventhal
jakeleventhal12mo ago
logins: integer('logins').default(1).notNull(),
logins: integer('logins').default(1).notNull(),
await db
.update(users)
.set({ logins: sql`${users.logins} + 1` })
.where(eq(users.id, user.id));
await db
.update(users)
.set({ logins: sql`${users.logins} + 1` })
.where(eq(users.id, user.id));
ERROR: invalid input syntax for type integer: "[object Object]"
CONTEXT: unnamed portal parameter $1 = '...'
STATEMENT: update "User" set "logins" = $1 where "User"."id" = $2
ERROR: invalid input syntax for type integer: "[object Object]"
CONTEXT: unnamed portal parameter $1 = '...'
STATEMENT: update "User" set "logins" = $1 where "User"."id" = $2
This doesn't seem to work for me
Want results from more Discord servers?
Add your server