Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

use external types #2182

Unanswered
bluebrown asked this question in Issue Triage
Discussion options

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.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /