aspen-cloud / triplit

A full-stack, syncing database that runs on both server and client. Pluggable storage (indexeddb, sqlite, durable objects), syncs over websockets, and works with your favorite framework (React, Solid, Vue, Svelte).
https://triplit.dev
GNU Affero General Public License v3.0
2.33k stars 70 forks source link

No option to include relations in type interface #228

Closed marcos-acosta closed 3 weeks ago

marcos-acosta commented 3 weeks ago

Hi! Enjoying your product so far, thanks for developing!

A simple situation that arises is defining a relation in the schema via example_relation: S.Relation*, but when I create a type to use in the rest of my application via type X = Entity<typeof schema, "table-name">, there is no way to ask it to include any of those relations in the way we can when actually querying the data via .query("table-name").include("example_relation"). So the Linter complains that example_relation doesn't exist on the object, even when it does.

The workaround is to compose a new type, which is fine, but a little annoying. I assumed a simple improvement could be to add all relational fields as optional fields when generating the type?

pbohlman commented 3 weeks ago

I think what you're looking for is the EntityWithSelection type which needs to be added to our docs. You can read about it in the blog here. Thanks for flagging.

marcos-acosta commented 3 weeks ago

That's exactly what I was looking for, thanks!