Collection: list() method
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe list() method of the Collection interface resolves with a page of entries, each without its value.
Syntax
list()
list(options)
Parameters
optionsOptional-
An object with any of these properties:
wheremetakeys 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
nextof 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
Collection.get(), for an entry’s value
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
list() | 0.1 | 0.1 | 0.1 | 0.1 |