Realm

Realm is a mobile database: a replacement for SQLite & Core Data
Realm can save you thousands of lines of code & weeks of work, and lets you craft amazing new user experiences.

Sign up to receive regular tips, learn about other use-cases and get alerted of blogposts & tutorials about Realm!


“Finally an elegant, low-footprint and multi-platform database for apps… and so beautifully designed too.”  *
David Helgason, CEO, Unity3D
“Your technology is possibly the first truly novel idea I've seen in software in 20 years.” *
Kostadis Roussos, Distinguished Engineer, Juniper
“I got up and running with Realm in literally a few minutes. It's really simple to use, and understand, especially compared to Core Data.” *
Rick Fillion, Black Pixel

What Does Realm Look Like?

Feels like Home

Realm’s data structures look like the Objects and Arrays of your language, but provide additional features such as: querying, relationships & graphs, thread safety, and more.

Compared to Core Data or other ORMs, you get a much simpler API, easy thread-safety and much improved performance on reads & writes.

Memory-Efficient

Realm is not built on SQLite. Instead, a custom C++ core is used to provide memory-efficient access to your data by using Realm objects, which usually consume less RAM than native objects. The core also provides an optional persistence layer that can automatically save and retrieve your objects from disk.

F-F-Fast!

Realm offers extraordinary performance compared to SQLite and other persistence solutions.
It has been in development since 2011 and powers an app with over 1 million daily active users at Zynga.

Realm Objects Look like Regular Objects…

// Just extend your standard POJO from RealmObject:

public class Dog extends RealmObject {
    private String          name;
    private int             age;
    @ignored private int    dontPersistMe;

    // + Standard setters and getters here
}
class Dog: RLMObject {
    dynamic var name = ""
    dynamic var age = 0
}

let mydog = Dog()

mydog.name = "Rex"
println("name of dog: \(mydog.name)")
@interface Dog : RLMObject
@property NSString *name;
@property NSInteger age;
@end

Dog *mydog = [[Dog alloc] init];

mydog.name = @"Rex"; 
NSLog(@"Name of dog: %@", mydog.name);

Offer Easy Persistence…

Realm realm = Realm.getInstance(this.getContext());

// Transactions give you easy thread-safety
realm.beginTransaction();
Dog dog = realm.createObject(Dog.class);
dog.setName("Rex");
dog.setAge(3);
realm.commitTransaction();
let realm = RLMRealm.defaultRealm()

realm.transactionWithBlock() {
    realm.addObject(mydog)
}
RLMRealm *realm = [RLMRealm defaultRealm];

[realm transactionWithBlock:^{
    [realm addObject:mydog];
}];

Can be Queried…

// Queries uses Builder pattern to build up the query conditions
RealmResults<Dog> query = realm.where(Dog.class)
                               .greaterThan("age", 8)
                               .findAll();

// Queries are chainable
RealmResults<Dog> allRex = query.where()
                                .contains("name", "rex")
                                .findAll();
let r = Dog.objectsWhere("age > 8")

// Queries are chainable
let r2 = r.objectsWhere("name contains 'rex'")
RLMResults *r = [Dog objectsWhere:@"age > 8"];
 
// Queries are chainable
r = [r objectsWhere:@"name contains 'rex'"];

Linked to Each Other…

public class Person extends RealmObject {
    private String name;
    private RealmList<Dog> dogs;
}

realm.beginWrite();
Dog mydog = realm.createObject(Dog.class);
Person person = realm.createObject(Person.class);
person.setName("Tim");
person.getDogs().add(mydog);
realm.commitWrite();
class Person : RLMObject {
    dynamic var name = ""
    dynamic var picture = NSData()
    dynamic var dogs = RLMArray(objectClassName: Dog.className())
}

realm.transactionWithBlock() {
    let person = Person()
    person.name = "Tim"
    person.dogs.addObject(mydog)
}
@interface Person : RLMObject
@property NSString      *name;
@property NSData        *picture;
@property RLMArray<Dog> *dogs;
@end

[realm transactionWithBlock:^{
    RLMPerson *person = [[RLMPerson alloc] init];
    person.name = @"Tim";
    [person.dogs addObject:mydog];
}];

… And are Safe to Use Across Threads!

new Thread(new Runnable() {
    public void run() {

        Realm realm = Realm.getInstance(this.getContext());
        RealmResults<Dog> dogs = realm.where(Dog.class)
                                      .contains("name", "rex")
                                      .findAll();
                                      
        // You can also write to a Realm from any thread
        // with full ACID guarantees
    }
}).start();
dispatch_async(dispatch_queue_create("background", 0)) {
  let results = Dog.objectsWhere("name contains 'rex'")

  // You can also write to a Realm from any thread
  // with full ACID guarantees
}
dispatch_async(dispatch_queue_create("background", 0), ^{
  RLMResults *results = [Dog objectsWhere:@"name contains 'rex'"];

  // You can also write to a Realm from any thread
  // with full ACID guarantees
}
Download for Android
Download for iOS+OSX