pgq icon indicating copy to clipboard operation
pgq copied to clipboard

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

Open NicholasAsimov opened this issue 2 years ago • 2 comments

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.

NicholasAsimov avatar Jul 28 '23 12:07 NicholasAsimov

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 avatar Jul 30 '23 22:07 henvic

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.

henvic avatar Jul 30 '23 22:07 henvic