Correct way of handling upserts in MySql

Hey folks! I am using MySql and cannot use onConflictDoUpdate. In leu of that I am wondering if this is a correct way of doing upserts

const updated = await db
  .update(...)
  .set(...)
  .where(eq(..))

// If no rows updated, create new row
if (updated[0].affectedRows === 0) {
  await db.insert(...).values(...)
}


In my use case this record is going to be created once and then updated several times.
Was this page helpful?