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

Support custom Scanner slices (like JSONB columns with Arrays) #11

Open
slaskis opened this issue Aug 25, 2017 · 4 comments
Open

Support custom Scanner slices (like JSONB columns with Arrays) #11

slaskis opened this issue Aug 25, 2017 · 4 comments

Comments

@slaskis
Copy link

slaskis commented Aug 25, 2017

This project seems great! While giving it a go with a project I'm doing in which, among a lot of things, I use a JSONB column in which I store an array of elements.

I've been using sqlx for named parameters so far which works well but is getting a bit out of hand which is why this "magic" DAO style seems very interesting.

The problem I'm facing is that the array of elements are a type which in turn is a slice which implement the Scanner interface to marshal as JSON.

Something like this:

type Records []*Record

func(r *Records) Scan(value interface{}) error {
	if row, ok := value.([]byte); ok {
		return json.Unmarshal(row, a)
	}
	return nil
}
func (r Records) Value() (driver.Value, error) {
	return json.Marshal(r)
}

When using proteus it expands the slice into multiple variables and my vague guess is that the issue might be that it checks if it's a slice before it checks if it implements the Scanner interface.

I might be able to write a test and a PR but I'm currently choked so I just wanted to give you a heads up and check if it sounds like the right path first.

Thanks!

@jonbodner
Copy link
Owner

Hi Robert,

Thanks for finding this! If you can give me a test case, I can work on a fix.

@jonbodner
Copy link
Owner

This is still on my radar; as soon as I get a chance, I will resolve this.

@slaskis
Copy link
Author

slaskis commented Sep 3, 2017

Cool!

I'm sorry for still not providing any tests yet. I've left this experiment for now but I'll be back as soon as we launch.

Cheers!

@jonbodner
Copy link
Owner

jonbodner commented May 20, 2018

I think I fixed this in Release v0.5.1; if anyone is still interested in this issue, please create a slice type that implements Scanner and Valuer and see if it does the right thing.

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

No branches or pull requests

2 participants