SlideShare a Scribd company logo
Querier:
simple relational database access
Michal Balda
What is Querier?
 A library for querying relational databases.
 Focused on simplicity.
 Heavily inspired by NotORM
(http://www.notorm.com/).
Why?
Accessing a relational database in Pharo:
Why?
Accessing a relational database in Pharo:
1) Write SQL by hand.
Why?
Accessing a relational database in Pharo:
1) Write SQL by hand.
2) Use an object-relational mapper (GLORP).
Why?
Accessing a relational database in Pharo:
1) Write SQL by hand.
1.5) Use Querier.
2) Use an object-relational mapper (GLORP).
Database structure
Primary Key Column id
Foreign Key Column {table}_id
Table Name {table}
Setup
| driver structure db |
driver := "…".
structure := QRRConventionalStructure new.
db := Querier withDriver: driver structure: structure
Accessing a table
db table: #song
"or use a shortcut:"
db song
song
id Integer, Primary Key
title Varchar
length Integer
album_id Integer, Foreign Key
Accessing a table
db table: #song
"or use a shortcut:"
db song
SELECT *
FROM song
Accessing a table
db song do: [ :row |
Transcript show: row title; cr ]
Two principles
1) A table is a collection of rows.
2) A row is a dictionary of values.
WHERE
db song select: [ :row |
(row length >= 180)
& (row length <= 300) ]
SELECT *
FROM song
WHERE length >= 180
AND length <= 300
WHERE
db song select: [ :row |
(row length >= 180)
& (row length <= 300) ]
Udo Schneider: BlockTranslators - parsing magic
http://readthesourceluke.blogspot.com/2014/09/
block-translators-parsing-magic.html
ORDER BY
db song sorted: [ :a :b |
a length < b length ]
SELECT *
FROM song
ORDER BY length ASC
LIMIT and OFFSET
(db song sorted: [ :a :b |
a length < b length ])
first: 10
SELECT *
FROM song
ORDER BY length ASC
LIMIT 10
LIMIT and OFFSET
(db song sorted: [ :a :b |
a length < b length ])
allButFirst: 10
SELECT *
FROM song
ORDER BY length ASC
OFFSET 10
Selecting a single row
row := db song detect: [ :row |
row id = 123 ]
SELECT *
FROM song
WHERE id = 123
LIMIT 1
Selecting by primary key
row := db song at: 123
SELECT *
FROM song
WHERE id = 123
LIMIT 1
Selecting by primary key
row := db song at: 123
SELECT *
FROM song
WHERE id = 123
LIMIT 1
Aggregations
db song average: [ :row |
row length ]
db song average: #length
SELECT AVG(length)
FROM song
Enumerating the result
db song collect: [ :row |
row title ]
db song do: [ :row |
Transcript show: row title; cr ]
db song size
Accessing related tables
song
id Integer, Primary Key
title Varchar
length Integer
album_id Integer, Foreign Key
album
id Integer, Primary Key
title Varchar
Accessing related tables
db song select: [ :row |
row album name = 'Unknown Album' ]
song
id Integer, Primary Key
title Varchar
length Integer
album_id Integer, Foreign Key
album
id Integer, Primary Key
title Varchar
Accessing related tables
db song select: [ :row |
row album name = 'Unknown Album' ]
SELECT *
FROM song
LEFT JOIN album
ON song.album_id = album.id
WHERE album.name = 'Unknown Album'
Accessing related tables
db song select: [ :row |
row album name = 'Unknown Album' ]
SELECT *
FROM song
LEFT JOIN album
ON song.album_id = album.id
WHERE album.name = 'Unknown Album'
Accessing related tables
db song select: [ :row |
row album artist name = 'Unknown Artist' ]
SELECT *
FROM song
LEFT JOIN album
ON song.album_id = album.id
LEFT JOIN artist
ON album.artist_id = artist.id
WHERE artist.name = 'Unknown Artist'
Accessing related tables
db song do: [ :row |
Transcript show: row album name ]
Accessing related tables
db song do: [ :row |
Transcript show: row album name ]
1) SELECT *
FROM song
Accessing related tables
db song do: [ :row |
Transcript show: row album name ]
1) SELECT *
FROM song
Accessing related tables
db song do: [ :row |
Transcript show: row album name ]
1) SELECT *
FROM song
2) SELECT *
FROM album
WHERE id IN (1, 2, 3, …)
Accessing related tables
song
id Integer, Primary Key
title Varchar
length Integer
album_id Integer, Foreign Key
album
id Integer, Primary Key
title Varchar
The opposite direction
db album do: [ :row |
row songCollection do: [ :song |
Transcript show: song name; cr ] ]
song
id Integer, Primary Key
title Varchar
length Integer
album_id Integer, Foreign Key
album
id Integer, Primary Key
title Varchar
The opposite direction
db album do: [ :row |
row songCollection do: [ :song |
Transcript show: song name; cr ] ]
1) SELECT *
FROM album
The opposite direction
db album do: [ :row |
row songCollection do: [ :song |
Transcript show: song name; cr ] ]
1) SELECT *
FROM album
2) SELECT *
FROM song
WHERE album_id IN (1, 2, 3, …)
UPDATE
db song do: [ :row |
row length: row length + 10.
row save ]
1) SELECT * FROM song
2) UPDATE song SET length = 325
WHERE id = 1
3) UPDATE song SET length = 648
WHERE id = 2
4) … and many more
Better UPDATE
db song update: [ :row |
row length: row length + 10 ]
UPDATE song
SET length = length + 10
Better UPDATE
(db song select: [ :row |
row length < 180 ])
update: [ :row |
row length: row length + 10 ]
UPDATE song
SET length = length + 10
WHERE length < 180
DELETE
(db song select: [ :row |
row length < 180 ])
removeAll
db song delete: [ :row |
row length < 180 ]
DELETE FROM song
WHERE length < 180
INSERT
| row |
row := db song new.
row title: 'New Song'.
row length: 316.
row album: (db album detect: [ :row |
row album name = 'Unknown Album' ]).
row save.
Transcript show: row id
Current Status
 A proof-of-concept for Pharo + Postgres.
 Working on polishing all features + querying
other RDBMS through Garage
(https://guillep.github.io/DBXTalk/garage/).
Future work
 Add ORM-like features (instantiate your
entity classes instead of dictionaries).
 Add at least partial support for non-relational
databases (like MongoDB).
Questions?
http://querier.xmb.cz/
Thank you for your attention!
http://querier.xmb.cz/

More Related Content

What's hot

My First Ruby
My First RubyMy First Ruby
My First Ruby
Murray Steele
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
swtjerin4u
 
Gnome terminal basics
Gnome terminal basicsGnome terminal basics
Gnome terminal basics
Kamrul Hasan
 
Switching from java to groovy
Switching from java to groovySwitching from java to groovy
Switching from java to groovy
Paul Woods
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014
Noé Fernández-Pozo
 
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
David Koelle
 
Linux commands
Linux commandsLinux commands
Linux commands
shekhar70
 
Ohm
OhmOhm
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
Ben Pope
 
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
David Koelle
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 

What's hot (13)

My First Ruby
My First RubyMy First Ruby
My First Ruby
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 
Linux cheat-sheet
Linux cheat-sheetLinux cheat-sheet
Linux cheat-sheet
 
Gnome terminal basics
Gnome terminal basicsGnome terminal basics
Gnome terminal basics
 
Switching from java to groovy
Switching from java to groovySwitching from java to groovy
Switching from java to groovy
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014
 
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Ohm
OhmOhm
Ohm
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
 
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 

Similar to Querier – simple relational database access

Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
fazanmobiles
 
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise GrandjoncAmazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Citus Data
 
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
arenamobiles123
 
JSON By Example
JSON By ExampleJSON By Example
JSON By Example
Stefanie Janine Stölting
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8
宇 傅
 
What Are For Expressions in Scala?
What Are For Expressions in Scala?What Are For Expressions in Scala?
What Are For Expressions in Scala?
BoldRadius Solutions
 
The PostgreSQL JSON Feature Tour
The PostgreSQL JSON Feature TourThe PostgreSQL JSON Feature Tour
The PostgreSQL JSON Feature Tour
Stefanie Janine Stölting
 
NoSQL as Not Only SQL (FrOSCon 11)
NoSQL as Not Only SQL (FrOSCon  11)NoSQL as Not Only SQL (FrOSCon  11)
NoSQL as Not Only SQL (FrOSCon 11)
Stefanie Janine Stölting
 
Advance sql session - strings
Advance sql  session - stringsAdvance sql  session - strings
Advance sql session - strings
Eyal Trabelsi
 
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
Olga Lavrentieva
 

Similar to Querier – simple relational database access (10)

Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
 
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise GrandjoncAmazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
 
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
 
JSON By Example
JSON By ExampleJSON By Example
JSON By Example
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8
 
What Are For Expressions in Scala?
What Are For Expressions in Scala?What Are For Expressions in Scala?
What Are For Expressions in Scala?
 
The PostgreSQL JSON Feature Tour
The PostgreSQL JSON Feature TourThe PostgreSQL JSON Feature Tour
The PostgreSQL JSON Feature Tour
 
NoSQL as Not Only SQL (FrOSCon 11)
NoSQL as Not Only SQL (FrOSCon  11)NoSQL as Not Only SQL (FrOSCon  11)
NoSQL as Not Only SQL (FrOSCon 11)
 
Advance sql session - strings
Advance sql  session - stringsAdvance sql  session - strings
Advance sql session - strings
 
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
 

More from ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
ESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
ESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
ESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
ESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
ESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
ESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
ESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
ESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
ESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
ESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
ESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
ESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
ESUG
 

More from ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Recently uploaded

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

Querier – simple relational database access

  • 2. What is Querier?  A library for querying relational databases.  Focused on simplicity.  Heavily inspired by NotORM (http://www.notorm.com/).
  • 3. Why? Accessing a relational database in Pharo:
  • 4. Why? Accessing a relational database in Pharo: 1) Write SQL by hand.
  • 5. Why? Accessing a relational database in Pharo: 1) Write SQL by hand. 2) Use an object-relational mapper (GLORP).
  • 6. Why? Accessing a relational database in Pharo: 1) Write SQL by hand. 1.5) Use Querier. 2) Use an object-relational mapper (GLORP).
  • 7. Database structure Primary Key Column id Foreign Key Column {table}_id Table Name {table}
  • 8. Setup | driver structure db | driver := "…". structure := QRRConventionalStructure new. db := Querier withDriver: driver structure: structure
  • 9. Accessing a table db table: #song "or use a shortcut:" db song song id Integer, Primary Key title Varchar length Integer album_id Integer, Foreign Key
  • 10. Accessing a table db table: #song "or use a shortcut:" db song SELECT * FROM song
  • 11. Accessing a table db song do: [ :row | Transcript show: row title; cr ]
  • 12. Two principles 1) A table is a collection of rows. 2) A row is a dictionary of values.
  • 13. WHERE db song select: [ :row | (row length >= 180) & (row length <= 300) ] SELECT * FROM song WHERE length >= 180 AND length <= 300
  • 14. WHERE db song select: [ :row | (row length >= 180) & (row length <= 300) ] Udo Schneider: BlockTranslators - parsing magic http://readthesourceluke.blogspot.com/2014/09/ block-translators-parsing-magic.html
  • 15. ORDER BY db song sorted: [ :a :b | a length < b length ] SELECT * FROM song ORDER BY length ASC
  • 16. LIMIT and OFFSET (db song sorted: [ :a :b | a length < b length ]) first: 10 SELECT * FROM song ORDER BY length ASC LIMIT 10
  • 17. LIMIT and OFFSET (db song sorted: [ :a :b | a length < b length ]) allButFirst: 10 SELECT * FROM song ORDER BY length ASC OFFSET 10
  • 18. Selecting a single row row := db song detect: [ :row | row id = 123 ] SELECT * FROM song WHERE id = 123 LIMIT 1
  • 19. Selecting by primary key row := db song at: 123 SELECT * FROM song WHERE id = 123 LIMIT 1
  • 20. Selecting by primary key row := db song at: 123 SELECT * FROM song WHERE id = 123 LIMIT 1
  • 21. Aggregations db song average: [ :row | row length ] db song average: #length SELECT AVG(length) FROM song
  • 22. Enumerating the result db song collect: [ :row | row title ] db song do: [ :row | Transcript show: row title; cr ] db song size
  • 23. Accessing related tables song id Integer, Primary Key title Varchar length Integer album_id Integer, Foreign Key album id Integer, Primary Key title Varchar
  • 24. Accessing related tables db song select: [ :row | row album name = 'Unknown Album' ] song id Integer, Primary Key title Varchar length Integer album_id Integer, Foreign Key album id Integer, Primary Key title Varchar
  • 25. Accessing related tables db song select: [ :row | row album name = 'Unknown Album' ] SELECT * FROM song LEFT JOIN album ON song.album_id = album.id WHERE album.name = 'Unknown Album'
  • 26. Accessing related tables db song select: [ :row | row album name = 'Unknown Album' ] SELECT * FROM song LEFT JOIN album ON song.album_id = album.id WHERE album.name = 'Unknown Album'
  • 27. Accessing related tables db song select: [ :row | row album artist name = 'Unknown Artist' ] SELECT * FROM song LEFT JOIN album ON song.album_id = album.id LEFT JOIN artist ON album.artist_id = artist.id WHERE artist.name = 'Unknown Artist'
  • 28. Accessing related tables db song do: [ :row | Transcript show: row album name ]
  • 29. Accessing related tables db song do: [ :row | Transcript show: row album name ] 1) SELECT * FROM song
  • 30. Accessing related tables db song do: [ :row | Transcript show: row album name ] 1) SELECT * FROM song
  • 31. Accessing related tables db song do: [ :row | Transcript show: row album name ] 1) SELECT * FROM song 2) SELECT * FROM album WHERE id IN (1, 2, 3, …)
  • 32. Accessing related tables song id Integer, Primary Key title Varchar length Integer album_id Integer, Foreign Key album id Integer, Primary Key title Varchar
  • 33. The opposite direction db album do: [ :row | row songCollection do: [ :song | Transcript show: song name; cr ] ] song id Integer, Primary Key title Varchar length Integer album_id Integer, Foreign Key album id Integer, Primary Key title Varchar
  • 34. The opposite direction db album do: [ :row | row songCollection do: [ :song | Transcript show: song name; cr ] ] 1) SELECT * FROM album
  • 35. The opposite direction db album do: [ :row | row songCollection do: [ :song | Transcript show: song name; cr ] ] 1) SELECT * FROM album 2) SELECT * FROM song WHERE album_id IN (1, 2, 3, …)
  • 36. UPDATE db song do: [ :row | row length: row length + 10. row save ] 1) SELECT * FROM song 2) UPDATE song SET length = 325 WHERE id = 1 3) UPDATE song SET length = 648 WHERE id = 2 4) … and many more
  • 37. Better UPDATE db song update: [ :row | row length: row length + 10 ] UPDATE song SET length = length + 10
  • 38. Better UPDATE (db song select: [ :row | row length < 180 ]) update: [ :row | row length: row length + 10 ] UPDATE song SET length = length + 10 WHERE length < 180
  • 39. DELETE (db song select: [ :row | row length < 180 ]) removeAll db song delete: [ :row | row length < 180 ] DELETE FROM song WHERE length < 180
  • 40. INSERT | row | row := db song new. row title: 'New Song'. row length: 316. row album: (db album detect: [ :row | row album name = 'Unknown Album' ]). row save. Transcript show: row id
  • 41. Current Status  A proof-of-concept for Pharo + Postgres.  Working on polishing all features + querying other RDBMS through Garage (https://guillep.github.io/DBXTalk/garage/).
  • 42. Future work  Add ORM-like features (instantiate your entity classes instead of dictionaries).  Add at least partial support for non-relational databases (like MongoDB).
  • 44. Thank you for your attention! http://querier.xmb.cz/