-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Query API #2272
Comments
This was referenced Feb 21, 2024
Should we constrain subjects to just static/fixed length field types? |
The spec in this proposal now lives in https://github.com/latticexyz/mud/blob/main/packages/query/src/api.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We're rethinking how to query for MUD data both in the client and from the indexer. It's designed in such a way to support incremental/streaming updates in an efficient way, so that we can offer a global automatic indexer with filtering and streaming.
Goals
>
,>=
,in
, etc.Reference
For all examples, let's assume a MUD config that looks like:
Proposal
I'm assuming the folks reading this understand TypeScript enough to internalize the constraints of the query API. It's designed to be JSON serializable so is a little more verbose than what might be exposed in client libs. It'll be used in a few different contexts with tooling on top: vanilla JS, React hooks, SSE API.
Subjects
The query API spec above refers to a "subject" in several places. You can think of a subject as a field (or fields) on which a relationship (or relationships) is based. Using SQL to demonstrate:
The subject in this case is
player
, or rather the tuple(player)
, for bothPosition
andInventory
tables. Subjects can span multiple fields and all subjects in a query must share the same underlying tuple of ABI types.A query returns a list of matching subject tuples for all tables in
from
and all conditions inwhere
.Any field of any table in
from
can be used as a query condition inwhere
, not just subject fields. And you can useexcept
to exclude subjects that exist in a given table (like RECS'Not
operator).Getting records
By default, queries only return the list of matched subject tuples. To return the records for a table(s), you can specify the corresponding table subjects in
records
. This is a separate field because we intend for loading records to be a separate operation internally. This means you also return records for tables that were not part of the query, as long as there's a suitable subject for each table that matches the query subject(s).Examples
Please note that the examples below are pseudocode using the query API above. I'm also using table names instead of hex table IDs for readability.
We're planning ship this with a strongly-typed query client for better UX and to simplify writing queries, but want to keep the discussion focused on the unlocks + constraints of the API design itself before we flesh out the query client, async + streaming interfaces, etc.
Give me all players with a position.
Give me all players at position (3, 5).
Give me all players within the bounds of (-5, -5) and (5, 5).
Give me the position of all players that are still alive.
Give me the inventory of all players with a score above 50.
// not possible in RECS today due to composite keys
Give me all players standing on a grass tile.
// not possible in RECS today
Notes
AND
ed together.The text was updated successfully, but these errors were encountered: