Commit Graph

6 Commits (79cab4640f4ba70c4be37ff2071ed4180ba8b63a)

Author SHA1 Message Date
Jack Christensen 6ea2d248a3 Remove anynil.NormalizeSlice
anynil.Is was already being called in all paths that
anynil.NormalizeSlice was used.
2024-05-18 21:01:34 -05:00
Jack Christensen cf6074fe5c Remove unused anynil.Normalize 2024-05-18 20:37:25 -05:00
Jack Christensen 13beb380f5 Fix encode driver.Valuer on nil-able non-pointers
https://github.com/jackc/pgx/issues/1566
https://github.com/jackc/pgx/issues/1860
https://github.com/jackc/pgx/pull/2019#discussion_r1605806751
2024-05-18 17:17:46 -05:00
Jack Christensen 2a36a7032e Fix encode driver.Valuer on pointer
pgx v5 introduced nil normalization for typed nils. This means that
[]byte(nil) is normalized to nil at the edge of the encoding system.
This simplified encoding logic as nil could be encoded as NULL and type
specific handling was unneeded.

However, database/sql compatibility requires Value to be called on a
nil pointer that implements driver.Valuer. This was broken by
normalizing to nil.

This commit changes the normalization logic to not normalize pointers
that directly implement driver.Valuer to nil. It still normalizes
pointers that implement driver.Valuer through implicit derefence.

e.g.

type T struct{}

func (t *T) Value() (driver.Value, error) {
  return nil, nil
}

type S struct{}

func (s S) Value() (driver.Value, error) {
  return nil, nil
}

(*T)(nil) will not be normalized to nil but (*S)(nil) will be.

https://github.com/jackc/pgx/issues/1566
2024-05-18 07:41:10 -05:00
Jack Christensen f14fb3d692 Replace interface{} with any 2022-04-09 09:12:55 -05:00
Jack Christensen 1cef9075d9 Simply typed nil and driver.Valuer handling
* Convert typed nils to untyped nils at beginning of encoding process.
* Restore v4 json/jsonb null behavior
* Add anynil internal package
2022-03-05 19:53:59 -06:00