* Don't use prefix import as it breaks in old nodes. This is a one time fix for #3577 because its easy to do. node < v16 is not supported.
* Update docs
* Set default PostgreSQL user to 'postgres' to avoid Deno env access errors
Currently, the pg package defaults the database user to process.env.USER (or USERNAME on Windows).
This causes errors when running in Deno without --allow-env, as environment access is restricted.
This PR changes the default user to 'postgres', so:
- Node.js behavior is unchanged when a user is explicitly provided in config.
- Deno users no longer hit NotCapable errors for environment access.
- Avoids relying on process.env for default values.
Example:
Before:
user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
After:
user: 'postgres', // default user, avoids using process.env
* Prioritize config values over environment variables in ConnectionParameters
Previously, ConnectionParameters would first check process.env for connection settings before using the provided config object. This could cause errors in environments like Deno where environment access is restricted.
This change updates the val function to:
1. Use the value from config if it is defined.
2. Fall back to environment variables only if config does not provide a value.
3. Use default values if neither config nor environment variables are set.
This ensures that explicitly provided configuration values are always respected, avoiding unnecessary errors in restricted environments.
* Wrap NODE_PG_FORCE_NATIVE check in try/catch for Deno compatibility
Replace the `typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined'` check with a try/catch
to safely handle environments like Deno without `--allow-env`.
- Keeps Node.js behavior unchanged.
- Prevents errors when accessing process.env in Deno.
- Preserves lazy loading of the native module.
* Make default database user Deno-safe
Wrap the default database user assignment in a try/catch to prevent errors when environment access is restricted (e.g., in Deno).
- Uses process.env.USER / USERNAME on Node if available
- Falls back to 'postgres' when env access fails or is unavailable
- Maintains code structure and comments
- Ensures Node tests continue to pass while preventing Deno runtime errors
* Fixing checks pass
* Update packages/pg/lib/connection-parameters.js
Co-authored-by: Charmander <~@charmander.me>
* fix(pg): only guard process.env access when forcing native client
---------
Co-authored-by: Charmander <~@charmander.me>
These object-mode rows don’t include a `length`. Dead code since 721cf56eb331bd35243c1425095b98cf09adf814 (“Rows are now associative arrays rather than straight arrays.”)?
* Make active query a private prop
* Make client.queryQueue private (with deprecation)
* Deprecate some legacy features
* Update packages/pg/lib/client.js
Co-authored-by: Charmander <~@charmander.me>
---------
Co-authored-by: Brian Carlson <brian.carlson@getcruise.com>
Co-authored-by: Charmander <~@charmander.me>
* fix(pg-protocol): specify number of result column format codes
Fixes a bug when binary format. We must specify both:
- the number of result column format codes
- the result column format codes
The text format case was working by accident. When using text format, the
intention was to set the format code to 0. Instead, we set the number
of result column format codes was set to 0. This is valid because it indicates
that all result columns should use the default format (text).
When using binary format, the intention was to set the format code to 1.
Instead, we set the number of result column format codes to 1.
Importantly, we never set a result column format code. This caused an
error: 'insufficient data left in message'.
We now always set the number of result column format codes to '1'. The
value of '1' has special meaning:
> or one, in which case the specified format code is applied to all result columns (if any)
We then set a single column format code based on whether the connection
(or query) is set to binary.
Fixes#3487
* fix(pg): use a Buffer when parsing binary
The call to parseArray was not working as expected because the value was
being sent as a string instead of a Buffer. The binary parsers in
pg-types all assume the incoming value is a Buffer.
* change instanceof to isDate
* use both methods to check for valid Date
* add test for PR 2862
* use only isDate(date) in place of instanceof Date
* Extend compatibility of `isDate` use back to Node 8
* Clean up test
---------
Co-authored-by: Charmander <~@charmander.me>
Reviewed-by: Charmander <~@charmander.me>
* Added support for SCRAM-SHA-256-PLUS i.e. channel binding
* Requested tweaks to channel binding
* Additional tweaks to channel binding
* Fixed lint complaints
* Update packages/pg/lib/crypto/sasl.js
Co-authored-by: Charmander <~@charmander.me>
* Update packages/pg/lib/crypto/sasl.js
Co-authored-by: Charmander <~@charmander.me>
* Update packages/pg/lib/client.js
Co-authored-by: Charmander <~@charmander.me>
* Tweaks to channel binding
* Now using homegrown certificate signature algorithm identification
* Update ssl.mdx with channel binding changes
* Allow for config object being undefined when assigning enableChannelBinding
* Fixed a test failing on an updated error message
* Removed - from hash names like SHA-256 for legacy crypto (Node 14 and below)
* Removed packageManager key from package.json
* Added some SASL/channel binding unit tests
* Added a unit test for continueSession to check expected SASL session data
* Modify tests: don't require channel binding (which cannot then work) if not using SSL
---------
Co-authored-by: Charmander <~@charmander.me>
It looks like this was removed in d615ebee177ed57c7a7df861b1db675c9e0ebb0f while it still had references to it.
Reviewed-by: Charmander <~@charmander.me>
* test: Actually test split messages in split message parsing test
* cleanup: Fix spelling in tests
* test: Wait on asynchronous tests
* cleanup: Remove unused parameter from test method `BufferList#getByteLength`
If someone did want this functionality, it would be better to use addition separate from the method anyway.
* cleanup: Remove unused test function `BufferList.concat`
* perf(utils): fast prepareValue
This PR add a performance improvements at prepare Value for non-object by skipping useless condition
* fix: lint
* fix: case of undefined
* fix: review