Commit Graph

472 Commits (61a0227241b2a0bccfd7be3e11995b3b59ae53ff)

Author SHA1 Message Date
Kostas Stamatakis 61a0227241
simplify test 2024-12-30 23:15:46 +02:00
Kostas Stamatakis 2190a8e0d1
cleanup and add test for json codec 2024-12-30 23:09:19 +02:00
Kostas Stamatakis 6e9fa42fef
fix #2204 2024-12-30 22:54:42 +02:00
Oleksandr Redko 17cd36818c Update comments in generated code to align with Go standards 2024-12-21 20:21:32 +02:00
Jack Christensen 9d851d7c98 Fix integration benchmarks 2024-12-21 08:22:12 -06:00
Ludovico Russo 5c9b565116 fix: #2146
[![Open Source Saturday](https://img.shields.io/badge/%E2%9D%A4%EF%B8%8F-open%20source%20saturday-F64060.svg)](https://www.meetup.com/it-IT/Open-Source-Saturday-Milano/)

Co-authored-by: Alessio Izzo <alessio.izzo86@gmail.com>
2024-10-19 15:43:56 +02:00
Konstantin Grachev 8723855d95
Implement pgtype.UUID.String() 2024-10-09 14:22:10 +03:00
Jack Christensen 3f84e891de
Merge pull request #2142 from jackc/add-xid8
Add xid8 type
2024-10-08 19:04:07 -05:00
Jack Christensen 123b59a57e Ensure planning encodes and scans cannot infinitely recurse
https://github.com/jackc/pgx/issues/2141
2024-10-05 12:20:50 -05:00
Jack Christensen 32a6b1b200 Skip xid8 test on PG < 13 and CRDB 2024-10-05 10:44:13 -05:00
Jack Christensen f0783c6fbe Add xid8 type
https://github.com/jackc/pgx/discussions/2137
2024-10-05 10:16:42 -05:00
Shean de Montigny-Desautels 7803ec3661
Fix pgtype.Timestamp json unmarshal
Add the missing 'Z' at the end of the timestamp string, so it can be
parsed as timestamp in the RFC3339 format.
2024-09-23 18:12:32 -04:00
Jack Christensen e9bd382c51
Merge pull request #2114 from jennifersp/master
add byte length check to uint32
2024-08-26 07:28:47 -05:00
Jack Christensen 603f2337d6
Merge pull request #2113 from mateuszkowalke/master
Add comment for pgtype.Interval struct
2024-08-26 07:28:29 -05:00
jennifersp 73bbced270 add byte length check to uint32 2024-08-23 16:17:07 -07:00
mateuszkowalke 4171f554d4 Add additional info for nullable pgtype types
Additional information warns about using nullable types being
used as parameters to query with Valid set to false.
2024-08-23 15:15:40 +02:00
jennifersp 57fd684068 update struct name 2024-08-22 16:51:42 -07:00
jennifersp 926913ad66 rm bound check 2024-08-21 15:12:36 -07:00
jennifersp b9f77cb1b3 fix typo 2024-08-21 12:27:23 -07:00
jennifersp 218c15a4eb support text scanner for binary format for uint32 2024-08-21 12:04:54 -07:00
Jack Christensen 5747f37d9c Fix: Scan and encode types with underlying types of arrays
Rather than special case the reported issue with UUID and [16]byte, this
commit allows the system to find the underlying type of any type that is
an array.

fixes https://github.com/jackc/pgx/issues/2107
2024-08-15 18:20:07 -05:00
Jack Christensen a68e14fe5a Explicitly disclaim support for time with time zone 2024-07-23 17:27:05 -05:00
nickcruess-soda a8aaa37363 fix(test): skip CockroachDB since it doesn't support XML 2024-07-12 09:56:59 -05:00
nickcruess-soda 37681a4f48 chore: remove unused JSONCodec code, correct typo 2024-07-11 15:18:20 -05:00
nickcruess-soda c7b9dc0e00 feat: add pgtype.XMLCodec based on pgtype.JSONCodec 2024-07-11 15:17:55 -05:00
Nick Farrell b770252a3b
Fix bug relating to reuse of types
When `LoadTypes` is being called, it does not include the
namespace-qualified types in its result. While these namespaces are
visible to `LoadTypes` itself, `RegisterTypes` will not recognise this
form of the types, only allowing them to be used if they are on the
schema path, and referred to without their namespace component.
2024-07-07 11:26:19 +10:00
Nick Farrell 47977703e1
Load types using a single SQL query
When loading even a single type into pgx's type map, multiple SQL
queries are performed in series. Over a slow link, this is not ideal.
Worse, if multiple types are being registered, this is repeated multiple
times.

This commit add LoadTypes, which can retrieve type
mapping information for multiple types in a single SQL call, including
recursive fetching of dependent types.
RegisterTypes performs the second stage of this operation.
2024-07-01 15:34:17 +10:00
Carlos Pérez-Aradros Herce 9f4a264f89 Fix interval encoding to allow 0s and avoid extra spaces
Fix a bugs introduced by 01d649b, also add some tests
2024-05-30 09:48:53 +02:00
Jack Christensen b4911f1da7
Merge pull request #2019 from jackc/fix-encode-driver-valuer-on-pointer
Fix encode driver.Valuer on pointer
2024-05-25 11:20:25 -05:00
Jack Christensen 9ca9203afb Move typed nil handling to Map.Encode from anynil
The new logic checks for any type of nil at the beginning of Encode and
then either treats it as NULL or calls the driver.Valuer method if
appropriate.

This should preserve the existing nil normalization while restoring the
ability to encode nil driver.Valuer values.
2024-05-18 22:39:28 -05:00
Jack Christensen 79cab4640f Only use anynil inside of pgtype 2024-05-18 21:06:23 -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
Mitar 732889728f Add support for custom JSON marshal and unmarshal.
The Codec interface is now implemented by *pgtype.JSONCodec
and *pgtype.JSONBCodec instead of pgtype.JSONCodec and
pgtype.JSONBCodec, respectively. This is technically a breaking
change, but it is extremely unlikely that anyone is depending on this,
and if there is downstream breakage it is trivial to fix.

Fixes #2005.
2024-05-18 08:02:09 -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
Oleksandr Redko c05cce7d41 Fix test asserts: reverse expected-actual 2024-05-14 20:07:10 -05:00
Jack Christensen 48cdd7bab0 Allow scanning time without time zone into string
https://github.com/jackc/pgx/issues/2002
2024-05-10 10:52:41 -05:00
Carlos Pérez-Aradros Herce 01d649b2bf Do not encode interval microseconds when they are 0
This make the encode match what postgres does
2024-05-09 17:29:13 -05:00
Jack Christensen 8649231bb3 Add ScanLocation to pgtype.TimestampCodec
If ScanLocation is set, the timestamps will be assumed to be in the
given location when scanning from the database.

The Codec interface is now implemented by *pgtype.TimestampCodec instead
of pgtype.TimestampCodec. This is technically a breaking change, but it
is extremely unlikely that anyone is depending on this, and if there is
downstream breakage it is trivial to fix.

https://github.com/jackc/pgx/issues/1195
https://github.com/jackc/pgx/issues/1945
2024-05-08 08:35:05 -05:00
Jack Christensen 33360ab479 Add ScanLocation to pgtype.TimestamptzCodec
If ScanLocation is set, it will be used to convert the time to the given
location when scanning from the database.

The Codec interface is now implemented by *pgtype.TimestamptzCodec
instead of pgtype.TimestamptzCodec. This is technically a breaking
change, but it is extremely unlikely that anyone is depending on this,
and if there is downstream breakage it is trivial to fix.

https://github.com/jackc/pgx/issues/1195
https://github.com/jackc/pgx/issues/1945
2024-05-08 08:35:05 -05:00
Oleksandr Redko 60a01d044a Fix typos in doc comments 2024-04-17 12:00:02 -05:00
Felix Röhrich fc416d237a make parsing stricter and add corresponding test 2024-04-16 12:18:06 -05:00
Carlos Pérez-Aradros Herce 78b22c3d2f fix tests 2024-03-20 18:21:11 -05:00
Carlos Pérez-Aradros Herce 221ad1b84c Add support for macaddr8 type
Postgres also has a `macaddr8` type, this PR adds support for it, using
the same codec as `macaddr`
2024-03-20 18:21:11 -05:00
Jack Christensen 88dfc22ae4 Fix simple protocol encoding of json.RawMessage
The underlying type of json.RawMessage is a []byte so to avoid it being
considered binary data we need to handle it specifically. This is done
by registerDefaultPgTypeVariants. In addition, handle json.RawMessage in
the JSONCodec PlanEncode to avoid it being mutated by json.Marshal.

https://github.com/jackc/pgx/issues/1763
2024-03-02 15:12:20 -06:00
David Kurman d149d3fe5c Fix panic in TryFindUnderlyingTypeScanPlan
Check if CanConvert before calling reflect.Value.Convert
2024-02-26 17:51:56 -06:00
Jack Christensen 85f15c4b3c Fix scan float4 into sql.Scanner
https://github.com/jackc/pgx/issues/1911
2024-02-23 18:18:03 -06:00
Jack Christensen 654dcab93e Fix: pgtype.Bits makes copy of data from read buffer
It was taking a reference. This would cause the data to be corrupted by
future reads.

fixes #1909
2024-02-23 17:40:11 -06:00
Jack Christensen 7b5fcac465 Add timetz and []timetz OID constants
https://github.com/jackc/pgx/issues/1883
2024-01-27 18:55:59 -06:00
Florent Viel 0fa533386c add ltree pgtype support 2024-01-26 09:06:13 -06:00
Kirill Malikov 517c654e2c feat: fast encodeUUID 2024-01-20 20:50:01 -06:00