Skip to content

fix(adapter-better-sqlite3): infer Bytes for Buffer values - #30913

Open
EnesKartal wants to merge 1 commit into
prisma:v7from
EnesKartal:fix/better-sqlite3-buffer-blob-29868
Open

EnesKartal wants to merge 1 commit into
prisma:v7from
EnesKartal:fix/better-sqlite3-buffer-blob-29868

Conversation

@EnesKartal

@EnesKartal EnesKartal commented Oct 30, 2026 •

Copy link
Copy Markdown

better-sqlite3 returns BLOBs as Buffer, but inferObjectType only accepted ArrayBuffer, so a BLOB in a column with no declared type (for example SELECT X'DEADBEEF') threw UnexpectedTypeError. It now accepts Uint8Array too, which covers Buffer.

Added conversion tests and an adapter test that runs the query from the issue on an in-memory database. They fail without the change. tsc, eslint and prettier are clean for the package. Unrelated: the UniqueConstraintViolation test in errors.test.ts failed before this change too (an extra "table" field in the output).

AI-assisted; I reviewed the change and the test results.

Fixes #29868

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of binary values when their column type is not explicitly declared. These values are now recognized as bytes and returned with their original byte contents, including results from BLOB expressions. Other unsupported object values continue to raise an error.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: prisma/orm
  • Branch: v7
  • File: .coderabbit.yml
  • Commit: 97ea359
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c64704cd-e265-49c6-bcaa-0a052776cc98
Commits

Reviewing files that changed from the base of the PR and between f0ede9e and c73601f.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: prisma/orm
  • Branch: v7
  • File: .coderabbit.yml
  • Commit: 97ea359
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d23ddba7-8001-4e5e-89e9-e2acbdbdb72f
Commits

Reviewing files that changed from the base of the PR and between 97ea359 and f0ede9e.

Files selected for processing: 3
  • packages/adapter-better-sqlite3/src/better-sqlite3.test.ts
  • packages/adapter-better-sqlite3/src/conversion.test.ts
  • packages/adapter-better-sqlite3/src/conversion.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The better-sqlite3 adapter now infers Bytes for Uint8Array values, including Buffer instances. Tests cover conversion behavior and querying a BLOB expression without a declared column type.

Changes: Untyped BLOB inference

Layer / File(s) Summary
Infer and verify byte values
packages/adapter-better-sqlite3/src/conversion.ts, packages/adapter-better-sqlite3/src/conversion.test.ts, packages/adapter-better-sqlite3/src/better-sqlite3.test.ts
inferObjectType recognizes Uint8Array values as bytes. Tests check inference for buffer-like values, rejection of other objects, mapping Buffer values to Uint8Array, and results from an untyped BLOB expression.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: jkomyno

Merge Risk: Minimal · previous review f0ede

Untyped SQLite BLOBs are inferred as bytes. No merge-blocking risk is evident.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the adapter fix: inferring Bytes for Buffer values. This matches the main code and test changes.
Linked Issues check Passed Issue [#29868] requires byte inference for BLOB values returned as Buffer when no declared type exists. inferObjectType now accepts Uint8Array, which includes Buffer, and still accepts `ArrayBuf…
Out of Scope Changes check Passed The changes are limited to the required conversion logic and focused unit and adapter tests. The tests support issue [#29868]. No unrelated production behavior or unrelated files changed.
Full details: Linked Issues check

Explanation

Issue [#29868] requires byte inference for BLOB values returned as Buffer when no declared type exists. inferObjectType now accepts Uint8Array, which includes Buffer, and still accepts ArrayBuffer. The adapter test covers SELECT X'DEADBEEF' AS b and asserts ColumnTypeEnum.Bytes and the expected bytes. Conversion tests cover Buffer, Uint8Array, and ArrayBuffer, and preserve rejection of unrelated objects.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

better-sqlite3 returns BLOBs as Buffer, a Uint8Array subclass, so
inferObjectType threw UnexpectedTypeError for BLOBs from columns with no
declared type (e.g. SELECT X'DEADBEEF').

Fixes prisma#29868

Signed-off-by: EnesKartal <eneskartal117@gmail.com>
@EnesKartal
EnesKartal force-pushed the fix/better-sqlite3-buffer-blob-29868 branch from f0ede9e to c73601f Compare October 30, 2026 10:32

This branch has not been deployed

No deployments
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.

1 participant