I try to figure out if it is possible to use json ...
# squarelibraries
t
I try to figure out if it is possible to use json function with sqldelight in KMP. I'm using the version 2.2.1, tried different version dialect for sqlite, but still didn't make it work. Does json_each or instr can work ? I tried some stuff like below, but is fail to compile on json_each.
Copy code
trySomething:
SELECT value FROM json_each('[ "a", "b", "c" ]');

trySomethingElse:
SELECT hookEntry.url
FROM hookEntry, json_each(user.urlWhiteList)
WHERE json_each.value LIKE ?;
Thanks.
Just found out, i wasn't using correctly the json module. It needs to be added inside sqldelight plugin. Now It compile without error.
Copy code
sqldelight {
    databases {
        create("Database") {
            packageName = "${kotlin.androidLibrary.namespace}.database"
            srcDirs.setFrom("src/commonMain/sqldelight")
            dialect(
                libs.sql.delight.dialect.get().toString().replace(
                    oldValue = "{{version}}",
                    newValue = libs.versions.sql.delight.dialect.get()
                )
            )
            module(libs.sql.delight.json)   // <--- Here
        }
    }
}
Now stuff like this works 😁
Copy code
trySomething:
SELECT value FROM json_each('[ "a", "b", "c" ]');

trySomething2:
SELECT value, instr(value, 'b') AS position FROM json_each('[ "a", "b", "c" ]');