-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Generate Typescript definitions #103
Comments
Am I correct in assuming this will enable a better typed Data API similar to what Prisma offers where a dev can run a script using a CLI tool to generate a typed client and then use that typed client to get automatic return types for their query, for example: const data = await typedSupabaseClient.posts.findMany({
where: { author: "Bob" },
include: { author: true }
});
// With the inferred return type of data thus being (Post & { author: Author })[] I know that the API might have to be more explicit e.g. what fields to perform a join on, but I think the DX is quite nice. I'm currently using tRPC + Prisma + NextJS API Routes to achieve this kind of type safety, but would love to be able to do this directly with Supabase 😀 |
@thomas-coldwell this one's a bit different, the aim is to generate the types for your tables & columns, so you don't have to manually write something like this yourself: // CREATE TABLE users (
// id int8,
// data text
// );
interface Users {
id: number
data: string
} And then you use it like: const { data }: { data: Users[] } = await supabase
.from<Users>('users')
.select() We don't really do ORMs, so this is just for convenience when working with the REST API. |
Is anyone currently working on this? I could have a look.
Would the lib would also generate files or just print it out as text e.g. \cc @kiwicopple |
This issue has been stalled for a while - I suspect we'd need to sort out supabase/supabase-js#170 first (updating type implementation especially) before we do this. |
Ah ok 👍🏼 I was just looking around for issues to help with 🙂 |
Would this also support signatures for |
@mr-bjerre it's technically possible, but would need more work to make arguments type-safe from pg-meta itself. So yeah |
Alright. Do you plan to add typesafety for it? And what about selects where you join tables? |
The jury's out if we can make it type-safe, but yes ideally we'd have type-safety. Re: |
Closing as it's now supported. |
Feature request
Is your feature request related to a problem? Please describe.
Currently we recommend creating Types from the OpenAPI spec (https://supabase.io/docs/reference/javascript/generating-types)
This will cause a few problems because the types in Open API spec are somewhat limited.
Describe the solution you'd like
It would be great to generate these definitions directly from the database. If we build it into this library then we can use it on the Dashboard and our CLI.
Additional context
selects
(which allow relationship) andinsert/update
(which don't allow relationships)The text was updated successfully, but these errors were encountered: