Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ROM.rb: Another Approach to Persistence
Search
Seiya IZUMI
September 28, 2017
Programming
1
840
ROM.rb: Another Approach to Persistence
Meguro.rb #7
Seiya IZUMI
September 28, 2017
Tweet
Share
More Decks by Seiya IZUMI
See All by Seiya IZUMI
Elm, the functional frontend
izumisy
3
1.1k
Elmの歩き方2019
izumisy
5
3.3k
Our Journey with the Biggest Elm App in Japan
izumisy
0
140
jQueryからElmまで
izumisy
1
1.6k
Ordering and Ordered
izumisy
1
73
僕が新卒として意識している4つのこと
izumisy
0
100
Choo: Fun Functional Framework
izumisy
1
450
StackoverflowでREPを稼ぐ技術
izumisy
1
770
フロントエンド・バリデーション
izumisy
5
3.5k
Other Decks in Programming
See All in Programming
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
cmp.Or に感動した
otakakot
3
210
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
Quine, Polyglot, 良いコード
qnighy
4
650
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
150
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Producing Creativity
orderedlist
PRO
341
39k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
The Language of Interfaces
destraynor
154
24k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Bash Introduction
62gerente
608
210k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Transcript
ROM.rb: Another Approach to Persistence Seiya IZUMI (@sy_izumi)
About me • ଂେֶ4 • 1ؒٳֶͯ͠ITاۀͰΊͪΌͪ͘ΌΠϯλʔ ϯͨ͠Γͨ͠ • ීஈVue.jsReactNativeͳͲΛ৮ͬͯ·͢ @sy_izumi
IzumiSy
ࠓROM.rbͷͳ͠Λ͠·͢
RailsΞϓϦέʔγϣϯΛ࡞͍ͬͯͯ • Model͕σʔλϕʔεʹର͢Δૢ࡞ͱɺυϝΠ ϯର͢Δૢ࡞ͱ͍͏̎ͭͷΛ͕࣋ͪͪʹ ͳΔ͜ͱ͕ଟ͍ • Ϟσϧ͕࣮࣭ɺӬଓԽϨΠϠͱૄ݁߹ database schema ≒
domain model
ActiveRecordͷ͍ͤͰͳ͍ • ActiveRecordύλʔϯʹ͓͍ͯɺϞσϧ͕ ӬଓԽϨΠϠͷߏͱಉ͡Ͱ͋Δͱ͍͏͜ͱ རɻ • ϦϑΝΫλϦϯάύλʔϯͳͲʹΑͬͯదͳ ରॲ͕Ͱ͖Δ (FormObject, Validator,
Callback,etc …)
ʮAR͡Όͳ͍ͱμϝʯͰͳ͍ • ϦϑΝΫλϦϯάύλʔϯΛۦͯ͠ ActiveRecordΛ͍͜ͳ͢ͷͻͱͭͷબ • Ͱɺ͔ͨ͠͠ΒସʹͳΔΑ͏ͳҟͳΔ ࢥͷORϚούʔ͕͋Δ͔ʂ • άάͬͯΈΔ
͋ͬͨ
ROM.rbͱ • RubyΞϓϦέʔγϣϯͷͨΊͷӬଓԽϥΠϒ ϥϦ • ୯ͳΔORϚούʔͰͳ͘ɺ༷ʑͳӬଓԽ ஔΛϓϥΨϒϧͳΞμϓλͱͯ͑͠Δ • Separating persistence
from domain layer
ϔΩαΰφϧɾΞʔΩςΫνϟ http://blog.tai2.net/hexagonal_architexture.html
ӬଓԽΛͲ͏ଊ͑Δ͔ʁ User.create(name: “Bob”) POST https://api.stripe.com/v1/charges
ӬଓԽϨΠϠͱૄ݁߹ੑ • ΞϓϦέʔγϣϯͷ֎෦ʹ͋Δஔͷૢ࡞ํ ๏ʹؔͯ͠Ͱ͖Δ͚ͩૄ݁߹ʹ͢Δ • WebAPI͍ͭ·Ͱ͑ΔͱݶΒͳ͍ ʢcf. WebPayͷαʔϏεऴྃ in 2016ʣ
• ΞϓϦέʔγϣϯ͕ϏδωεҎ֎ͷͷʹґ ଘ͠ॊೈੑ͕ࣦΘΕΔͷΛආ͚Δ
How to use ROM.rb?
Architecture .PEFM 3FQPTJUPSZ 3FMBUJPO "EBQUFS Infratructure Layer Domain Layer
Architecture 1030 ROM::Repository ROM::Relation ROM::Gateway Infratructure Layer Domain Layer
Model module Domain class Book attr_reader :id, :title, :price def
initialize(attrs) @id, @title, @price = attrs.values_at(:id, :title, :price) end end end • POROͳΞϓϦέʔγϣϯݻ༗ͷϩδοΫΛ࣋ͭ • ଟ͘ͷ߹RepositoryʹΑͬͯੜ͞ΕΔ • ROM.rb͕͜͜ʹ༩͑ΔӨڹ࠷খݶ
Repository module Repository class Book < ROM::Repository[:books] def by_id(id) books.by_pk(id).map_to(Domain::Books).one!
end def all books.map_to(Domain::Book) end end end • υϝΠϯϨΠϠͱӬଓԽϨΠϠͷ૭ޱʹͳΔ෦ • υϝΠϯʹదͳΦϒδΣΫτΛੜ͠ɺӬଓԽஔʹݻ༗ͳΫΤϦੜ ͳͲRelation͕ͱ͚ͯ͠ෛ͏
Relation class Books < ROM::Relation[:sql] schema(infer: true) do associations do
belongs_to :author end def by_id(id) where(id: id) end def available where(is_available: true) end end end • ӬଓԽϨΠϠͱͯ͠Ξμϓλʹ ର͢Δૢ࡞Λϥοϓ͢Δ • ΞιγΤʔγϣϯϑΟʔϧυ όϦσʔγϣϯͳͲΛ͜͜Ͱఆ ٛ • ରͱͳΔΞμϓλʹݻ༗ͷૢ ࡞͕Ͱ͖Δ • ͜͜Ͱఆٛͨ͠ϝιου܈Λ RepositoryͰ͑Δ
Adapter • ӬଓԽஔͷ۩ମతͳૢ࡞Λߦ͏ • 3rd-partyͷओཁͳAPIΞμϓλ͍͔ͭ͘༻ҙ͞Ε͍ͯΔ • SQLΞμϓλʹSequel͕ϥοϓ͞Ε͍ͯΔ
·ͱΊ
·ͱΊ • ROM.rbӬଓԽϨΠϠͷநԽͱυϝΠϯϨ ΠϠ͔ΒͷΛΨονϦͱαϙʔτͯ͘͠ ΕΔ • υϝΠϯʢϞσϧʣϨΠϠͱӬଓԽϨΠϠΛ ૄ݁߹ʹͯ͠ɺΞϓϦέʔγϣϯΛมԽʹڧ ͘͠Α͏
Ұํ·ͨผͷҙݟ • ͲͷΛͲ͏͚Δ͔ͱ͍͏؍ͷ౷Ұ͕ ग़དྷ͍ͯͳ͍ͱӡ༻ͣ͠Β͍ݒ೦͕͋Δ • ιʔείʔυ͕ࢄΒͬͯݟ௨͕͠ѱ͘ͳΔͱ ͍͏ਓ͍Δ • ΞϓϦέʔγϣϯͷఆنʹ߹Θͤͯద ͳπʔϧΛબͿͷ͕BEST
https://github.com/IzumiSy/sample_bookshelf
Thank You! http://rom-rb.org