Skip to content
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

[Feature]: Sorting and $in where filter #351

Open
1 task
starknetdev opened this issue Dec 8, 2024 · 0 comments
Open
1 task

[Feature]: Sorting and $in where filter #351

starknetdev opened this issue Dec 8, 2024 · 0 comments

Comments

@starknetdev
Copy link
Contributor

Feature Request

To perform any paginated queries the data requires sorting. Currently any query will give results in a random order, and querying with a limit will always rerun until all data is fetched.

Secondly, cross referencing entities to fetch is difficult without $in filters. Currently I need to perform a single fetch for my paginated results, which is not optimal.

Proposed Solution

Enable the following queries:

Sorting

  sdk.getEntities({
    query: useMemo<TournamentGetQuery>(
      () => ({
        tournament: {
          TournamentModel: []
        },
      }),
      []
    ),
    callback: (resp) => {
      if (resp.error) {
        console.error("useSdkGetEntities() error:", resp.error.message);
        return;
      }
      if (resp.data) {
        setEntities(resp.data);
      }
    }
    orderBy: {
      tournament_id: "asc",
    },
    limit: 10,
    offset: 0
  });

In where filter

  sdk.getEntities({
    query: useMemo<TournamentGetQuery>(
      () => ({
        tournament: {
          TournamentEntriesModel: {
            $: {
              where: {
                tournament_id: { $in: tournamentIds },
              },
            },
          },
        },
      }),
      [tournamentIds]
    ),
    callback: (resp) => {
      if (resp.error) {
        console.error("useSdkGetEntities() error:", resp.error.message);
        return;
      }
      if (resp.data) {
        setEntities(resp.data);
      }
    }
  });

This is also useful in subscriptions.

Alternatives

No response

Related Code

No response

Additional context

No response

If the feature is accepted, would you be willing to contribute it?

  • Yes I would be willing to contribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant