-
Notifications
You must be signed in to change notification settings - Fork 923
-
If you have two queries, that return the same struct of the same type is there way to coerce them into returning the same object? Or is the best way to use a go interface after the fact?
https://play.sqlc.dev/p/5633c21e64ed689afc5e86c84da8a5e03d9015c921677a3d480594cc9b43094c
As you can see in this example, I have one function that returns
type GetUserTimeLineRow struct { Tweet Tweet Likedbyself interface{} Bookmarkedbyself interface{} }
and one that returns
type GetTimeLineRow struct { Tweet Tweet Likedbyself interface{} Bookmarkedbyself interface{} }
Is there a way to coerce them into one shape for passing on to a parseTimeLine()
function without having to use interfaces to a do a bit of a type dance?
Or perhaps there is a better way to do it with my schema. I already have a trigger updating the counts so open to other ideas with views, triggers etc.
Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
You won't be able to change the return type of the function, but as the struct fields in GetUserTimeLineRow
and GetTimeLineRow
are identical, you could simply convert either of the types to the other, e.g.
foo := GetUserTimeLineRow{} bar := GetTimeLineRow(foo)
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.