Collection: list() method

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The list() method of the Collection interface resolves with a page of entries, each without its value.

Syntax

list()
list(options)

Parameters

options Optional

An object with any of these properties:

where
meta keys and values that every entry listed has, matched by equality.
owner
Only this player’s entries.
order
"score", "-score", "created", "-created", "updated" or "-updated". Defaults to "-created", newest first.
limit
The most entries in the page, from 1 to 100. Defaults to 20.
after
The next of the page before, for the page after it.

Return value

A Promise that resolves with { entries, next }. Each entry has the properties get() gives but value. next is null on the last page.

Exceptions

The promise rejects with a DataError, such as E_INVALID for a limit out of range.

Description

Ties go by id, and entries without a score come last in both score orders. list() is never cached, so call it on an event or every few seconds, not every tick.

Examples

Showing the highest-rated levels

// browse.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  async onMessage(room, connection, message) {
    const m = message as { type?: string; after?: string | null };
    if (m.type !== "browse") return;
    const page = await room.collection("levels").list({ where: { theme: "lava" }, order: "-score", limit: 10, after: m.after ?? null });
    room.send(connection, { type: "levels", ids: page.entries.map((e) => e.id), next: page.next });
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
list()0.10.10.10.1