Image alternative text

Realm - A reactive database for .NET developers

Mobile database platform Realm has just announced Realm Xamarin, a new edition of their database built specifically for the Xamarin. Realm offers easy object persistence and full query capabilities, with a performance profile that’s faster than existing options.

Realm is designed from the ground up to enable reactive app development, with live objects, change events, and support for unidirectional data flows. With Xamarin support, Realm now covers Android, iOS, JavaScript and .NET.

Realm began working on the project after a large number of developers requested Xamarin support, and feels it can solve one of the major challenges Xamarin developers face right now.

If you’re not familiar with it, Realm is a popular database solution already used by developers such as Twitter, Starbucks, Cisco, Walmart, Google, Amazon, eBay and more. Additional technical details shared by Realm:

"Realm Xamarin brings the modern design & simplicity you expect from Realm, and will allow you to target both iOS and Android with the same codebase. Like the other editions of Realm, it is designed from the ground up to enable reactive app development, with live objects, change events, and support for unidirectional data flows.

Please note the Realm file format is also completely cross-platform, allowing data to be shared across iOS & Android easily. We currently support Xamarin.iOS and Xamarin.Android, and look forward to supporting Xamarin.Mac in the future, as well as UWP and Unity."

Realm Xamarin is already available on GitHub, and the team is asking developers to provide feedback on bugs and feature requests. Realm is not built on top of SQLite. Instead Realm is a full database for mobile app developers, one that uses native C# objects that are dynamically mapped to a full, custom database engine. With Realm, you can model complex data, link objects in a graph, and compose advanced queries.

Realm Example

// Define your models like regular C# classes
public class Dog : RealmObject 
{
    public string Name { get; set; }
    public int Age { get; set; }
    public Person Owner { get; set; }
}

public class Person : RealmObject 
{
    public string Name { get; set; }
    public RealmList Dogs { get; } 
}

var realm = Realm.GetInstance();

// Use LINQ to query
var puppies = realm.All().Where(d => d.Age  0 because no dogs have been added yet

// Update and persist objects with a thread-safe transaction
realm.Write(() => 
{
    var mydog = realm.CreateObject();
    mydog.Name = "Rex";
    mydog.Age = 1;
});

// Queries are updated in real-time
puppies.Count(); // => 1

// LINQ query syntax works as well
var oldDogs = from d in realm.All() where d.Age > 8 select d;

// Query and update from any thread
new Thread(() =>
{
    var realm2 = Realm.GetInstance();

    var theDog = realm2.All().Where(d => d.Age == 1).First();
    realm2.Write(() => theDog.Age = 3);
}).Start();

Why use Realm?

Because Realm is:

Easy

Realm’s primary focus has always been ease of use, and as you can see from the samples above, Realm Xamarin has the same overall goal. After that, we’ve been working on some of the same advantages our other products are known for…

Fast

Realm’s ease of use doesn’t come at a performance cost. Because of its memory mapping, lazy loading, and custom storage engine, Realm is usually faster than SQLite despite offering a rich object-based API. Although we always recommend everyone test their own use-cases, we usually see huge speedups when porting code to Realm. See benchmark results below.

Cross-platform

This should go without saying, but Realm Xamarin obviously allows you to write your app once in C# and target both iOS & Android. Please note the Realm file format is also completely cross-platform, allowing data to be shared across iOS & Android easily. For debugging, .realm files can be opened via the Realm Browser.

Advanced

Realm objects are always up-to-date with the underlying data, making it trivial to follow reactive patterns or a unidirectional data flow. You can link Realm objects in graphs, query any property combination via LINQ, and even easily integrate Realm data in Xamarin.Forms.

Trusted

Realm Xamarin is built on top of the same core as Realm Java, Objective‑C, React Native, and Swift, which is trusted by hundreds of millions of people around the world, and used by e‑commerce applications, banks, healthcare providers, and even governments.

Community-driven

Realm Xamarin is built in the open on GitHub. Features are prioritized based on user requests and we welcome contributions.

Supported

Realm prioritizes support & bugfixes above all else. You can get answers about your database directly from the people that build & maintain it, via StackOverflow, GitHub or Twitter.