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

Firebase or Realm?

Firebase or Realm?

7Masters Firebase

Douglas Kayama

August 30, 2017
Tweet

More Decks by Douglas Kayama

Other Decks in Technology

Transcript

  1. @douglasdrumond Funcionalidades com.google.firebase:firebase-core:11.2.0 Analytics com.google.firebase:firebase-database:11.2.0 Realtime Database com.google.firebase:firebase-storage:11.2.0 Storage com.google.firebase:firebase-crash:11.2.0

    Crash Reporting com.google.firebase:firebase-auth:11.2.0 Authentication com.google.firebase:firebase-messaging:11.2.0 Cloud Messaging com.google.firebase:firebase-config:11.2.0 Remote Config com.google.firebase:firebase-invites:11.2.0 Invites And Dynamic Links com.google.firebase:firebase-ads:11.2.0 AdMob com.google.firebase:firebase-appindexing:11.2.0 App Indexing com.google.firebase:firebase-perf:11.2.0 Performance Monitoring 3
  2. @douglasdrumond Funcionalidades com.google.firebase:firebase-core:11.2.0 Analytics com.google.firebase:firebase-database:11.2.0 Realtime Database com.google.firebase:firebase-storage:11.2.0 Storage com.google.firebase:firebase-crash:11.2.0

    Crash Reporting com.google.firebase:firebase-auth:11.2.0 Authentication com.google.firebase:firebase-messaging:11.2.0 Cloud Messaging com.google.firebase:firebase-config:11.2.0 Remote Config com.google.firebase:firebase-invites:11.2.0 Invites And Dynamic Links com.google.firebase:firebase-ads:11.2.0 AdMob com.google.firebase:firebase-appindexing:11.2.0 App Indexing com.google.firebase:firebase-perf:11.2.0 Performance Monitoring 4
  3. @douglasdrumond Setup Realm // Authenticating the User User user =

    User.login(Credentials.google("google token"), "http://realm.example.com:9080/auth"); // Opening a remote Realm String realmURL = "realm://realm.example.com:9080/~/userRealm"; SyncConfiguration config = new SyncConfiguration.Builder(user, realmURL).build(); Realm realm = Realm.getInstance(config); // Any changes made to this Realm will be synced across all devices 9
  4. @douglasdrumond Setup Firebase // Write a message to the database

    FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("message"); myRef.setValue("Hello, World!"); 10
  5. @douglasdrumond Leitura em tempo real (Realm) list = realm.where(TaskList.class) .equalTo(TaskList.FIELD_ID,

    id).findAll(); list.addChangeListener( new RealmChangeListener<RealmResults<TaskList>>() { @Override public void onChange(RealmResults<TaskList> results) { updateList(results); } }); updateList(list); 12
  6. @douglasdrumond Leitura em tempo real (Firebase) // Read from the

    database myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { String value = dataSnapshot.getValue(String.class); Log.d(TAG, "Value is: " + value); } @Override public void onCancelled(DatabaseError error) { } }); 13
  7. @douglasdrumond Escrita (Firebase) private void writeNewUser(String userId, String name) {

    User user = new User(name); mDatabase.child("users").child(userId).setValue(user); } 15
  8. @douglasdrumond Curva de aprendizado Realm tem uma sintaxe semelhante a

    ORMs A modelagem do Firebase é um pouco mais complexa 17
  9. @douglasdrumond Principal diferença Realm é offline first com sync Firebase

    é sync first com offline Pense no que isso significa para sua arquitetura 18