Hey everyone, Im trying to use supabase with types...
# help
n
Hey everyone, Im trying to use supabase with typescript and I noticed that the
.eq
method doesn't support joined tables. Could someone help me out? I'll include details in the thread
n
Hello @nahtnam! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
n
Here is some sample code with the issue:
Copy code
ts
const shape = getShape<definitions["posts"] & { unsplash_category_snapshots: definitions["profiles"]}>()({
  "*": true,
  users: {"_": "profile_id", "*": true}
});

await supabaseClient
  .from<typeof shape>("posts")
  .select(getFields(shape))
  .eq("profiles.email", "asdf@gmail.com")
  .limit(1)
The typescript errors on the
.eq("user.email"
line saying that
user.email
is not a valid option
I think the
.eq
might need to be updated to use the template strings feature in typescript, but I'm not sure. Does anyone have any workarounds other than
// @ts-ignore
?
g
Not great with typescript, and your .select is a function, but to use a foreign table in a filter you need https://supabase.com/docs/reference/javascript/select#filtering-with-inner-joins. Also, as it is hard for me to read your code, is user a table versus users and is it a public schema table and not the auth.users table?
n
Oops that was a typo, it shouldve been
users.email
(these arent my table names, I just changed them to make it easier to understand)
Crap, i forgot that supabase has a
auth
schema, let me rename it to
profiles
so it makes more sense 🙂
And to clarify, the code above works perfectly, its just the types fail. In the
.eq
it expects the first parameter to be a column of the
posts
table, I couldnt figure out a way to have it accept
profiles.email
which is valid postgrest but fails ts
Alright here is a "temp" solution
.from<typeof shape & {"profiles.email": string}>("posts")
n
Thread was archived by @nahtnam. Anyone can send a message to unarchive it.