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

SQLite to Realm

Realm
November 25, 2015

SQLite to Realm

2015/11/20 Realm meetup Seoul
노현석님 발표

Realm

November 25, 2015
Tweet

More Decks by Realm

Other Decks in Technology

Transcript

  1. Why? • 웹툰 앱 소스 GitHub 공개 • 내 소스인데

    엉망이다 • 바꿔보고 싶은 걸 바꿔보자 그냥!!
  2. Modify • jsoup • butterknife • glide • sqlbrite •

    rxandroid • okhttp • jsoup • butterknife • glide • realm • otto • rxandroid
  3. Save • Favorite Info • Read Info Favorite Service Name

    : String Toon ID : String Read Service Name : String Toon ID : String Episode ID : String
  4. Sqlbrite • by square • SQLiteOpenHelper + Reactive ◦ A

    lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operation
  5. Sqlbrite Code BriteDatabase db = sqlBrite.wrapDatabaseHelper(openHelper); Observable<Query> users = db.createQuery("users",

    "SELECT * FROM users"); users.subscribe(new Action1<Query>() { @Override public void call(Query query) { Cursor cursor = query.run(); // TODO parse data... } });
  6. Realm • Core NDK • Realm != Sqlite • Sqlite

    Migration Guide X ◦ Realm 0.84.2
  7. SqliteToRealm.java public void pushSynonymsToWords() { SqliteHelper dbs = SqliteHelper.getInstance(); RealmHelper

    dbr = RealmHelper.getIntance(); List<Word> rawWords = getAllRawWords(); List<List<String>> records = dbs.getRecords("synonym"); List<IntPair> synonyms = new ArrayList<>(); for(List<String> record : records){ if(null == record.get(0) || null == record.get(1)) continue; IntPair pair = new IntPair(Integer.parseInt(record.get(0)),Integer.parseInt(record.get(1))); synonyms.add(pair); } dbr.addSynonymToWords(synonyms); }
  8. SqliteToRealm Sqlite Realm • Open Sqlite • Get Data •

    Close Sqlite • Realm.getInsatance(Context) • beginTransaction() • Add Data • commitTransaction()
  9. Um ... • Realm 사용 ◦ SPEED ◦ ORM •

    기존 sqlite 관련 파일을 지울 수 없음 ◦ SQLiteOpenHelper ◦ Item Class • 한국 페이지에는 부재인 ADD-ON 페이지
  10. Extend Um ... • APK SIZE ◦ ABI Split 으로

    해결 가능 ◦ Reducing your Android APK size When Using Native Libraries • 큰 데이터 ( 수만 건 ) ◦ 트랜잭션에서 처리하는 단위가 큰 경우 OOM 발생 ◦ 100~200 단위 처리 • Realm version 에 맞는 Proguard 처리 Link : Twitter クライアントの内部 DB を SQLite から Realm に移行したときのノウハウまとめ Link : Realm 導入による APK 肥大化を防ぐ (Split APK)
  11. Extend Um ... • Insert, 20 Count ◦ 150ms →

    100ms • Search, 4 Count ◦ 14ms → 8ms or 17ms → 10ms or or or • Insert, 16 Count (62kb) ◦ 97ms → 38ms Link : Twitter クライアントの内部 DB を SQLite から Realm に移行したときのノウハウまとめ
  12. recommended 처음부터 Realm • Realm != Sqlite Rx + Preference

    • 초기 작업 + 1 • 실행 시 SqliteToRealm 필요 • Preference 에 Flag 등록