SQLite JSON Query Limitations
Overview
While SQLite provides basic JSON support through the json()
function, it has several limitations when using the Hysteria ORM's JSON query methods compared to other databases like PostgreSQL or MySQL.
Known Limitations
1. Partial JSON Matching
The following Hysteria ORM methods have limited or no support in SQLite:
whereJson()
with nested objectswhereJson()
with array elements- Complex combinations of
andWhereJson()
andorWhereJson()
2. JSON Containment Operations
These methods are not supported in SQLite:
whereJsonContains()
andWhereJsonContains()
orWhereJsonContains()
whereJsonNotContains()
andWhereJsonNotContains()
orWhereJsonNotContains()
3. Complex JSON Queries
Limited support for:
- Complex combinations of
andWhereJson()
andorWhereJson()
- Multiple
orWhereJson()
conditions - Nested object property filtering with
whereJson()
Working Features
Supported Operations
The following Hysteria ORM JSON methods work correctly in SQLite:
- Basic
whereJson()
with simple objects - Simple
orWhereJson()
combinations whereNotJson()
whereJsonIn()
andwhereJsonNotIn()
- Basic JSON data insertion and retrieval
- Partial JSON object updates
- Bulk JSON operations with simple equality checks
- JSON column selection and null handling
Example of Working vs Non-Working API Usage
Working API Usage
// Basic JSON equality
User.query().whereJson("json", { key: "value" })
// Simple OR combination
User.query()
.whereJson("json", { type: "A" })
.orWhereJson("json", { type: "B" })
// JSON IN operation
User.query().whereJsonIn("json", [{ type: "A" }, { type: "B" }])
Non-Working API Usage
// Nested property filtering (not supported)
User.query().whereJson("json", {
user: { profile: { name: "John" } }
})
// Array element filtering (not supported)
User.query().whereJson("json", {
tags: ["frontend", "typescript"]
})
// JSON containment (not supported)
User.query().whereJsonContains("json", { key: "value" })
Recommendations
- For applications requiring complex JSON querying, consider using PostgreSQL or MySQL
- Keep JSON queries in SQLite simple and focused on exact matches
- Consider denormalizing critical JSON data into separate columns if complex querying is needed
- Use application-level filtering for complex JSON operations when using SQLite
Alternative Approaches
When working with SQLite and JSON data in Hysteria ORM:
- Use simple equality checks with
whereJson()
instead of containment operations - Implement complex JSON filtering in the application layer
- Use
whereJsonIn()
for multiple value checks instead of complex OR conditions - Consider using raw queries for specific JSON operations when necessary
See also: