How to preload Room Database with prepackaged DB ๐
Why use Room?
1. It is annotation-driven. ๐

2. It's easy to configure. ๐น
3. There is less code to write. โ๏ธ
4. No need to worry about threading. ๐งถ
5. It has Rx support and co-routine support. ๐
6. It's very easy to unit test. ๐งช
7. You can use room to preload DB from a file ๐

8. There is real-time editing via database inspector on Android Studio. ๐
TODOโs Before Preloading Table with Prepackaged database
When preloading data onto DB:
- Room will do an integrity check before loading the tables with contents.
- Ensure youโre following the rules below:
1. Data types are supported โ
The data type should match supported SqlLite types:
NULL: The value is a NULL value.
INTEGER: The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
REAL: The value is a floating-point value, stored as an 8-byte IEEE floating-point number.
TEXT: The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
BLOB: The value is a blob of data, stored exactly as it was input.
2. Column count & names match โ
What may seem obvious to some is not to others. One canโt add/remove columns without a migration even when preloading data for the first time.
3. Verify the validity โ
When opening the database Room will check the integrity of your table using RoomOpenHelper.java class.

Notice within the method checkIdentity()

Ensures proper usage. If any one of the above rules is not met, then it will throw the following exception:

Thanks & Happy Coding !!