Skip to content

Conversation

@ocean
Copy link
Owner

@ocean ocean commented Jan 20, 2026

Remove automatic list JSON-encoding from encode_param function.

This fixes the datatype mismatch error when using IN clauses with parameterised lists. The issue occurred because lists were being JSON-encoded to strings, causing SQLite to see them as JSON strings instead of individual values.

Key changes:

  • Lists are no longer automatically JSON-encoded in encode_param
  • Ecto's query builder properly expands IN clause parameters at the SQL generation level
  • Ecto dumpers handle JSON encoding for array fields in schemas
  • Raw SQL queries with array fields should pre-encode lists using Jason.encode!

This allows proper IN clause expansion while maintaining support for array fields through schema dumpers and explicit pre-encoding in raw SQL queries.

Updated tests to pre-encode lists when using raw SQL with array fields.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed parameter handling in IN clauses to correctly support list values without unintended encoding.
  • Tests

    • Added comprehensive test coverage for IN clause usage with list and empty list parameters.
    • Updated array and map encoding tests to reflect refined encoding behaviour.

✏️ Tip: You can customize this high-level summary in your review settings.

Remove automatic list JSON-encoding from encode_param function.

This fixes the datatype mismatch error when using IN clauses with parameterized lists.
The issue occurred because lists were being JSON-encoded to strings, causing SQLite
to see them as JSON strings instead of individual values.

Key changes:
- Lists are no longer automatically JSON-encoded in encode_param
- Ecto's query builder properly expands IN clause parameters at the SQL generation level
- Ecto dumpers handle JSON encoding for array fields in schemas
- Raw SQL queries with array fields should pre-encode lists using Jason.encode!

This allows proper IN clause expansion while maintaining support for array fields
through schema dumpers and explicit pre-encoding in raw SQL queries.

Updated tests to pre-encode lists when using raw SQL with array fields.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

Walkthrough

This change removes automatic JSON encoding of lists in query parameters, allowing them to be passed unchanged. Ecto's IN clause expansion and schema field dumpers now handle list encoding appropriately based on context.

Changes

Cohort / File(s) Summary
Query parameter handling
lib/ecto_libsql/query.ex
Removed JSON encoding for lists in encode_param. Lists are now returned unchanged, delegating to Ecto's IN clause expansion and schema dumpers for proper handling.
IN clause validation tests
test/issue_63_in_clause_test.exs
New test module validating IN clause queries with list parameters, including single lists, multiple lists, and empty lists. Verifies correct row matching without JSON encoding.
Type encoding/decoding tests
test/type_loader_dumper_test.exs
Updated assertions to reflect JSON pre-encoding of arrays in raw SQL queries. Tests now verify that arrays are JSON-encoded before insertion and properly decoded when loading from the database.

Possibly related issues

Poem

🐰 No more JSON wrapping for lists so dear,
IN clauses now work without fear!
Ecto expands, the schema knows best,
Lists flow freely through the test. ✨

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarises the main change: removing automatic JSON-encoding of lists from encode_param to fix IN clause datatype mismatches.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/in-clause-json-encoding

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.

@ocean ocean merged commit 241db3a into main Jan 21, 2026
14 checks passed
@ocean ocean deleted the fix/in-clause-json-encoding branch January 21, 2026 07:57
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.

2 participants