Gotta Persist 'Em All: Realm as Replacement for SQLite
-
Upload
siena-aguayo -
Category
Software
-
view
1.748 -
download
2
Transcript of Gotta Persist 'Em All: Realm as Replacement for SQLite
● “embedded mobile database”
Realm
● Core is written in C++
● Available for Android and iOS
● Second most-deployed mobile database in the world
Pros for Realm
● Very responsive team
● Easy to use
● Convenient for creating and storing data on the fly
● Object conversion handled for you
● Faster than SQLite
Cons for Realm
● Have to create with Java on the device
● Still under active development
● Not a lot of content online
● No importing
● Can’t access objects across threads
Missing Features
● Auto-incrementing ids
● Easy migrations (exist, but are painful)
● Compound primary keys
● Notifications on specific data changed
● Null support
● Testing with Robolectric
● Map<K, V> support
Shipping with Existing Database
copy
SQLite: SQLiteAssetHelperRealm: Sample migration app
Shipping with Existing Database
SQLite: dbHelper.getReadableDatabase() ordbHelper.getWritableDatabase()
Realm: Realm.getInstance(context)
An ORM or not?
SQLite>> pragma table_info(pokemon)0|id|INTEGER|1||11|identifier|VARCHAR(79)|1||02|height|INTEGER|1||03|weight|INTEGER|1||0
Javapublic class Pokemon { private int id; private String identifier; private int height; private int weight; // constructor(s), // getters, setters}
Typical ORM usage
Shout-Out to Other ORMs
● greenDAO● Active Android● Sugar ORM● ORMLite (Java)● Cupboard
Michael Pardo’s Android Data talk
Acknowledgments
● Realm: http://realm.io/ ● SQLite db from veekun’s Pokémon repo:
https://github.com/veekun/pokedex