SQLite to Realm

1fa9cb8c7997c8c4d3d251fb5e41f749?s=47 Realm
November 25, 2015

SQLite to Realm

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

1fa9cb8c7997c8c4d3d251fb5e41f749?s=128

Realm

November 25, 2015
Tweet

Transcript

  1. 3.
  2. 4.

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

    엉망이다 • 바꿔보고 싶은 걸 바꿔보자 그냥!!
  3. 5.

    Modify • jsoup • butterknife • glide • sqlbrite •

    rxandroid • okhttp • jsoup • butterknife • glide • realm • otto • rxandroid
  4. 6.

    Save • Favorite Info • Read Info Favorite Service Name

    : String Toon ID : String Read Service Name : String Toon ID : String Episode ID : String
  5. 7.

    Sqlbrite • by square • SQLiteOpenHelper + Reactive ◦ A

    lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operation
  6. 9.

    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... } });
  7. 10.

    Realm • Core NDK • Realm != Sqlite • Sqlite

    Migration Guide X ◦ Realm 0.84.2
  8. 12.

    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); }
  9. 13.

    SqliteToRealm Sqlite Realm • Open Sqlite • Get Data •

    Close Sqlite • Realm.getInsatance(Context) • beginTransaction() • Add Data • commitTransaction()
  10. 14.

    Um ... • Realm 사용 ◦ SPEED ◦ ORM •

    기존 sqlite 관련 파일을 지울 수 없음 ◦ SQLiteOpenHelper ◦ Item Class • 한국 페이지에는 부재인 ADD-ON 페이지
  11. 15.

    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)
  12. 16.

    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 に移行したときのノウハウまとめ
  13. 17.

    recommended 처음부터 Realm • Realm != Sqlite Rx + Preference

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