sqldelight / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://sqldelight.github.io/sqldelight/
Apache License 2.0
6.18k stars 516 forks source link

Void type generated for WHERE JSON_EXTRACT = ? #4140

Open rougsig opened 1 year ago

rougsig commented 1 year ago

SQLDelight Version

1.5.5

SQLDelight Dialect

mysql

Describe the Bug

My sql file:

CREATE TABLE ImageProcessingParams (
  id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  data JSON NOT NULL
);

search:
SELECT
  id,
  data
FROM
  ImageProcessingParams
WHERE
  JSON_EXTRACT(data, '$.preset_id') = :preset_id;

Queries generated by sqldelight:

import com.squareup.sqldelight.Query
import com.squareup.sqldelight.Transacter
import java.lang.Void
import kotlin.Any
import kotlin.Int
import kotlin.String
import kotlin.Unit

public interface ImageProcessingParamsQueries : Transacter {
  public fun <T : Any> search(preset_id: Void?, mapper: (id: Int, data_: String) -> T): Query<T>

  public fun search(preset_id: Void?): Query<ImageProcessingParams>
}

What's wrong: 1 - preset_id type is java.lang.Void. I think java type was not expected. 2 - It is logical that sqldelight cannot understand the field type in json.\ However, I would like to pass Int value for preset_id param.

Stacktrace

No response

hfhbd commented 1 year ago

As a workaround, use CAST(:preset_id, INT);