Skip to content
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

Fix result generation for map, slice, pointer when targeting other package #66

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mikeschinkel
Copy link

@mikeschinkel mikeschinkel commented Dec 17, 2023

Using the following command line where persister contains files generated by sqlc, the latest version in master generates invalid code for results that are references, e.g. map, slice, and pointers.

This PR aims to fix that — which appear to be that the original fix for #12 was incomplete, and this PR assumes PR #65 has been committed.

ifacemaker -f ./persister/*.go -s Queries -i DataStoreQueries -p app -o ./app/query.iface.go

Here is the test code I wrote against:

package persister
type Category struct {}
func (q *Queries) Ex1() (map[int]*Category, error) {
	return nil, nil
}
func (q *Queries) Ex2() (map[int]Category, error) {
	return nil, nil
}
func (q *Queries) Ex3() ([]*Category, error) {
	return nil, nil
}
func (q *Queries) Ex4() ([]Category, error) {
	return nil, nil
}
func (q *Queries) Ex5() (*Category, error) {
	return nil, nil
}

Without the PR it generates this (and some newlines I removed), which fails to compile in Go:

// Code generated by ifacemaker; DO NOT EDIT.
package app
import (
	_ "embed"
	_ "github.com/mattn/go-sqlite3"
)
// DataStoreQueries ...
type DataStoreQueries interface {
	Ex1() (map[int]*Category, error)
	Ex2() (map[int]Category, error)
	Ex3() ([]*Category, error)
	Ex4() ([]Category, error)
	Ex5() (*Category, error)
}

With the PR, it generates this, also minus newlines, which does compile in Go:

// Code generated by ifacemaker; DO NOT EDIT.
package app
import (
	_ "embed"
	_ "github.com/mattn/go-sqlite3"
	"github.com/mikeschinkel/gerardus/persister"
)
// DataStoreQueries ...
type DataStoreQueries interface {
	Ex1() (map[int]*persister.Category, error)
	Ex2() (map[int]persister.Category, error)
	Ex3() ([]*persister.Category, error)
	Ex4() ([]persister.Category, error)
	Ex5() (*persister.Category, error)
}

@mikeschinkel mikeschinkel changed the title Fix struct validation for multiple files Fix result generation for map, slice, pointer when targeting package Dec 17, 2023
@mikeschinkel mikeschinkel changed the title Fix result generation for map, slice, pointer when targeting package Fix result generation for map, slice, pointer when targeting other package Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant