REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes...
Transcript of REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes...
![Page 1: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/1.jpg)
REALM.IO NOSQL FOR MOBILE
![Page 2: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/2.jpg)
Mitchell Tilbrook▸ Twitter: @sir_tilbrook▸ Mobile Engineer @ Seatfrog▸ Android, iOS, Xamarin
▸ Recording & Editing for 7+ meet-ups▸ ANZCoders: https://www.youtube.com/c/
ANZCoders▸ Android Sydney: http://bit.ly/2dvqk2t
![Page 3: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/3.jpg)
WHY?
![Page 4: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/4.jpg)
1. Not always FAST2. Threading is hard
3. Writes can block reads4. Stringly typed schema
5. Object Mapping6. Migrations
![Page 5: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/5.jpg)
![Page 6: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/6.jpg)
DATA MODELS
![Page 7: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/7.jpg)
ANDROID MODELSpublic class Person extends RealmObject { private String name; private int age;
// Getters and Setters}
OR
![Page 8: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/8.jpg)
ANDROID INTERFACE MODELS@RealmClasspublic class Person implements RealmModel { private String name; private int age;
// Getters and Setters …}
// with RealmObjectperson.isValid();// With RealmModelRealmObject.isValid(user);
![Page 9: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/9.jpg)
PROPERTY ATTRIBUTES
![Page 10: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/10.jpg)
ANDROID PRIMARY KEYpublic class Person extends RealmObject { @PrimaryKey private int id; private String name; private Int age;
// Getters and Setters}
![Page 11: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/11.jpg)
REQUIREDpublic class Person extends RealmObject { @Required private String name; @Required private Int age;
// Getters and Setters}
![Page 12: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/12.jpg)
INDEXINGpublic class Person extends RealmObject { @Index private String name; private int age;
// Getters and Setters}
![Page 13: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/13.jpg)
DON'T PERSIST PROPERTIESpublic class User extends RealmObject { private String email; @Ignore private String sessionToken;
// Getters and Setters}
![Page 14: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/14.jpg)
CUSTOM MODEL LOGICpublic class Person extends RealmObject { private String name; private int age;
public String getName() { return name.toUpperCase(); }
public String getNameAndAge() { return name + " is " + age + " old"; }
public void setName(String newName) { name = newName.toUpperCase(); }}
![Page 15: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/15.jpg)
QUERYING// Gets All the Users RealmQuery<Person> query = realm.where(Person.class);
![Page 16: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/16.jpg)
QUERYING// Gets All the Users RealmQuery<Person> query = realm.where(Person.class);
// Add query conditions:query.equalTo("name", "John");query.or().equalTo("name", "Peter");
// Execute the query:RealmResults<Person> result1 = query.findAll();
// Or alternatively do the same all at once (the "Fluent interface"):RealmResults<Person> result2 = realm.where(Person.class) .equalTo("name", "John") .or() .equalTo("name", "Peter") .findAll();
![Page 17: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/17.jpg)
MANY-TO-ONEpublic class Person extends RealmObject { // .... private Dog dog;
// Getters and Setters }
![Page 18: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/18.jpg)
MANY-TO-MANYpublic class Person extends RealmObject { // .... private RealmList<Dog> dogs;
// Getters and Setters }
![Page 19: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/19.jpg)
RECURSIVE RELATIONSHIPSpublic class Person extends RealmObject { public String name; public RealmList<Person> friends; // Other fields…}
public class Person extends RealmObject { public String name; public Person father; // Other fields…}
![Page 20: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/20.jpg)
LINKED QUERIESpublic class Person extends RealmObject { private String id; private String name; private RealmList<Dog> dogs; // getters and setters}
public class Dog extends RealmObject { private String id; private String name; private String color; // getters and setters}
![Page 21: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/21.jpg)
LINKED QUERIES
![Page 22: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/22.jpg)
LINKED QUERIESRealmResults<Person> persons = realm .where(Person.class) .equalTo("dogs.color", "Brown") .findAll();
![Page 23: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/23.jpg)
QUERYING IS LAZYRealmResults<Person> result = realm .where(Person.class) .findAll();
![Page 24: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/24.jpg)
READING LAZY DATAPerson person = results.get(1);
String name = person.getName();
![Page 25: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/25.jpg)
ASYNC QUERYINGprivate RealmChangeListener callback = new RealmChangeListener() { @Override public void onChange(RealmResults<Person> results) { // called once the query complete and on every update }};
public void onStart() { RealmResults<Person> result = realm.where(Person.class).findAllAsync(); result.addChangeListener(callback);}
![Page 26: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/26.jpg)
AUTO UPDATINGRealmResults<Person> peoples = realm.where(Person.class).findAll();peoples.size(); // => 0
addRandomPerson();
peoples.addChangeListener( results -> { // results and peoples point are both up to date results.size(); // => 1 peoples.size(); // => 1});
![Page 27: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/27.jpg)
CHANGE EVENTS BUBBLERealmResults<Person> peoples = realm.where(Person.class).findAll();
peoples.addChangeListener( results -> { /* ... */ } );
realm.addChangeListener( results -> { /* ... */ } );
![Page 28: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/28.jpg)
FINE GRAIN CHANGE LISTENERS
![Page 29: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/29.jpg)
SAVING UNMANAGED OBJECTSPerson obj = new Person();obj.setId(42);obj.setName("Fish");
// Obtain a Realm instanceRealm realm = Realm.getDefaultInstance();// Save to diskrealm.beginTransaction();managedPerson = realm.copyToRealmOrUpdate(obj);realm.commitTransaction();
![Page 30: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/30.jpg)
SAVING MANAGED OBJECTS// Obtain a Realm instanceRealm realm = Realm.getDefaultInstance();realm.beginTransaction();Person person = realm.createObject(Person.class);person.setName("Mitchell");person.setAge(27);realm.commitTransaction();
![Page 31: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/31.jpg)
ROLLBACK FAILED TRANSACTIONStry { realm.beginTransaction(); Person person = realm.createObject(Person.class); person.setName("Mitchell"); person.setAge(27); realm.commitTransaction();} catch(Exception ex) { // Rollback realm.cancelTransaction();}
![Page 32: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/32.jpg)
RECOMMENDED TRANSACTION STYLEouterRealm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { Person person = realm.createObject(Person.class); person.setName("Mitchell"); person.setAge(27); }});
![Page 33: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/33.jpg)
ASYNCHRONOUS TRANSACTIONSrealm.executeTransactionAsync({ // ...}, new Realm.Transaction.OnSuccess() { @Override public void onSuccess() { // Transaction was a success. }}, new Realm.Transaction.OnError() { @Override public void onError(Throwable error) { // Transaction failed and was automatically canceled. }});
![Page 34: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/34.jpg)
DELETE TRANSACTIONSrealm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { person.getDog().deleteFromRealm(); person.deleteFromRealm(); }});
![Page 35: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/35.jpg)
AGGREGATIONRealmResults<User> results = realm.where(User.class).findAll();long sum = results.sum("age").longValue();long min = results.min("age").longValue();long max = results.max("age").longValue();double average = results.average("age");
long matches = results.size();
![Page 36: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/36.jpg)
![Page 37: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/37.jpg)
ENCRYPTION// Totally not safe keyval key = new byte[64];new SecureRandom().nextBytes(key);val config = new RealmConfiguration.Builder() .encryptionKey(key) .build();
// Open the Realm with encryption enabledval realm = Realm.getInstance(config);
![Page 38: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/38.jpg)
DATA MIGRATIONS
![Page 39: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/39.jpg)
JUST DELETE ITRealmConfiguration config = new RealmConfiguration.Builder() .deleteRealmIfMigrationNeeded() .build()
![Page 40: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/40.jpg)
MIGRATIONSRealmConfiguration config = new RealmConfiguration.Builder() .schemaVersion(2) // Must be bumped when the schema changes .migration(new MyMigration()) // Migration to run instead of throwing an exception .build()
![Page 41: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/41.jpg)
MIGRATIONSRealmMigration migration = new RealmMigration() { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { RealmSchema schema = realm.getSchema();
if (oldVersion == 0) { schema.create("Person") .addField("name", String.class) .addField("age", int.class); oldVersion++; }
if (oldVersion == 1) { schema.get("Person") .addField("id", long.class, FieldAttribute.PRIMARY_KEY) .addRealmObjectField("favoriteDog", schema.get("Dog")) .addRealmListField("dogs", schema.get("Dog")); oldVersion++; } }}
![Page 42: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/42.jpg)
REALM SETUP
![Page 43: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/43.jpg)
ANDROID SETUPbuildscript { repositories { jcenter() } dependencies { classpath "io.realm:realm-gradle-plugin:2.0.0" }}
apply plugin: 'realm-android'
![Page 44: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/44.jpg)
ANDROID INITpublic class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Realm.init(this); RealmConfiguration config = new RealmConfiguration.Builder() .build(); Realm.setDefaultConfiguration(config) }}
![Page 45: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/45.jpg)
SWIFT & OBJECTIVE-C▸ https://realm.io/docs/swift/latest/#installation▸ https://realm.io/docs/objc/latest/#installation
![Page 46: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/46.jpg)
REALM BROWSER
![Page 47: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/47.jpg)
![Page 48: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/48.jpg)
REALM MOBILE PLATFORM
![Page 49: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/49.jpg)
REALM USER SEGREGATION
![Page 50: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/50.jpg)
DRAWBACKS▸ Thread confined*▸ Large binary
▸ Connections need to be closed
![Page 51: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/51.jpg)
ANDROID SIZE COST
![Page 52: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/52.jpg)
IOS SIZE COST
![Page 53: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/53.jpg)
INSPECT REALM ON ANDROID
Realm.init(this);
Stetho.initialize( Stetho.newInitializerBuilder(this) .enableDumpapp( Stetho.defaultDumperPluginsProvider(this) ) .enableWebKitInspector( RealmInspectorModulesProvider .builder(this) .build() ) .build());
![Page 54: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/54.jpg)
ANDROID LIBRARY INTEGRATIONS▸ JSON ( GSON, Moshi )
▸ RxJava▸ Retrofit
![Page 55: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/55.jpg)
RXJAVA SUPPORTrealm.where(Person.class) .findAllAsync() .asObservable();
![Page 56: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/56.jpg)
RXJAVA REALM SCHEDULERfun Schedulers.newRealmThread(): Scheduler { val backgroundThread = HandlerThread( "RxRealm-BackgroundThread", THREAD_PRIORITY_BACKGROUND ) backgroundThread.start() val backgroundLooper = backgroundThread.looper return AndroidSchedulers.from(backgroundLooper)}
compile "io.reactivex:rxandroid:$rx_android_version"
![Page 57: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/57.jpg)
PRODUCTION READY?
![Page 58: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/58.jpg)
![Page 59: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/59.jpg)
YES
![Page 60: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/60.jpg)
QUESTIONS?
![Page 61: REALM.IO NOSQL FOR MOBILE - YOW! Conferences · 1. Not always FAST 2. Threading is hard 3. Writes can block reads 4. Stringly typed schema 5. Object Mapping 6. Migrations](https://reader033.fdocuments.us/reader033/viewer/2022060307/5f09b6a57e708231d4282932/html5/thumbnails/61.jpg)
Mitchell Tilbrook ! @SIR_TILBROOK " GITHUB.COM/MARUKAMI