id on transaction conflict

hey all, using mysql (planetscale). when a transaction conflict happens over an insert with the same 'serial'
id
i believe that mysql will resolve this by changing one of the inserts to the next available.
my concern is that within a transaction i want to reference the returned
id
to use as a reference. will this
id
match the 'new'
id
after the conflict has resolved, or will it reference the original?
here is some code to better explain maybe:

async function test() {
  await db.transaction(async (tx) => {
    const insertRecord = await tx.insert(record).values({
      foo: "bar",
    });

    await tx
      .insert(user)
      .values({
        foo: "bar",
        recordId: parseInt(insertRecord.insertId)  // is insertId ok on conflict?
       });
  });
}


This is my first time trying to make something production ready so want to make sure all situations are covered, any help is appreciated thank you!
Was this page helpful?