prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
583 stars 61 forks source link

fix(mariadb): json gt/gte/lt/lte comparisons #315

Closed Weakky closed 3 years ago

Weakky commented 3 years ago

Overview

Follow-up PR to https://github.com/prisma/quaint/pull/311

It turns out CAST(? as JSON) is not supported by MariaDB. We work around this limitation by no longer rendering a JSON value compared to JSON_EXTRACT() as JSON, but as its parsed type.

As a result though, it is no longer possible to perform numeric comparisons with JSON_EXTRACT() as the left/right and a JSON value as the left/right member that's NOT a number or a string.

Examples

SELECT ... FROM ... WHERE
- JSON_EXTRACT(?, ?) > CAST("1" AS JSON)
+ JSON_EXTRACT(?, ?) > 1
SELECT ... FROM ... WHERE
- JSON_EXTRACT(?, ?) > CAST('"hello"' AS JSON)
+ JSON_EXTRACT(?, ?) > "hello"

Additional notes

Since we added MySQL8 and MariaDB to the list of tested databases, some failing tests have appeared. I created an issue to track this: https://github.com/prisma/quaint/issues/318