Athena

Mutations

insert, update, upsert, and delete with @xylex-group/athena — filters as WHERE, returning rows, and delete safety rules.

Insert

const { data: inserted } = await athena
  .from("users")
  .insert({ name: "Bilbo", email: "bilbo@shire.com" })
  .select("id, name");

const { data } = await athena
  .from("characters")
  .insert([{ name: "Frodo" }, { name: "Sam" }])
  .select();

Single payload vs array infers AthenaResult row shape (User | null vs User[] | null).

Update

Apply filters before .update(). They become the WHERE clause.

const { data: updated } = await athena
  .from("users")
  .update({ name: "Bilbo Baggins" })
  .eq("id", userId)
  .select();

Upsert

await athena
  .from("users")
  .upsert(
    { id: 1, name: "Bilbo" },
    { updateBody: { name: "Bilbo Baggins" }, onConflict: "id" },
  )
  .select("id, name");

updateBody is applied on conflict; onConflict names the unique key column(s).

Delete

await athena.from("users").eq("id", 1).delete();

const { data: deleted } = await athena
  .from("users")
  .eq("resource_id", "abc-123")
  .delete()
  .select("id, name");

Requirement: you must provide .eq("resource_id", …), .eq("id", …), or delete({ resourceId }). Calling .delete() without one throws synchronously.