Skip to content

feat(pdo): add from-connection to wrap an existing PDO#33

Merged
Chemaclass merged 1 commit into
mainfrom
feat/21-from-connection
Jun 3, 2026
Merged

feat(pdo): add from-connection to wrap an existing PDO#33
Chemaclass merged 1 commit into
mainfrom
feat/21-from-connection

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

Adds pdo/from-connection so Phel can reuse a host framework's already-open \PDO (Symfony/Laravel + Doctrine DBAL's getNativeConnection()) instead of opening a second connection:

(def conn (pdo/from-connection php-pdo))
(-> (pdo/query conn "select * from products where id = 1") (pdo/fetch))

Behaviour (per #21):

  • Returns the standard connection value, so every downstream fn (query, prepare, execute, fetch, insert, begin/commit/rollback, with-transaction, ...) works unchanged.

  • Leaves attributes untouched by default - the host owns the connection's configuration. {:apply-defaults true} opts into phel-pdo's ERRMODE_EXCEPTION.

  • Lifecycle: phel-pdo never closes a connection it did not open (the library exposes no close, so a wrapped handle is never closed by it).

  • Tests: wrap a pre-opened in-memory SQLite \PDO and run query/fetch; run a with-transaction; verify default leaves ERRMODE as set by the host (SILENT preserved) and :apply-defaults forces ERRMODE_EXCEPTION.

  • README API table + docs/recipes.md "reuse an existing (framework) connection" section + CHANGELOG updated.

Polish pass: no refactor needed - reuses the connection struct and set-attribute; no duplication.

composer test green (60 assertions).

Closes #21

@Chemaclass Chemaclass added the enhancement New feature or request label Jun 3, 2026
@Chemaclass Chemaclass self-assigned this Jun 3, 2026
@Chemaclass Chemaclass merged commit d447a51 into main Jun 3, 2026
1 check passed
@Chemaclass Chemaclass deleted the feat/21-from-connection branch June 3, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: from-connection to wrap an existing PDO (reuse framework/DBAL connection)

1 participant