Athena

Sorting

.order() in @xylex-group/athena maps to sort_by on the gateway — field, ascending vs descending, and composition with pagination and .single().

.order() maps to the gateway sort_by object on fetch, update, and delete. It can appear before or after .select(), .update(), or .delete().

Shape

interface AthenaSortBy {
  field: string;
  direction: "ascending" | "descending";
}
  • .order("created_at") → ascending
  • .order("created_at", { ascending: true }) → ascending
  • .order("created_at", { ascending: false }) → descending

Examples

Ascending (default):

await athena.from("events").select("id, occurred_at").order("occurred_at");

Descending with a cap:

await athena
  .from("rsf_messages")
  .eq("room_id", roomId)
  .select("*", { stripNulls: false })
  .order("created_at", { ascending: false })
  .limit(100);

With page-based pagination:

await athena
  .from("orders")
  .select("id, total, created_at")
  .order("created_at", { ascending: false })
  .currentPage(1)
  .pageSize(25);

Latest or oldest row

Pair with .single():

const { data: latest } = await athena
  .from("messages")
  .eq("room_id", roomId)
  .select("*")
  .order("created_at", { ascending: false })
  .single();

Limitation: one column

Only the last .order() wins. The SDK does not support multi-column ORDER BY. For that, use .rpc() or .query() / raw SQL paths.