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

はじめてのCDQ

 はじめてのCDQ

RubyMotion Kaigi 2014 (http://connpass.com/event/8254/) で発表した資料です。

Katsuyoshi Ito

September 17, 2014
Tweet

More Decks by Katsuyoshi Ito

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ w ҏ౻উྑ ,BUTVZPTIJ*UP  w ༗ݶձࣾҏ౻ιϑτσβΠϯ w ळాݝେઋࢢ w

    "LJUBN8FCؔ৺͋Δਓͱͷަྲྀձ w "LJUB3VCZ.FFUJOH3VCZ ΋͘΋͘ ษڧձ
  2. DER

  3. DERͱ͸ʁ w $PSF%BUB2VFSZ w *OpOJUF3FE w $PSF%BUBͷϥούʔ w ͪΐͬͱ3BJMTΆ͘ w

    SVCZYDENซ༻͢ΔͱϞσϧ؅ཧ͕ςΩετͰ w J$MPVEʹ΋ରԠ
  4. $SFBUJPO include CDQ def create_objects Movie.create title:"Star Wars: A New

    Hope" Movie.create title:"Star Wars: The Empire Strikes Back " Movie.create title:"Star Wars: Return of the Jedi" cdq.save # ͜͜ͰॳΊͯอଘ͞ΕΔ end
  5. 2VFSZ def fetch_objects Movie .where(:title) .eq("Star Wars: A New Hope”)

    .first ! Movie .where(:title) .contains("Star Wars”)[0] ! Movie .where(:title) .contains("Star Wars”) .and .contains(“Hope") .first end
  6. 0SEFSJOHT def query_with_orderings ! Movie.all .sort_by(:title) .map(&:title) ! Movie.all .sort_by(:title,

    order: :descending, case_insensitive: true) .map(&:title) ! end ͸·ΓͲ͜Ζ TPSU@CZ͚ͩͩͱιʔτ͠ͳ͍
  7. NJHSBUJPO schema "0002" do entity "Movie" do string :title has_many

    :characters, deletionRule: "Cascade" end entity "Character" do string :name belongs_to :movie end end 4DIFNB@BEE@DIBSBDUFSSC
  8. 3FMBUJPOTIJQ $SFBUJPO def relation_create_objects m = Movie.new_hope.first m.characters.create name:"LUKE SKYWALKER"

    m.characters.create name:"OBI-WAN KENOBI" m.characters.create name:"DARTH VADER" cdq.save end
  9. .VMUJ5ISFBEJOH def background_insert m = Movie.new_hope.first parent = cdq.contexts.current Dispatch::Queue.concurrent.async

    do cdq.contexts.push(parent) cdq.contexts.new(NSPrivateQueueConcurrencyType) do context = cdq.contexts.current m1 = context.objectWithID(m.objectID) m1.characters.create name: "C-3PO" m1.characters.create name: "R2-D2" cdq.save Dispatch::Queue.main.sync { p Movie.new_hope.first.characters.map(&:name) } end end end
  10. .VMUJ5ISFBEJOH m = Movie.new_hope.first parent = cdq.contexts.current # 1 Dispatch::Queue.concurrent.async

    do cdq.contexts.push(parent) # 2 cdq.contexts.new(NSPrivateQueueConcurrencyType) do # 3 context = cdq.contexts.current # 4 m1 = context.objectWithID(m.objectID) QBSFOUDPOUFYU OFXDPOUFYU QBSFOUDPOUFYU .BJOUISFBE 5ISFBE DERDPOUFYUTDVSSFOU    DERDPOUFYUTDVSSFOU 
  11. .VMUJ5ISFBEJOH w 5ISFBEؒΛ·͙ͨ৔߹͸PCKFDU*%Λ࢖͏ m = Movie.new_hope.first parent = cdq.contexts.current Dispatch::Queue.concurrent.async

    do cdq.contexts.push(parent) cdq.contexts.new(NSPrivateQueueConcurrencyType) do context = cdq.contexts.current m1 = context.objectWithID(m.objectID) # 5
  12. ·ͱΊ w ͦͦ͜͜࢖͑·͢ w $PSF%BUBΛ͋·Γҙࣝ͠ͳͯ͘΋͍͍ w (SPVQɺ)BWJOH͸ະରԠ w 7BMJEBUJPO͸ࣗલͰ 3PBENBQʹ͸͋Δ͚Ͳ

     w .JHSBUJPOSPMMCBDL͏·͍͔͘ͳ͍Έ͍ͨ w J$MPVEJ5VOFT$POOFDUʹ·ͩ4VCNJUͯ͠ͳ͍ w ଍Γͳ͍ػೳ1VMMSFRVFTUͩ͠·͠ΐ͏