87 Commits

Author SHA1 Message Date
WGH
e4f72071f8 Document that generic helpers call rows.Close()
Existing generic helpers always call defer rows.Close().
Examples of their usage also omit external defer rows.Close() call.

For clarity, state that explicitly, because that's another point
why one would want to switch to generic helpers from manually written
rows.Next() loop.
2024-05-09 15:54:48 -05:00
Zach Olstein
8f69e45a53 fixup! Cache reflection analysis in RowToStructBy... 2024-04-16 13:08:16 -05:00
Zach Olstein
ec98406207 Cache reflection analysis in RowToStructBy...
Modify the RowToStructByPos/Name functions to store the computed mapping
of columns to struct field locations in a cache to reuse between calls.
Because this computation can be expensive and the same few results will
frequently be reused, caching these results provides a significant
speedup.

For positional mappings, we can key the cache by just the struct-type.
However, for named mappings, the key must include a representation of
the columns, in order, since different columns produce different
mappings.
2024-04-16 13:08:16 -05:00
Felix
c1b0a01ca7 Fix behavior of CollectRows to return empty slice if Rows are empty
https://github.com/jackc/pgx/issues/1924
2024-03-03 07:52:18 -06:00
Edoardo Spadolini
a57bb8caea Add AppendRows helper 2024-01-23 17:14:24 -06:00
Tikhon Fedulov
d2c9ebc2ef Use local variables in fieldPosByName and fix errors 2023-12-25 09:47:10 -06:00
Tikhon Fedulov
0c7acf9481 Add snake_case support to RowToStructByName 2023-12-25 09:47:10 -06:00
Ville Skyttä
c6c50110db Spelling and grammar fixes 2023-10-07 09:26:23 -05:00
Ville Skyttä
24ed0e4257 Make use of strings.Cut 2023-10-04 20:41:55 +03:00
Jack Christensen
c08cc72306 Improve QueryExecModeCacheDescribe and clarify documentation
QueryExecModeCacheDescribe actually is safe even when the schema or
search_path is modified. It may return an error on the first execution
but it should never silently encode or decode a value incorrectly. Add a
test to demonstrate and ensure this behavior.

Update documentation of QueryExecModeCacheDescribe to remove warning of
undetected result decoding errors.

Update documentation of QueryExecModeCacheStatement and
QueryExecModeCacheDescribe to indicate that the first execution of an
invalidated statement may fail.
2023-09-23 10:35:42 -05:00
Mochammad Hanif R
4e7aa59d64 Fix typos in docs 2023-09-23 07:20:36 -05:00
Julien GOTTELAND
389931396e No data result on error 2023-08-19 18:31:41 -05:00
Julien GOTTELAND
9ee7d29cf9 Add CollectExactlyOneRow function 2023-08-19 18:31:41 -05:00
Craig Ringer
a7375cc503 docs: Emphasise need to call rows.Err() after rows.Next() returns false
The Rows interface in pgx, like its ancestor in database/sql, is easy to
accidentally misuse in a way that can cause apps to misinterpret
database or connection errors as successful queries with empty or
truncated result-sets.

Update the docs to emphasise the need to call rows.Err() after
rows.Next() returns false, and direct users of the interface to the v5
API helpers that make writing correct code easier.

The docs on Conn.Query() already call this out, so only a small change
is needed to warn users and point them at the details on Query()

Per details in #1707
2023-08-10 17:19:15 -05:00
Jack Christensen
1a9b2a53a5 Fix staticcheck issues 2023-07-28 18:04:31 -05:00
Jack Christensen
2f6fcf8eb0 RowTo(AddrOf)StructByPos ignores fields with "-" db tag
https://github.com/jackc/pgx/discussions/1682
2023-07-15 09:39:20 -05:00
Jack Christensen
91cba90e8d Fix: RowScanner errors are fatal to Rows
https://github.com/jackc/pgx/issues/1654
2023-06-20 08:48:06 -05:00
Jack Christensen
5f28621394 Add docs clarifying that FieldDescriptions may return nil
https://github.com/jackc/pgx/issues/1634
2023-06-14 07:42:11 -05:00
Jack Christensen
f59e8bf555 Fix: RowToStructByPos with embedded unexported struct
https://github.com/jackc/pgx/issues/1583
2023-04-27 21:03:58 -05:00
Audi P. Risa P
7555c43033 add lax field to namedStructRowScanner 2023-03-25 09:57:38 -05:00
Audi P. Risa P
193bab416f add RowTo(AddrOf)StructByNameLax 2023-03-25 09:57:38 -05:00
Nazar Vovk
24c53259f8 Fix typo 2022-11-28 09:36:20 -06:00
Jack Christensen
2e9e2865f9 Added more docs and tests 2022-11-12 10:13:20 -06:00
Pavlo Golub
14be51536b implement RowToStructByName and RowToAddrOfStructByName 2022-11-12 09:39:54 -06:00
Baptiste Fontaine
3e825ec898 Fix RowToStructByPos on structs with multiple anonymous sub-structs
Fixes #1343
2022-10-22 10:02:32 -05:00
Jack Christensen
6e40968cfc CollectOneRow prefers PostgreSQL error over pgx.ErrorNoRows
fixes https://github.com/jackc/pgx/issues/1334
2022-10-22 08:44:06 -05:00
Jack Christensen
ee2622a8e6 RowToStructByPos supports embedded structs
https://github.com/jackc/pgx/issues/1273#issuecomment-1236966785
2022-09-06 18:32:10 -05:00
Jack Christensen
ae65a8007b Use higher pgconn.FieldDescription with string Name
Instead of using pgproto3.FieldDescription through pgconn and pgx. This
lets the lowest level pgproto3 still be as memory efficient as possible.

https://github.com/jackc/pgx/pull/1281
2022-08-20 10:04:18 -05:00
Jack Christensen
b6f5cbd15e Add Conn to Rows interface
https://github.com/jackc/pgx/issues/1191
2022-07-16 17:56:24 -05:00
Jack Christensen
78875bb95a Add tracing support
Replaces existing logging support. Package tracelog provides adapter for
old style logging.

https://github.com/jackc/pgx/issues/1061
2022-07-16 12:27:10 -05:00
Jack Christensen
759e47dba3 Merge branch 'master' into v5-dev 2022-07-12 07:26:00 -05:00
Jack Christensen
62f0347586 Add CollectOneRow 2022-07-09 16:59:29 -05:00
Jack Christensen
90c2dc6f68 Rename ForEachScannedRow to ForEachRow 2022-07-09 16:47:28 -05:00
Jack Christensen
da192291f7 Add CollectRows and RowTo* functions
Collect functionality was originally developed in pgxutil
2022-07-09 16:39:42 -05:00
Jack Christensen
e7aa76ccf9 SendBatch now uses pipeline mode to prepare and describe statements
Previously, a batch with 10 unique parameterized statements executed
100 times would entail 11 network round trips. 1 for each prepare /
describe and 1 for executing them all. Now pipeline mode is used to
prepare / describe all statements in a single network round trip. So it
would only take 2 round trips.
2022-07-09 09:32:36 -05:00
Jack Christensen
76946fb5a3 Replace QueryFunc with ForEachScannedRow 2022-07-07 20:29:04 -05:00
Jack Christensen
1168b375e4 Expose pgx functionality for manual integration with pgconn
This is primarily useful for using pipeline mode.
2022-07-04 13:29:49 -05:00
Stepan Rabotkin
bfb19cd4f6 feat: add time duration to error query and copy 2022-05-12 19:05:08 -05:00
Jack Christensen
c1495aace0 Add RowScanner interface 2022-04-30 12:49:12 -05:00
Jack Christensen
a89a400b69 Fix documentation for Rows.RawValues and test new behavior 2022-04-30 08:27:57 -05:00
Jack Christensen
f14fb3d692 Replace interface{} with any 2022-04-09 09:12:55 -05:00
Jack Christensen
8e341e20f3 Remove ConnConfig.BuildStatementCache 2022-03-12 09:23:40 -06:00
Jack Christensen
ffc5a692cb Detect unsafe pgtype.DriverBytes usage
Add test for unsafe usage and test for correct usage that ensures driver
memory is actually used.
2022-02-26 20:23:35 -06:00
Jack Christensen
95cbbfe441 Import pgproto3
Also copy in pgmock as an internal package.
2022-02-21 13:22:42 -06:00
Jack Christensen
1f2f239d09 Renamed pgtype.ConnInfo to pgtype.Map 2022-02-21 09:13:09 -06:00
Jack Christensen
bda10b2ec9 Rename pgtype.DataType to pgtype.Type 2022-02-21 09:01:48 -06:00
Jack Christensen
318018504a Merge branch 'master' into v5-dev 2022-02-07 11:22:01 -06:00
djsavvy
9eccdd6a81 Clarify that Values() and Scan() require Next() to have been called on the rows object 2022-02-05 20:06:01 -06:00
Jack Christensen
5ed95dcd1c Expose wrap functions on ConnInfo
- Remove rarely used ScanPlan.Scan arguments
- Plus other refactorings and fixes that fell out of this change.
- Plus rows Scan now handles checking for changed type.
2022-01-22 17:50:19 -06:00
Jack Christensen
2b395f3730 pgtype.DataType.Codec can never be nil 2022-01-22 12:21:16 -06:00