Skip to content

fix: Deny passing Buffer columns to SQLite JSON helpers#1

Draft
hwisu wants to merge 3 commits intomasterfrom
fix/how-sqlite-dialect-handle-bitarray-in-json
Draft

fix: Deny passing Buffer columns to SQLite JSON helpers#1
hwisu wants to merge 3 commits intomasterfrom
fix/how-sqlite-dialect-handle-bitarray-in-json

Conversation

@hwisu
Copy link
Copy Markdown
Owner

@hwisu hwisu commented Feb 3, 2026

Howdy 🖖,

This PR adds compile-time type checks to SQLite JSON helpers (jsonArrayFrom, jsonObjectFrom, jsonBuildObject) to reject Buffer/Uint8Array columns.

Passing binary values to JSON functions throws SqliteError: JSON cannot hold BLOB values. This change prevents that runtime error by catching it at compile time.

Changes

  • Added HasUint8Array<T> and ObjectHasUint8ArrayProperty<O> type utilities

  • SQLite JSON helpers now return KyselyTypeError when binary columns are detected

  • Error message includes workarounds: eb.cast(column, "text") or sql`hex(column)`

    Example

    // ❌ Compile error - Buffer column detected
    jsonArrayFrom(
      db.selectFrom('person').select(['id', 'data'])  // data: Buffer
    )
    
    // ✅ Works - convert to hex string
    jsonArrayFrom(
      db.selectFrom('person').select([
        'id',
        sql<string>`hex(data)`.as('data_hex')
      ])
    )

@hwisu hwisu force-pushed the fix/how-sqlite-dialect-handle-bitarray-in-json branch 2 times, most recently from ba508a8 to beb2b3b Compare February 4, 2026 05:31
@hwisu hwisu changed the title fix/how-sqlite-dialect-handle-bitarray-in-json fix: how-sqlite-dialect-handle-bitarray-in-json Feb 4, 2026
@hwisu hwisu changed the title fix: how-sqlite-dialect-handle-bitarray-in-json fix: Deny passing Buffer columns to SQLite JSON helpers Feb 4, 2026
@hwisu hwisu force-pushed the fix/how-sqlite-dialect-handle-bitarray-in-json branch from 5b1abd5 to 4babce7 Compare February 4, 2026 05:45
- Added HasUint8Array<T> and ObjectHasUint8ArrayProperty<O> type utilities
- SQLite JSON helpers now return KyselyTypeError when binary columns are detected
- Error message includes workarounds: eb.cast<string>(column, "text") or sql<string>`hex(column)`
@hwisu hwisu force-pushed the fix/how-sqlite-dialect-handle-bitarray-in-json branch from 3b148d7 to d61611b Compare February 26, 2026 05:13
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