Could you help me please with SQLDelight?
I use SQLDelight for Kotlin Multiplatform Project (Android + iOS) with SQLite under the hood. SQLite has NUMERIC type for storing high precision values. I need NUMERIC type for storing currency amount, but I can't use this type in SQLDelight for some reasons. How can I store currency amount using SQLDelight?
Виталий Перятин
01/06/2024, 8:01 AM
image.png
d
Derek Ellis
01/06/2024, 4:12 PM
SQLDelight doesn't really deal with SQLite's type affinities. It forces you to choose a storage class directly.
As I understand it, the
NUMERIC
affinity doesn't necessarily offer high precision. A numerical value will be stored with either the
INTEGER
or
REAL
storage classes, or it may otherwise be stored as
TEXT
if you try storing a malformed string representation of a number.
z
Zoltan Demant
01/07/2024, 9:43 AM
Fwiw, when looking into doing the same thing I ended up storing the string representation of a BigDecimal. Might also be worth looking into scaling down the amount so that you can store it as INTEGER.