I see I can create tables with foreign keys, but I don’t see a way to write queries with joins in the frontend. Did I miss something or is that not implemented yet?
Or if I could define a view on the backend and use that in the same way as a table with useQuery(), that’d be great
Joins are not supported yet, but will be in the future
We’ve also looked into adding support for views. To make views work well with the row level security policies, we need the security_invoker feature of Postgres 15 (which is not out yet). Or we need to implement some kind of workaround.
For me, by the way, the views would be of greater benefit as I’d generally prefer writing queries directly in SQL rather than via the client library functions- I can execute them in a database tool of my choice, I can use various built-in functions, I’m less dependent on 3rd-party code, and users can’t see the queries I’m using if they dig into the code.
@exiang yes we don’t have joins yet. You need to manually fetch the task’s user like this:
function Task({ task }: TaskProps) {
const user = useQuerySingleResult(query('users').filterWhere('id', task.userId));
return <div>{task.title} created by {user.email}</div>
}
If the types are older than a week, try to change something in the Schema Designer to trigger a rebuild. After that install the latest generated types.