Skip to content

feat(adapter-pg): accept connection string URL in PrismaPg constructor#29287

Merged
jacek-prisma merged 2 commits intoprisma:mainfrom
Not-Sarthak:fix/adapter-pg-connection-string-error
Mar 17, 2026
Merged

feat(adapter-pg): accept connection string URL in PrismaPg constructor#29287
jacek-prisma merged 2 commits intoprisma:mainfrom
Not-Sarthak:fix/adapter-pg-connection-string-error

Conversation

@Not-Sarthak
Copy link
Copy Markdown
Contributor

@Not-Sarthak Not-Sarthak commented Mar 2, 2026

Summary

  • Adds support for passing a raw connection string URL directly to PrismaPg (e.g., new PrismaPg(process.env.DATABASE_URL))
  • The constructor now accepts pg.Pool | pg.PoolConfig | string, converting strings to { connectionString: string } internally
  • This is a convenience feature — pg.PoolConfig already supports { connectionString: '...' }, but accepting a plain string is more ergonomic

Related: #29151

Test plan

  • Added unit test verifying PrismaPgAdapterFactory accepts a connection string URL and creates a working adapter
  • All existing adapter-pg tests pass (36/36)
  • Lint passes with no new warnings

Note: The CodSpeed regression (compile findUnique -97.77%) is unrelated — this PR only touches adapter-pg constructor logic, not query compilation.

…uctor

When a raw connection string URL is passed to `new PrismaPg(url)` instead
of a Pool instance or config object, it was being treated as a PoolConfig
object, causing `TypeError: Cannot use 'in' operator to search for
'password' in postgresql://...` at query time.

Now accepts `string` as a valid first argument and converts it to
`{ connectionString: string }` for pg.Pool.

Fixes prisma#29151
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 2, 2026

Walkthrough

PrismaPgAdapterFactory constructor now accepts a connection string (string) in addition to pg.Pool and pg.PoolConfig. If given a string, the constructor builds a PoolConfig with connectionString. A test was added to verify the connection-string initialization path.

Changes

Cohort / File(s) Summary
Constructor & runtime behavior
packages/adapter-pg/src/pg.ts
Constructor signature changed to accept `pg.Pool
Tests
packages/adapter-pg/src/__tests__/pg.test.ts
Added test "should accept a connection string URL" that constructs the factory with a connection string, asserts internal config contains connectionString, calls connect() and verifies the adapter/driver options include the same connection string, then disposes the adapter.

Possibly related issues

  • Issue #29151 — Reported error when initializing the adapter with a connection string; this change enables that initialization path.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully implements the required fix by extending the PrismaPgAdapterFactory constructor to accept string connection strings and normalizing them to PoolConfig format, directly resolving issue #29151.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the stated objective: extending constructor type signature, adding string handling logic, and including a unit test to validate the new functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: extending PrismaPgAdapterFactory constructor to accept connection string URLs alongside existing Pool and PoolConfig options.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6738298 and 0d9af9f.

📒 Files selected for processing (2)
  • packages/adapter-pg/src/__tests__/pg.test.ts
  • packages/adapter-pg/src/pg.ts

Comment thread packages/adapter-pg/src/__tests__/pg.test.ts
Comment thread packages/adapter-pg/src/__tests__/pg.test.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d9af9f and 1f0b6e3.

📒 Files selected for processing (1)
  • packages/adapter-pg/src/__tests__/pg.test.ts

Comment thread packages/adapter-pg/src/__tests__/pg.test.ts
@jacek-prisma
Copy link
Copy Markdown
Contributor

I think the original issue was linked to missing Typescript typings (which has already been resolved on main), see #29151 (comment), which means this is no longer a bug fix, although this change could be merged as a new feature.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 3, 2026

Merging this PR will degrade performance by 97.77%

❌ 1 regressed benchmark
✅ 16 untouched benchmarks
⏩ 30 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
compile findUnique (uncached baseline) 929.9 µs 41,789.7 µs -97.77%

Comparing Not-Sarthak:fix/adapter-pg-connection-string-error (1f0b6e3) with main (6738298)

Open in CodSpeed

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Not-Sarthak Not-Sarthak changed the title fix(adapter-pg): handle connection string argument in PrismaPg constructor feat(adapter-pg): accept connection string URL in PrismaPg constructor Mar 3, 2026
@Not-Sarthak
Copy link
Copy Markdown
Contributor Author

Not-Sarthak commented Mar 3, 2026

I think the original issue was linked to missing Typescript typings (which has already been resolved on main), see #29151 (comment), which means this is no longer a bug fix, although this change could be merged as a new feature.

Thanks for the context! updated the PR title, please lmk if there's anything i am missing

@jacek-prisma jacek-prisma merged commit e97b3e0 into prisma:main Mar 17, 2026
493 of 499 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants