Room2.1 DatabaseView あるある

Room2.1 DatabaseView あるある

494a2760dceccc31c4bcdb689041c614?s=128

Koji Wakamiya

January 28, 2020
Tweet

Transcript

  1. Room2.1 DatabaseView ͋Δ͋Δ ͋Δ͋ΔLTʙ ͓ਖ਼݄ͩΑʂAndroid & iOS߹ಉ େLTେձ ʙ Vol.10

  2. ࣗݾ঺հ • Koji Wakamiya • Studyplus, inc. • @koji-1009 (Github)

    • @D_R_1009 (Twitter, Hatena, etc…) 
  3. DatabaseView ࢖ͬͯ·͔͢ʁ

  4. DatabaseViewʹ͍ͭͯʢ͓͞Β͍ʣ • Room 2.1Ͱ௥Ճ͞Εͨػೳ • Inner/Outer joinΛRoomͰ࣮ݱ • ςʔϒϧΛ͋Δ΂͖ܗʹ෼ׂ͠ දࣔ(View)ʹ߹ΘͤͯσʔλΛ߹੒͢Δ͜ͱ͕Ͱ͖Δ

    
  5. ෳ਺ͷςʔϒϧͱForeignKey • ؔ࿈ͷ͋Δෳ਺ͷςʔϒϧΛѻ͏͜ͱʹͳΔͨΊ ForeignKeyΛར༻͢Δ͜ͱ͕͋Δ • ؔ࿈෇͚Λߦ͏͜ͱͰɺத৺ͱͳΔrowΛ࡟আͨ࣌͠ʹ ଞͷςʔϒϧͷrow΋࡟আ͢ΔͳͲͷߟྀΛߦ͏ 

  6. OnConflictStrategy.REPLACEͰ σʔλ͕ফ͑ͪΌ͏ࣄ݅

  7. OnConflictStrategy • InsetॲཧதʹConflict͕ൃੜ(row͕طʹଘࡏ)ͨ࣌͠ ͲͷΑ͏ͳѻ͍Λ͢Δ͔ΛܾΊΔ͜ͱ͕Ͱ͖Δ • DBͷར༻༻్΍໨తʹ߹Θͤͯར༻͢ΔStrategy͕มΘΔ 

  8. OnConflictStrategy • ABORT (default) • OnConflict strategy constant to abort

    the transaction. • REPLACE • OnConflict strategy constant to replace the old data and continue the transaction. • Ignore • OnConflict strategy constant to ignore the conflict. 
  9. ࣄ݅ঢ়گ • ΞΠςϜςʔϒϧͱΞΠςϜฒͼॱςʔϒϧ͕ଘࡏ • ΞΠςϜ͸ΞϓϦىಈ࣌ʹαʔόʔͱಉظ • @InsertͱOnConflictStrategy.REPLACEͰશσʔλߋ৽ • ฒͼॱͷσʔλ͸ΞϓϦ಺ʹ͔͠ଘࡏ͠ͳ͍ͨΊอ࣋ 

  10. ࣄ݅ঢ়گ • αʔόʔͱΞϓϦ಺DBΛಉظ(ϦϑϨογϡ)͢Δͱ ΞΠςϜϦετ͕දࣔ͞Εͳ͘ͳΔ • ௐ΂ͯΈΔͱʮΞΠςϜʯͷσʔλ͸͋Δ͕ ʮΞΠςϜฒͼॱʯ͕ଘࡏ͠ͳ͘ͳ͍ͬͯΔ • Inner JoinͷͨΊDatabaseView͕ੜ੒͞Ε͍ͯͳ͍……ʁ

    
  11. Ͳ͏ͯ͠σʔλফ͑ͪΌ͏Μ……

  12. REPLACEʹΑΔUpdateॲཧ • REPLACE͸࣮࣭తʹUpdateॲཧʢͩͱࢥ͍ͬͯͨʣ • Conflictൃੜ͠ͳ͍ → ৽نrow࡞੒ॲཧ • Conflictൃੜ͢Δ →

    طଘrowߋ৽ॲཧ 
  13. REPLACEʹΑΔUpdateॲཧ • REPLACE͸࣮࣭తʹUpdateॲཧʢͰ͸ͳ͍ʣ • Conflictൃੜ͠ͳ͍ → ৽نrow࡞੒ॲཧ • Conflictൃੜ͢Δ →

    طଘrowߋ৽ॲཧ طଘrow࡟আॲཧ + ৽نrow௥Ճॲཧ 
  14. REPLACEʹΑΔUpdateॲཧ • طଘrowͷ࡟আ + ForeignKeyʹΑΔؔ࿈෇͚ʹΑΓ ʮΞΠςϜʯͷ࡟আͰʮΞΠςϜฒͼॱʯ͕࡟আ͞Ε͍ͯͨ • @InsertͰ͸ͳ͘@UpdateΛར༻͠ͳ͚Ε͹ͳΒͳ͔ͬͨ • ௥Ճͱߋ৽ॲཧΛϝιουͰ੾Γ෼͚Δ͜ͱͰ

    ͜ͱͳ͖ΛಘΔ͜ͱ͕Ͱ͖ͨ 
  15. υΩϡϝϯτ͸ͪΌΜͱಡΉ ʢ͋ͱɺԣண͠ͳ͍ʣ

  16. Thanks!