Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Simple Disk Storage with ObjectBox by Vincent Carrier

Simple Disk Storage with ObjectBox by Vincent Carrier

GDG Montreal

October 25, 2017
Tweet

More Decks by GDG Montreal

Other Decks in Technology

Transcript

  1. Why do we need (yet) another database library? – Object-relational

    mappers (i.e. Room, GreenDAO) – Need to write SQL for every request – No auto-completion, no type safety – Migrations are scary – Realm – Complex – Inheritance-based – Custom types (e.g. JodaTime) suck – Weird threading requirements – Migrations are scary
  2. Why do we need (yet) another database library? – ObjectBox

    – No need to write SQL – Super fast – Great Kotlin support – RxJava 2 support – Annotation-based – Easy to learn – Safe, easy migrations – Web-based data browser – Local unit tests
  3. Why do we need (yet) another database library? – ObjectBox

    – No need to write SQL – Super fast – Great Kotlin support – RxJava 2 support – Annotation-based – Easy to learn – Safe, easy migrations – Web-based data browser – Local unit tests
  4. Setup Set automatically by the library VERY IMPORTANT: You need

    to provide ObjectBox either an empty constructor or an all-args one. Otherwise your queries will fail silently because ObjectBox cannot set the ID of your entities.
  5. The basics Note: If you don’t like RxJava, you can

    also use ObjectBox’s own data observers put() will update an object if the ID is already in the database. Your objects aren’t “live” like in Realm. Your changes need to be persisted with put()
  6. ToMany<T> Relations – Implements java.util.List (you can also just a

    normal List and track changes yourself) – Tracks changes to be persisted (using put()) – Use with @Backlink annotation to link with a ToOne<T> property and create a One-To-Many relation
  7. Migrations – Adding and removing properties is done automatically –

    For ambiguous schema modifications (i.e. changing the name or type of a property), annotate your entity class with @Uid, build your project and follow the instructions – UIDs are stored in a file called default.json. Make sure to add it to Git.