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

Custom Valuer interface breaks inter-operability with packages that implement driver.Valuer #4

Open
NicholasAsimov opened this issue Jul 28, 2023 · 2 comments

Comments

@NicholasAsimov
Copy link

Hi! I'm experiencing a problem with the package where because of the custom Valuer interface, the types that do implement driver.Valuer are not recognized.

For context, I'm using github.com/google/uuid type and since it does implement driver.Valuer interface I expected it to automatically convert to string, so doing something like this would just work:

func myFunc(ctx context.Context, id uuid.UUID) error {
	q := pgq.Update("table").Where(pgq.Eq{"id": id})
}

Is there a reason to not use driver.Valuer interface? It's semantically the same since driver.Valuer is Value() (driver.Value, error) where driver.Value is just an alias to any.

@henvic
Copy link
Owner

henvic commented Jul 30, 2023

Hi Nicholas,

Could you please help me understand what is happening?

  • What is your Go version?
  • What is your pgq version?
  • What is your google/uuid version?

Using Go 1.20, pgq v0.0.2, and github.com/google/uuid v1.3.0, I tested the following code and it worked for me:

q := pgq.Update("table").Where(pgq.Eq{"id": uuid.New()}).Set("x", "y")
fmt.Println(q.SQL())

// Example of output:
// UPDATE table SET x = $1 WHERE id = ANY ($2) [y 59de013e-0348-4c19-9b10-9ada2a673575] <nil>

@henvic
Copy link
Owner

henvic commented Jul 30, 2023

But answering you: the reason I avoided database/sql and database/sql/driver is that this query builder generates queries that aren't compatible with it as I want to take advantage of being able to produce queries that take advantage of PostgreSQL's native protocol as much as possible, including passing slices as an argument.

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