voyage by example
DESCRIPTION
Title: Voyage by example Speaker: Esteban Lorenzano Thu, August 21, 11:00am – 11:30am Video Part1: https://www.youtube.com/watch?v=1szVgKQm474 Video Part2: https://www.youtube.com/watch?v=vxork8Kckh8 Description Voyage is a framework to abstract over NoSQL databases and provides nice object-oriented features to save objects. Bio: Esteban Lorenzano, 42 years. Programmer since ever, Full-time Smalltalker since 2007 and Pharo enthusiast since almost its every beginning, after owning his own company and spend some years teaching at different universities in Argentina, he currently works de development of Pharo itself, at the RMoD team of INRIA (France)TRANSCRIPT
![Page 1: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/1.jpg)
Voyage by exampletips and tricks on persisting object models
![Page 3: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/3.jpg)
Why?• You already know about Voyage
• You already attended to a tutorial last year
• But there are some recurrent problems people find when trying to use it
• And I’m still seeing a lot of people that could be using it and they chose other solutions
![Page 4: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/4.jpg)
What is Voyage? (1)• Simple abstraction layer to map objects into a database
- Very well suited for document databases, but in theory, the approach will work for other kind of repositories
‣ There was (long time ago) a Voyage-GLORP backend
‣ There was (even more time ago) a Voyage-ImageSegment backend
- Voyage-Memory, Voyage-Mongo
![Page 5: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/5.jpg)
What is Voyage? (2)
• Did I said is simple?
• it ensures object identity
• it provides error handling
• it implements a connection pool
![Page 6: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/6.jpg)
Voyage principles• Behavioural complete (for common usage), but
decoupled approach also possible.
• Same design for different backends, but not a common abstraction
- There is no such thing as a “voyage query language”, etc.
- is a bit more work for users who want to switch, but a lot more happiness for the program itself
![Page 7: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/7.jpg)
Voyage ultimate goal
To be the GLORP for NoSQL databases
![Page 8: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/8.jpg)
The problem to solve
![Page 9: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/9.jpg)
Impedance mistmatch
Table BTable A Table C
Class A Class B Class C
1..*
*..*
Ideal relational model
![Page 10: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/10.jpg)
Impedance mistmatch
anObject otherObject
aColection
firstObject
secondObject
thirdObject
Real object model
![Page 11: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/11.jpg)
Impedance mistmatch
Real object model
anObject otherObject
aColection
firstObject
secondObject
thirdObject
![Page 12: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/12.jpg)
Impedance mistmatch
Real object model
anObject otherObject
aColection
firstObject
secondObject
thirdObject
![Page 13: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/13.jpg)
So, what about those tips?
![Page 14: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/14.jpg)
Think in objects
![Page 15: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/15.jpg)
A simple model
Hero Power*..*
![Page 16: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/16.jpg)
Persist
(Hero named: ‘Groot’) addPower: ((Power named: ‘Plant Control’) level: #epic; yourself); save.
![Page 17: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/17.jpg)
Persist{ _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Groot’, powers: [ { #collection: ‘Power’, __id: OID(…) } ] } !{ _id: OID(…), #version: …, #instanceOf: ‘Power’, name: ‘Plant Control’, level: #epic, heroes: [ #collection: ‘Hero’, __id: OID(…) ] }
![Page 18: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/18.jpg)
Take control
![Page 19: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/19.jpg)
A simple model (a bit more complete)
Hero Power*..*
Equipment
1..*
Container Pistol
1..*
![Page 20: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/20.jpg)
Persist
(Hero named: ‘Star-lord’) addEquipment: (Container addItem: Pistol new; yourself); save.
![Page 21: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/21.jpg)
Persist (1)
{ _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #instanceOf: ‘Container’, ‘items’, [ { #instanceOf: ‘Pistol’ } ] } ] }
![Page 22: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/22.jpg)
Persist (2){ _id: OID(1), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #collection: ‘Equipment’, __id: OID(2) } ] } !{ _id: OID(2), #version: …, #instanceOf: ‘Container’, items: [ { #collection: ‘Equipment’, __id: OID(3) } ] } !{ _id: OID(3), #version: …, #instanceOf: ‘Pistol’, }
![Page 23: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/23.jpg)
Integrity is a consequence
![Page 24: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/24.jpg)
Allowing missing content
• We do not have foreign keys
- So we cannot do things like “ON DELETE CASCADE”
- Even delete validations are difficult
‣ Imagine “hero” has a “power”,and I remove the “power”. How can the hero notice it?
![Page 25: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/25.jpg)
Persist
mongoContainer <mongoContainer> ! ^ VOMongoContainer new collectionName: ‘powers’; enableMissingContent; yourself
![Page 26: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/26.jpg)
Querying smart
![Page 27: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/27.jpg)
Query (1)
Hero selectMany: [ :each | … ] sortBy: { #name -> VOOrder ascending } asDictionary limit: 100 offset: 100
![Page 28: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/28.jpg)
Query (2)
Hero selectMany: { ‘name’ -> { ‘$regexp’ -> ‘^G.*’. ‘$options’ -> ‘i’ } asDictionary } asDictionary
![Page 29: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/29.jpg)
Adapt schemes
![Page 30: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/30.jpg)
The “scheme is not mine” problem
• You can move meta-information to your program
• Magritte-Voyage gives you a lot of power
• You can extend/modify parts of the updating system too (like versioning)
![Page 31: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/31.jpg)
Meta-information
{ _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #instanceOf: ‘Container’, ‘items’, [ { #instanceOf: ‘Pistol’ } ] } ] }
![Page 32: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/32.jpg)
Meta-information
{ _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #instanceOf: ‘Container’, ‘items’, [ { #instanceOf: ‘Pistol’ } ] } ] }
![Page 33: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/33.jpg)
Meta-information
{ _id: OID(…), name: ‘Star-lord’, powers: [], equipment: [ { ‘items’, [ {} ] } ] }
![Page 34: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/34.jpg)
Voyage 2.0• Root detection (enhance save & update)
• Cyclic detection
- Add strategy to persist cycles even without roots (It has some consequences (in querying, etc.), so it will be optional)
• integrity validations
- #removeWithDependencies
• Materialisation customisations
- #readRaw
• Add backend: Riak
![Page 35: Voyage by example](https://reader033.vdocuments.net/reader033/viewer/2022052505/555bde8ad8b42a38078b4850/html5/thumbnails/35.jpg)
Use it today!
Gofer it smalltalkhubUser: ‘Pharo’ project: ’MetaRepoForPharo30’; configurationOf: ‘VoyageMongo’; loadStable.
Thanks!!Esteban Lorenzano - 2014