Commit Graph

15 Commits (12c49ee213fabc092f24b92db6874ed0d319d7b3)

Author SHA1 Message Date
Jack Christensen 12c49ee213 shopspring-numeric extension does not panic on NaN
https://github.com/jackc/pgtype/issues/169
2022-06-23 21:01:56 -05:00
Eli Treuherz db84905b7f Add NullDecimal to shopspring-numeric
The shopspring/decimal package provides a NullDecimal struct intended
for use with nullable SQL NUMERICs and numbers. It has Scanner and
Valuer implementations already, but adding it to this package allows
it to be used with the binary encoding as well.

The implementation is very straightforward, but the tests have been made
slightly more complicated. The previous version wasn't testing the
decimal.Decimal cases, and this change adds those as well as new
NullDecimal cases. I've added some logic to the test harness to catch
these as you need to use the Equals method to properly compare Decimals.
2021-08-07 08:23:02 -05:00
Jack Christensen dd160540c4 Use Go 1.13 errors instead of xerrors 2021-03-25 09:08:27 -04:00
Jack Christensen e6c6de9494 Improved ext/shopspring-numeric binary decoding performance
Before:
BenchmarkDecode/Zero-Binary-16       	 3944304	       292 ns/op	     128 B/op	       7 allocs/op
BenchmarkDecode/Small-Binary-16      	 2034132	       585 ns/op	     184 B/op	      13 allocs/op
BenchmarkDecode/Medium-Binary-16     	 1747191	       690 ns/op	     192 B/op	      12 allocs/op
BenchmarkDecode/Large-Binary-16      	 1334006	       899 ns/op	     304 B/op	      14 allocs/op
BenchmarkDecode/Huge-Binary-16       	  702382	      1590 ns/op	     584 B/op	      18 allocs/op

After:
BenchmarkDecode/Zero-Binary-16       	14592645	        80.1 ns/op	      64 B/op	       2 allocs/op
BenchmarkDecode/Small-Binary-16      	 5729318	       212 ns/op	     104 B/op	       7 allocs/op
BenchmarkDecode/Medium-Binary-16     	 4930009	       241 ns/op	      88 B/op	       5 allocs/op
BenchmarkDecode/Large-Binary-16      	 3369573	       344 ns/op	     144 B/op	       7 allocs/op
BenchmarkDecode/Huge-Binary-16       	 2587156	       453 ns/op	     216 B/op	       9 allocs/op
2020-05-02 11:34:14 -05:00
Jack Christensen 55a56add23 Set will call Get on src if possible 2020-02-19 11:58:49 -06:00
Jack Christensen f3816bd1c0 Get implemented on T instead of *T
Methods defined on T are also available on *T. Thought this technically
changes the interface, because *T will be automatically dereferenced as
needed it shouldn't be a breaking change.

See a8802b16cc for similar change.
2020-02-19 10:48:09 -06:00
Jack Christensen cf87e34792 Add JSON to shopspring-numeric extension 2020-01-24 17:07:41 -06:00
Jack Christensen a8802b16cc Value, EncodeBinary, EncodeText, and MarshalJSON on T instead of *T
Methods defined on T are also available on *T. This change makes Value
consistent with database/sql Value implementations. It also makes Value,
EncodeBinary, and EncodeText more convenient to use because you can
pass T or *T as an argument to a query.

The MarshalJSON change is even more significant because without it
json.Marshal would generate the "%v" format instead of the implemented
MarshalJSON.

Thought this technically changes the interface, because *T will be
automatically dereferenced as needed it shouldn't be a breaking change.

See: https://github.com/jackc/pgx/issues/538 for initial discussion.
2019-08-27 20:46:16 -05:00
Jack Christensen 4ed0de4755 Splitting pgtype into own repo 2019-04-20 19:14:08 -05:00
Jack Christensen f25878662d Use golang.org/x/xerrors 2019-04-20 17:43:44 -05:00
Jack Christensen 8502a12ac7 Fix go modules
Wow. This is fun. Sure is easy to get modules wrong when upgrading a v2+
project.
2019-04-20 17:41:08 -05:00
Jack Christensen 4e79a104f7 Test domains when registered and unregistered
Fix bug assigning to unknown type.
2019-04-13 17:09:51 -05:00
Jack Christensen a5f166bd21 Use github.com/pkg/errors 2017-06-04 21:30:03 -05:00
Jack Christensen 6b906ca870 Refactor pgio and types to append buffers 2017-05-02 20:38:26 -05:00
Jack Christensen b49035fdc1 Add shopspring.Numeric
This adds PostgreSQL numeric mapping to and from
github.com/shopspring/decimal.

Makes pgtype.NullAssignTo public as external types need this functionality.

Begin extraction of pgtype testing functionality so it can easily be used by
external types.
2017-04-14 12:24:44 -05:00