-
Notifications
You must be signed in to change notification settings - Fork 923
use external types #2182
-
Hi, I am wondering if there is any good way to use sqlc with other codegen tools. For example when using https://github.com/ogen-go/ogen, both sqlc and ogen come with their own type. But chances are that both are pretty much the same. It feels wasteful to map fields from one type to another type, especially for list queries.
If we take the authors example from the docs, the type generated by ogen might look like this
type Author struct { ID float64 `json:"id"` Name string `json:"name"` Bio OptString `json:"bio"` }
And the type generated by sqlc looks like this
type Author struct { ID int64 Name string Bio sql.NullString }
In order to use the data from the sqlc query struct, we need to do something like this
func convert(a store.Author) openapi.Author { return openapi.Author{ ID: float64(a.ID), Name: a.Name, Bio: openapi.OptString{ Value: a.Bio.String, Set: a.Bio.Valid, }, } }
So, It would be nice if both could use the same type somehow.
This is not specific to ogen. It does apply to other codegen tools and maybe even user created types as well.
Beta Was this translation helpful? Give feedback.