Better type support in Swift Client database requests #27544
Unanswered
tmcgann
asked this question in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I like the Supabase swift client we have today but I think it would be so much better if it had better type support or could do some kind of type inference. For example, today I have a query like this:
client .from("some_table") .update([ "some_column": "some_value", ]) .eq("some_id", value: someUUID) .execute()If the column names in my database change and I don't update the strings in this code then this request throws a runtime error instead of a compile time error.
It would be so much better if instead of allowing any arbitrary string in
.fromor.eqor even in the.updatedictionary (or anything referencing database tables, columns, etc.) it could detect if that string was actually a valid column. I've seen this kind of thing done with ORMs in the TypeScript world and it's amazing DX. Even if you could give the client some type hints by passing in a model to the.fromor to some kind of generic where it could then require you pass in the correct column names based on that model...that would be amazing. All your client requests would then be typed; no magic strings; compile time errors for the win. I'm already definingCodableDTOs anyway, so those could be used in the client requests as well when pushing data back to the database.Example model:
Example usage:
// BAD client .from(SomeModelDTO.self) .update([ "some_column": "some_value", // ERROR: Not a valid column name ]) .eq("some_id", value: someUUID) // ERROR: Not a valid column name .execute() // GOOD client .from(SomeModelDTO.self) .update([ SomeModelDTO.CodingKeys.name: "some_value", ]) .eq(SomeModelDTO.CodingKeys.id, value: someUUID) .execute()Open to other ideas (e.g. autogenerated models, etc.) but I'm desperate for a solution that will make my code more maintainable and leverage the advantages of the compiler/types.
I dropped a comment on the Swift OpenAPI generator discussion. That poses another interesting solution.
All reactions