Realm Database is the fast, easy to use, and open source alternative to SQLite and Core Data that is popular with hundreds of thousands of developers. Learn what makes it special and how it can be used to build better apps, faster.
5. What is Realm?
1. Native on-device object database
2. Cloud service that allows seamless synchronization and sharing
across devices
6. The failed promise of ubiquitous connectivity
• Even in major cities connectivity is spotty
• Go to the countryside, still many places with no connectivity
• Crises or huge events often takes down connectivity
• Developing countries are the next big market, but there
connectivity is even worse, and bandwidth is expensive
How do you deal with this reality as a developer?
7. Developer experience is key
• A data model that fits seamlessly with the platform and
programming language
• Transparent synchronization that just works
• A conflict resolution model that works both in realtime, and when
users are offline for extended periods of time
17. An Object Database
• Represents an instance of a Realm
database container (can be a file, or in
memory)
• Data internally represented and exposed as
objects
• Relations are linked lists / pointers
• Cross platform
• ACID compliant, performant
18. Native objects map directly to the database
public class Dog extends RealmObject {
private String name;
private int age;
// ... Generated getters and setters ...
}
public class Person extends RealmObject {
@PrimaryKey
private long id;
private String name;
private RealmList<Dog> dogs; // Declare one-to-many relationships
// ... Generated getters and setters ...
}
20. Query across the object graph
// Query using a predicate string
let johnsDogs = realm.objects(Dog.self).filter(”owner.name = 'John'")
// Query using an NSPredicate
let predicate = NSPredicate(format: "color = %@ AND name BEGINSWITH %@", "tan", "B")
let tanDogs = realm.objects(Dog.self).filter(predicate)
// Sort tan dogs with names starting with "B" by name
let sortedDogs = realm.objects(Dog.self).filter("color = 'tan' AND name BEGINSWITH 'B'”)
.sorted(byKeyPath:"name")
21. Easy and safe multi-threading with
transactions
// create new object
let person = Person(name: "Jane")
// add to realm in transaction
try! realm.write {
realm.add(person)
}
23. Objects and queries live-update in response
to changes
// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet
// Persist your data easily
try! realm.write {
let myDog = Dog(name: “Fido”, age: 1)
realm.add(myDog)
}
// Queries are updated in realtime
puppies.count // => 1
25. Bind directly to components for reactive UI
// Observe Results Notifications
notificationToken = results.observe { [weak self] (changes: RealmCollectionChange) in
guard let tableView = self?.tableView else { return }
switch changes {
case .initial:
tableView.reloadData()
case .update(_, let deletions, let insertions, let modifications):
// Query results have changed, so apply them to the UITableView
tableView.beginUpdates()
tableView.insertRows(at: insertions.map({ IndexPath(row: $0, section: 0) }), with: .automatic)
tableView.deleteRows(at: deletions.map({ IndexPath(row: $0, section: 0)}), with: .automatic)
tableView.reloadRows(at: modifications.map({ IndexPath(row: $0, section: 0) }), with: .automatic)
tableView.endUpdates()
case .error(let error):
}
26. Backend integration
§ Event handling
§ Listen and respond to changes from clients
§ Pass along data to other systems or databases
§ Connectors to 3rd party databases
§ Two-way sync to legacy databases
§ Postgres and SQL Server. MongoDB coming!
§ Integrations (via Node.js & .NET SDK)
§ Identical object interface
§ Full database capabilities
§ Apply changes to push data
§ Mobilize legacy APIs
§ An easier way to integrate legacy data with mobile devices
§ Keep complexity in backend
27. Make a synced Realm with one line change
• Instead of a file path, specify a URL pointing to the realm in the cloud.
• Exactly the same as a local realm, but now with background synchronization.
// Create the configuration
SyncUser user = SyncUser.currentUser();
String url = "realms://myinstance.cloud.realm.io/~/userRealm";
SyncConfiguration config = user.createConfiguration(url).build();
// Open the remote Realm
Realm realm = Realm.getInstance(config);
// Any changes made to this Realm will be synced across all devices
29. Digital Transformation Use Case
Food Services Companies
• Real-time Inventory updates at meal purchase
• Reliable (offline) inventory reconciliation (think
“walk-in” fridge)
• Synchronize supply catalog & meal planning
• Automated order submit
Result: Highly Automated Process Flow
30. Digital Transformation Use Case
Flight Management / Reporting
Pilot & Crew focused:
• Crew management:
• Scheduling
• Check-in/out
• Flight tracking
• Fuel, Speed
• Event Logging, Incident tracking
Result: Replacing lots of paperwork!
31. Digital Transformation Use Case
Major Cruise Vacation Company
• Food/Drink orders management:
• Order capture, Bar workflow,
• Fulfillment tracking (Billing)
• Excursion Pre-booking
• Each On-Island ‘Activity’ has their dedicated device with
synced booking info
• Check-in, up-sells synced locally,
• Fulfillment tracking (for Billing)
Result: automated & simplified communication
“Ship-to-shore”
32. Digital Transformation Use Case
National Police Force (Europe)
Realtime empowered Police Force
• Enable Chat & Messaging amongst force
members
• Evidence and Note capture (shared)
• Task sharing, team assignment
• Everything realm-time & offline
Results: (under development)