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

Nested and related data? #55

Open
cubecull opened this issue Feb 24, 2023 · 4 comments
Open

Nested and related data? #55

cubecull opened this issue Feb 24, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request roadmap You should be able to see this on https://github.com/orgs/tinyplex/projects/1

Comments

@cubecull
Copy link

cubecull commented Feb 24, 2023

Sorry to open this as an issue but I noticed you've previously said you don't get notifications for Discussions.

Has there been any further movement on supporting one->many queries? Or a pattern I should be following?

_Originally posted in #18

@jamesgpearce
Copy link
Contributor

Do you mean one-to-many (which hopefully can be modeled via the relationships or queries module) or many-to-many?

@cubecull
Copy link
Author

cubecull commented Feb 27, 2023

I do indeed mean 1->many, so it sounds like I've missed an example or I'm misunderstanding something. Specifically I'm asking about how to use https://tinybase.org/api/queries/type-aliases/definition/join/ to achieve one->many queries.

I tried following the Movie Database demo as the closest example, but of course here the relationship is a many->many.

My workaround currently is to store the rowId of the source table row in the matching row of the target table and then execute two queries and join the data together manually. Not sure if this is the intended solution but it feels sub-optimal.

store.setTablesSchema({
  packets: {
    id: { type: 'string' },
    name: { type: 'string' },
  },
  byteRanges: {
    id: { type: 'string' },
    packetId: { type: 'string' },
    name: { type: 'string' },
  },
});

queries.setQueryDefinition('viewingPacket', 'packets', ({ select, where }) => {
  select('id');
  select('name');
  where('id', packetId);
});

queries.setQueryDefinition('viewingPacketByteRanges', 'byteRanges', ({ select, where }) => {
  select('id');
  select('packetId');
  select('name');
  where('packetId', packetId);
});

@jamesgpearce
Copy link
Contributor

Ok so I see the challenge here: you are using a cell called 'Id' rather than the native rowId (which is used in join conditions).

It's not possible to create a join based on columns in both tables. Instead you need to create an expression based on columns in one table (the 'root' table) that identifies the rowId to join to.

Is it possible for you to use id also as the rowId?

@jamesgpearce
Copy link
Contributor

...Not to say your requirement isn't a valid one - just seeing if that helps you out for now.

@jamesgpearce jamesgpearce self-assigned this Sep 27, 2023
@jamesgpearce jamesgpearce added the enhancement New feature or request label Sep 27, 2023
@jamesgpearce jamesgpearce added the roadmap You should be able to see this on https://github.com/orgs/tinyplex/projects/1 label Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request roadmap You should be able to see this on https://github.com/orgs/tinyplex/projects/1
Projects
Status: Aspirational
Development

No branches or pull requests

2 participants