-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add return types #301
Comments
Thanks for the issue @Filsommer Edit: a more complete implementation of the PR I linked above - anand2312#1 |
Thanks for the insights @anand2312 My linter (Pylance) complains:
|
@Filsommer from typing import Any, TypeVar, Type
from pydantic import BaseModel
_ModelT = TypeVar("_ModelT", bound=BaseModel)
class Item(BaseModel):
... # fields are defined here
def parse_query(cls: Type[_ModelT], data: list[dict[str, Any]]) -> list[_ModelT]:
return [cls(**row) for row in data]
items = parse_query(Item, supabase.table("item").select().execute().data)
reveal_type(items) # Type of items is list[Item] |
Can you check out the PRs I linked and tell which of the APIs I've shown in the examples there look better from a user's perspective? Thanks 😄 |
@anand2312, I read your PR and really like the direction you're taking. Some remarks: I feel like I cloned your PR and experimented with some cool ideas:
This would output
Another approach I tried was the prisma way, e.g.: |
Thanks for the feedback @Filsommer ! Auto-generating the models had been on my mind too, very interesting to see an actual solution 😄 Although I doubt I'd put that in the main library (probably an extension library that works along with supabase-py?) Are you on Discord? We can chat in the supabase discord server - https://discord.gg/kk7UgwWYen (i'm |
I'd like to join the discussions too. One thing; I don't think we should go with Feel free to ping me on Discord. |
Another option is to generate based on the SQL Schema by connecting directly to the database. Similar to |
Note: I'm on the latest version: supabase==1.0.3
Is your feature request related to a problem? Please describe.
Related to this issue. However, that issue isn't fixed yet
Describe the solution you'd like
When executing
supabase.table("item").select().execute().data
, it is crucial for me and other users to get a return type beyond Any. In this query the return type should be Item, just as it is when using supabase with Typescript.Describe alternatives you've considered
I saw Prisma for Python offers this. E.g.
items: List[Item] = await prisma.item.find_many()
works as expected.The text was updated successfully, but these errors were encountered: