Maurice Jouvet
09/28/2020, 9:17 AM// Gradle file
sqldelight {
database("Database") {
dialect = "sqlite:3.24"
packageName = "com.myapp.kmm.database"
}
}
// .sq File
upsert:
INSERT INTO Organization VALUES ?
ON CONFLICT(id) DO
UPDATE SET name=excluded.name, code=excluded.code;
// Error when running the app
E/SQLiteLog: (1) near "ON": syntax error
alec
09/28/2020, 10:42 AMalec
09/28/2020, 10:50 AMalec
09/28/2020, 10:50 AMMaurice Jouvet
09/28/2020, 12:00 PMalec
09/28/2020, 1:05 PMMaurice Jouvet
09/28/2020, 1:06 PMMaurice Jouvet
09/28/2020, 1:07 PMalec
09/28/2020, 1:08 PMMaurice Jouvet
09/28/2020, 1:10 PMMaurice Jouvet
09/28/2020, 1:11 PMTolriq
09/28/2020, 1:24 PMMaurice Jouvet
09/28/2020, 1:28 PMMaurice Jouvet
09/28/2020, 1:28 PMmyanmarking
09/28/2020, 2:53 PMmyanmarking
09/28/2020, 2:54 PMColton Idle
09/29/2020, 4:43 PMMiSikora
09/29/2020, 5:27 PMreadJsonValue()
- https://github.com/square/moshi/blob/bf72ce8ade0db490136834096e0881d17c87e20a/moshi/src/main/java/com/squareup/moshi/JsonReader.java#L525-L526. You read a number which is converted to a double and passed to be read by a delegate as a string.
You need to create a separate adapter that is capable of parsing doubles that will be strings and annotate properties that are of interest. I’m not sure what you expect from @ToJson
, so I left it as is.
@Retention(RUNTIME)
@Target(VALUE_PARAMETER, FUNCTION)
annotation class NumberString
object NumberStringAdapter {
@ToJson fun toJson(@NumberString number: String): String {
return number
}
@FromJson @NumberString fun fromJson(number: String): String {
return number.toDoubleOrNull()?.toLong()?.toString() ?: number
}
}
Colton Idle
09/29/2020, 5:55 PMDefaultIfNullFactory
?MiSikora
09/29/2020, 5:55 PMZach Klippenstein (he/him) [MOD]
09/29/2020, 6:01 PMColton Idle
09/29/2020, 6:12 PMColton Idle
09/29/2020, 6:13 PMMiSikora
09/29/2020, 6:19 PMreadFromJson()
, check for doubles and convert them to strings in a long format but you can lose information this way on some of the actual doubles and generally seems like a bad idea. Using a separate adapter for this type of conversion seems correct. That’s basically main purpose of custom annotations in MoshiColton Idle
09/29/2020, 11:59 PMMiSikora
09/30/2020, 6:11 AMColton Idle
09/30/2020, 3:51 PMMiSikora
09/30/2020, 4:04 PM@NumberString
in order to make sure that it will be parsed differently than to rely on some magic inside a different adapter that will act on all of the numbers.Colton Idle
09/30/2020, 11:05 PMPablo
10/03/2020, 8:20 AM