UPSERT operation not working for SQLite/Turso

Hey! So I'm trying to do a BULK UPSERT for multiple rows with a
.returning()
and its not working. I expect:
  • UPDATE: rows which include the PKs
    "id"
  • INSERT: rows which DO NOT include the PKs
    "id"

    the code is as follows (I've followed the docs and tried some variants):
    const data [
    // this row IS NOT updated (from "Untitled1" to "John")
    { id: "nhdbw1xklex5", name: "John" },
    // this row IS properly inserted
    { name: "Unknown2" } 
    ]
    const result = await db
    .insert(users)
    .values(data)
    .onConflictDoUpdate({
      target: users.id,
      set: { id: sql.raw(`excluded.${user.id.name}`) },
    })
    .returning();

    I would expect results being:
    [
    { id: "nhdbw1xklex5", name: "John" },
    { id: "<nanoid-here>", name: "Untitled2" } 
    ]

    and I keep getting (the first row is unchanged / not updated):
    [
    { id: "nhdbw1xklex5", name: "Untitled1" },
    { id: "<nanoid-here>", name: "Untitled2" } 
    ]

    Am I doing something wrong? Thanks! Any help is greatly appreciated!
Was this page helpful?