Slide 1

Slide 1 text

Gotta Persist ‘Em All: Realm as Replacement for SQLite Siena Aguayo Indiegogo @sienatime

Slide 2

Slide 2 text

Overview ● What Realm Is ● Pros and cons ● Compare and contrast with SQLite ● What Realm Isn’t

Slide 3

Slide 3 text

But First, Hello!

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

What Realm Is

Slide 8

Slide 8 text

● “embedded mobile database” Realm ● Core is written in C++ ● Available for Android and iOS ● Second most-deployed mobile database in the world

Slide 9

Slide 9 text

Pros

Slide 10

Slide 10 text

Pros for Realm ● Very responsive team ● Easy to use ● Convenient for creating and storing data on the fly ● Object conversion handled for you ● Faster than SQLite

Slide 11

Slide 11 text

Source: http://www.slideshare.net/ChristianMelchior/realm-building-a-mobile-database#25

Slide 12

Slide 12 text

Cons

Slide 13

Slide 13 text

Cons for Realm ● Have to create with Java on the device ● Still under active development ● Not a lot of content online ● No importing ● Can’t access objects across threads

Slide 14

Slide 14 text

Missing Features ● Auto-incrementing ids ● Compound primary keys ● Testing with Robolectric ● Map support

Slide 15

Slide 15 text

Compare and Contrast with SQLite

Slide 16

Slide 16 text

Database Connection and Setup

Slide 17

Slide 17 text

Shipping with Existing Database copy SQLite: SQLiteAssetHelper Realm: Sample migration app

Slide 18

Slide 18 text

Shipping with Existing Database SQLite: dbHelper.getReadableDatabase() or dbHelper.getWritableDatabase() Realm: Realm.getDefaultInstance()

Slide 19

Slide 19 text

Creating Schema SQLite

Slide 20

Slide 20 text

Creating Schema Realm

Slide 21

Slide 21 text

In Realm, your models ARE your schema.

Slide 22

Slide 22 text

Reading Data

Slide 23

Slide 23 text

Java with SQLite

Slide 24

Slide 24 text

Find All Java with Realm Find First

Slide 25

Slide 25 text

Writing Data

Slide 26

Slide 26 text

Java with SQLite

Slide 27

Slide 27 text

Java with Realm

Slide 28

Slide 28 text

Java with Realm

Slide 29

Slide 29 text

Adding Relationships and Complex Queries

Slide 30

Slide 30 text

Encounter has a LocationArea LocationArea has a Location

Slide 31

Slide 31 text

Location LocationArea Encounter

Slide 32

Slide 32 text

Raw SQL

Slide 33

Slide 33 text

Java with Realm

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

What Realm Isn’t

Slide 36

Slide 36 text

Realm says they are not an ORM because your data is not copied.

Slide 37

Slide 37 text

An ORM or not? SQLite >> pragma table_info(pokemon) 0|id|INTEGER|1||1 1|identifier|VARCHAR(79)|1||0 2|height|INTEGER|1||0 3|weight|INTEGER|1||0 Java public class Pokemon { private int id; private String identifier; private int height; private int weight; // constructor(s), // getters, setters } Typical ORM usage

Slide 38

Slide 38 text

Data from Realm in the toString()... Member variables are all uninitialized...

Slide 39

Slide 39 text

Shout-Out to Other ORMs ● greenDAO ● Active Android ● Sugar ORM ● ORMLite (Java) ● Cupboard Michael Pardo’s Android Data talk

Slide 40

Slide 40 text

Conclusion

Slide 41

Slide 41 text

Acknowledgments ● Realm: http://realm.io/ ● SQLite db from veekun’s Pokémon repo: https://github.com/veekun/pokedex ● Official Pokémon art by Ken Sugimori ● Christian Melchior for feedback

Slide 42

Slide 42 text

Questions? Twitter: @sienatime