Presented this talk at DevFest Ahmedabad 2015 (#DevFestAhm). In this talk I have covered what is Realm? Why you should use Realm over SQLite and ORM with code snippets.
slow ▷ Not entirely SQL free, still need to write queries for certain task ▷ And as underlying is SQLite all the issues with database scaling. ORM Bad Part
Cursor cursor = sqliteDB.rawQuery("SELECT bookTitle FROM " + tableName, null); // if Cursor contains results if (cursor != null) { // move cursor to first row if (cursor.moveToFirst()) { do { // Get version from Cursor String bookName = cursor.getString(cursor.getColumnIndex("bookTitle")); } while (cursor.moveToNext()); } } What is Zero Copy
= new Person() //call setter to set data …. //save data try{ realm.beginTransaction(); realm.copyToRealm(person); realm.commitTransaction(); }catch(Exception e){ realm.cancelTransaction(); // rollback data }
public void execute(Realm realm) { Person person = realm.createObject(Person.class); person.setName("John"); person.setEmail("[email protected]"); } });
int, long, boolean etc. ▷ Supports Box types like Integer, Long, String etc. ▷ Allows null value for non primitives types ▷ Supports Indexing Realm Object
RealmQuery<User> query = realm.where(User.class); // Add query conditions: query.equalTo("name", "John"); query.or().equalTo("name", "Peter"); // Execute the query: RealmResults<User> result1 = query.findAll(); // Or alternatively do the same all at once (the "Fluent interface"): RealmResults<User> result2 = realm.where(User.class) .equalTo("name", "John") .or() .equalTo("name", "Peter") .findAll();
class Email extends RealmObject { private String address; private boolean active; // ... setters and getters left out } public class Contact extends RealmObject { private String name; private Email email; // ... setters and getters left out }
for database change like CP ▷ Encryption support in built ▷ Adapters for binding data with views ▷ Cross Platform, same data can work across iOS and Android ▷ Robust 3rd parties addons Other Features
No support for auto incrementing primary keys ▷ Closed source code ▷ Mutable, thread-confined objects ▷ No support for realm objects across threads ▷ Slower write ▷ Increase method count and size of apk Limitations
released these awesome resources for free: ▷ Realm by realm.io ▷ Christian Melchior from Realm Team ▷ Pranay Airan from GDG BlrDroid ▷ Presentation template by SlidesCarnival