Skip to content

feat(pdo): expose statement rows as a lazy seq (statement-seq)#30

Merged
Chemaclass merged 1 commit into
mainfrom
feat/16-statement-seq
Jun 3, 2026
Merged

feat(pdo): expose statement rows as a lazy seq (statement-seq)#30
Chemaclass merged 1 commit into
mainfrom
feat/16-statement-seq

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

Wraps the intent of PDOStatement::getIterator as pdo/statement-seq: a lazy seq of the statement's remaining rows as maps, fetched one row at a time.

(->> (pdo/query conn "select * from big")
     (pdo/statement-seq)
     (map :name)
     (take 10))   ;; only 10 rows are fetched

Return-shape decision (per #16)

Returning the raw PHP Iterator would force callers into php/->, and an eager vector would just duplicate fetch-all. Instead statement-seq is built on lazy-seq + the existing fetch, so:

  • it is genuinely lazy - (first ...) / (take n ...) only fetch what they consume;

  • rows are keywordised maps via row->map, consistent with fetch/fetch-all (and with a stable FETCH_ASSOC, unlike a raw iterator whose shape depends on the fetch mode).

  • Removed getIterator from the "Not implemented yet" block in src/pdo/statement.phel.

  • Tests: statement-seq-yields-rows-as-maps (full realisation) and statement-seq-is-lazy-first-only-fetches-head (first realises just the head).

  • README API table + CHANGELOG ## [Unreleased] updated.

Polish pass: no refactor needed - composes lazy-seq + fetch + cons, no new state.

composer test green (49 assertions).

Closes #16

@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 e8dd1c4 into main Jun 3, 2026
1 check passed
@Chemaclass Chemaclass deleted the feat/16-statement-seq branch June 3, 2026 05:20
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.

Implement statement iterator wrapper for PDOStatement::getIterator

1 participant