SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
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/

Weitere ähnliche Inhalte

Was ist angesagt?

Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commandsswtjerin4u
 
Gnome terminal basics
Gnome terminal basicsGnome terminal basics
Gnome terminal basicsKamrul Hasan
 
Switching from java to groovy
Switching from java to groovySwitching from java to groovy
Switching from java to groovyPaul Woods
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Noé 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 commandsshekhar70
 
Mkscript sh
Mkscript shMkscript sh
Mkscript shBen 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
 

Was ist angesagt? (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
 

Ähnlich wie 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 .pdffazanmobiles
 
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 GrandjoncCitus 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.pdfarenamobiles123
 
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
 
Advance sql session - strings
Advance sql  session - stringsAdvance sql  session - strings
Advance sql session - stringsEyal Trabelsi
 
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»Olga Lavrentieva
 

Ähnlich wie 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»
 

Mehr von 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 programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
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 RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
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 resultsESUG
 
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 6ESUG
 
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 GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
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 ModesESUG
 
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 ReportESUG
 
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 APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
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 CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
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 JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
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 TransformationsESUG
 

Mehr von 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
 

Kürzlich hochgeladen

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

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/