You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
edit: so in sqldelight 2.0.0-alpha05 this seems to work 😀
incrementCount:
UPDATE test
SET json_attrs = json_set(json_attrs, '$.count', CAST(:count ASINTEGER)); -- 👈 CAST works
I was playing around with json1 extension in sqldelight and I couldn't find a way to specify the type on a json_set (nor its friends) -- it seems to always expect a string in the generated code (i guess because the column is of type TEXT), .. which seems fair because afaik sqldelight cant possibly know what json structure we would input -- so i figured i could try to cast the input parameter CAST(:param AS INTEGER) nor INTEGER(:param) gives compiler error.
I could get around this by just .toString() and .toLong() in app code but it feels like it would be preferred if those casts existed in the .sq files.
Given the json payload {"count": 0}, I'd like to update the count key's value as an integer but the generated code
always expects a string.
Or am I doing something wrong?
dialect: app.cash.sqldelight:sqlite-3-38-dialect
sqldelight: 2.0.0-alpha04
CREATETABLEtest (
json_attrs TEXTNOT NULL
);
insert:
INSERT INTO test VALUES (?);
incrementCount:
UPDATE test
SET json_attrs = json_set(json_attrs, '$.count', :count); -- if I cast count it wont compile 👇
INTEGER(:param)
Execution failed for task ':generateMainTestDbInterface'.
> A failure occurred while executing app.cash.sqldelight.gradle.SqlDelightTask$GenerateInterfaces> Failed to compile SqliteUpdateStmtLimitedImpl(UPDATE_STMT_LIMITED): [] :
UPDATE test
SET json_attrs = json_set(json_attrs, '$.count', INTEGER(:count))
CAST(:param AS INTEGER)
Compiling with dialect app.cash.sqldelight.dialects.sqlite_3_38.SqliteDialect
/Users/sphrak/dev/sqldelight-test/src/main/sqldelight/com/example/test.sq: (10, 53): ')', <binary like operator real>, AS, BETWEEN or IN expected, got 'as'
09 UPDATE test
10 SET json_attrs = json_set(json_attrs, '$.count', CAST(:count as INTEGER))
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
edit: so in sqldelight 2.0.0-alpha05 this seems to work 😀
I was playing around with json1 extension in sqldelight and I couldn't find a way to specify the type on a
json_set
(nor its friends) -- it seems to always expect a string in the generated code (i guess because the column is of type TEXT), .. which seems fair because afaik sqldelight cant possibly know what json structure we would input -- so i figured i could try to cast the input parameterCAST(:param AS INTEGER)
norINTEGER(:param)
gives compiler error.I could get around this by just
.toString()
and.toLong()
in app code but it feels like it would be preferred if those casts existed in the.sq
files.Given the json payload
{"count": 0}
, I'd like to update thecount
key's value as an integer but the generated codealways expects a string.
Or am I doing something wrong?
INTEGER(:param)
CAST(:param AS INTEGER)
Beta Was this translation helpful? Give feedback.
All reactions