I have a pre-existing sqlite database, the date time is saved as ticks so the sqlite column is bigint. How would I create a roomdb entity for that?
I tried using Long in RoomDb but it shows as INTEGER when I generated a database, Also tried using a converter to Long to DateTime but it still store as integer.
I tried using Long in RoomDb but it shows as INTEGER when I generated a database, Also tried using a converter to Long to DateTime but it still store as integer.
That is correct Long (kotlin) would be stored in a column with an SQLite type of INTEGER, which can hold a 63 bit signed integer value.
Although in SQLite the column type is highly flexible (in most situations any type of value can be stored in any type of column) Room requires a much stricter column type limited to
A TypeConverter is only required if a field in an @Entity
annotated class is not catetered for directly (Room caters for the above) such as other objects (e.g. Date).
If you have a pre-existing database then it may well have to be converted to suit Room's expectattions.
You mention BIGINT as a type. Room will not accept this. The column type would have to be changed to INTEGER. The conversion of the column types (and importantly constraints such as NOT NULL) MUST match Room's expectations.
The simplest way to ascertain Room's expectations is to
@Entity
annotated classes.@Database
's entities
parameter.@Database
annotated class.The database may, certainly in the case of using BIGINT as a column type, need to be converted. This could be prior to including the database file as an asset, or could be via the prepackageddatabase callback.