SlideShare a Scribd company logo
1 of 36
1
Davide Imola • Ludovico Russo
Level UP your
RDBMS
Productivity
in GO
2
Davide Imola
Software Engineer @ RedCarbon
CM @ Schrödinger Hat
3
Ludovico Russo
VP of Engineering @ RedCarbon
4
A little Disclaimer about this talk
All the things inside this talk are highly opinionated
and they are not a standard. They are simply things we
have discovered by working with DataBases and Go.
Examples are in PostgreSQL, but all the stuff works for
other SQL DBs.
No DB have been harmed for the purpose of this talk,
but a couple was truncated 🤫
5
Davide Imola • Ludovico Russo
The Actual
Status
What might go(lang) wrong this time?
6
Let's be honest!
Who loves writing again and
again all this code?
No, Copilot (or any generative
AI 🤖) is not the answer.
Handling the DB Code
Davide Imola • Ludovico Russo
7
Finding hidden errors in SQL
Davide Imola • Ludovico Russo
8
SQL Injection
Davide Imola • Ludovico Russo
5 OR 1=1
9
ALTER TABLE users ADD
column email varchar;
error: sql: expected 3 destination arguments
in Scan, not 2
Code and DB out of sync
Davide Imola • Ludovico Russo
10
The problem is always between
the chair and the monitor
Manual type sync and possible downtimes
Davide Imola • Ludovico Russo
11
You don't want to bring up a
DB? Ok let's mock it.
But, if you decide to mock
db.Query or all the ListUsers
function you can't see the bug
inside this Query.
Automated Testing (Why mocking your DB will make you cry 😭)
Davide Imola • Ludovico Russo
12
● SQL-first paradigm
● Migrations
● Test Containers (or Docker Test)
So… what we are covering today…
Davide Imola • Ludovico Russo
13
Davide Imola • Ludovico Russo
SQL-first
Compile SQL to type-safe code
14
1. Write a SQL Query
2. Run a tool which generates type-safe code from
your queries and schema
3. Enjoy writing your application by calling the
generated methods!
SQL-first
Davide Imola • Ludovico Russo
15
● ORM (Object-Relational Mapping)
Programming technique that enables seamless
interaction between object-oriented code and
relational databases
● Query Builders
Tools or libraries that provide a programmatic and
often fluent interface for generating db queries
Other approaches
Davide Imola • Ludovico Russo
16
● You don't have the chance to use SQL
● We don't like so much the APIs built for Go
● You can't use all the DBs features (e.g., JSONB
filtering in Postgres)
Why we don't like ORM in Go?
Davide Imola • Ludovico Russo
17
● Not type-safe
● Mixed approach between SQL and Code that can be
complex to read and understand
● You still need to map data and maintain the types
manually
Why we don't like Query Builders?
Davide Imola • Ludovico Russo
18
SQL-first vs ORM vs Query Builders
Davide Imola • Ludovico Russo
SQL First ORM Query Builder
Type-safe Code ✅ ✅ ❌
Learn SQL ✅ ❌ ✅
Protect from SQL Injection ✅ ✅ ❌
All DB features ✅ ❌ ✅
Clean Api ✅ ❌ (in Go) ❌
Code Generation 🤖 ✅ ❌ ❌
We like it 🤫 ✅✅✅✅✅✅✅ ❌ ❌
19
SQL-first may be an interesting approach. But it has
major outsides when it comes to complex queries.
In this case using an ORM/Query Builders as a fallback
for some specific cases might work very well!
Don't hate ORM or Query Builders! Use it as fallback!
Davide Imola • Ludovico Russo
20
Davide Imola • Ludovico Russo
Migrations
dbmate up your DB!
21
● Write your migration in SQL code
○ UP: queries to run for applying some changes to a DB
○ DOWN: if you want to revert them
● Commit in your migrations
● Run it
○ Manullay
○ In a Job
○ In your CD pipeline
● That’s all
UP and DOWN your DB automatically
Davide Imola • Ludovico Russo
22
A technique to avoid breaking DB interactions between
releases.
Rules:
● Automated testing
● Small migrations
● Breaking changes introduced in two steps
Evolutionary Database Design
Davide Imola • Ludovico Russo
23
Davide Imola • Ludovico Russo
Test Containers
(or Docker Test)
Dockerize your Integration tests
24
Containerize your Infrastructure into Testing
Davide Imola • Ludovico Russo
25
Davide Imola • Ludovico Russo
Demo Time
May the Demo God be with US ❤️
26
Davide Imola • Ludovico Russo
The New Status
What might we have fixed?
27
Let's be honest!
Who loves writing again and
again all this code?
No, Copilot (or any generative
AI 🤖) is not the answer.
Handling the DB Code
Davide Imola • Ludovico Russo
✅
28
Errors in SQL syntax
Davide Imola • Ludovico Russo
✅
29
SQL Injection
Davide Imola • Ludovico Russo
5 OR 1=1
✅
30
ALTER TABLE users ADD
column email varchar;
error: sql: expected 3 destination arguments
in Scan, not 2
Code and DB out of sync
Davide Imola • Ludovico Russo
✅
31
The problem is always between
the chair and the monitor
Manual type sync and possible downtimes
Davide Imola • Ludovico Russo
✅
32
You don't want to bring up a
DB? Ok let's mock it.
But, if you decide to mock
db.Query or all the ListUsers
function you can't see the bug
inside this Query.
Automated Testing (Why mocking your DB will make you cry 😭)
Davide Imola • Ludovico Russo
✅
33
Open Source Day
7-8 March 2024 @ Florence
34
Ludovico Russo
in/ludusrusso
@ludusrusso
Davide Imola
in/davideimola
@davideimola
@davideimola@fosstdon.org
35
Q&A
Don't be shy! We don't bite!
Please consider to give us a
feedback!
42
So long, and
Thanks for all
the 🐠

More Related Content

Similar to Level UP your RDBMS Productivity in GO

[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...Ambassador Labs
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database RefactoringAnton Keks
 
A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5SSW
 
Domain Specific Languages
Domain Specific LanguagesDomain Specific Languages
Domain Specific Languageselliando dias
 
Optimizing Browser Rendering
Optimizing Browser RenderingOptimizing Browser Rendering
Optimizing Browser Renderingmichael.labriola
 
Introducing systems analysis, design & development Concepts
Introducing systems analysis, design & development ConceptsIntroducing systems analysis, design & development Concepts
Introducing systems analysis, design & development ConceptsShafiul Azam Chowdhury
 
Dell Webinar 2014-06-24: Subqueries For Superheroes
Dell Webinar 2014-06-24: Subqueries For SuperheroesDell Webinar 2014-06-24: Subqueries For Superheroes
Dell Webinar 2014-06-24: Subqueries For SuperheroesTracy McKibben
 
Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)Guy Harrison
 
PostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real DifferencesPostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real DifferencesAll Things Open
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid WorldTanel Poder
 
Python performance profiling
Python performance profilingPython performance profiling
Python performance profilingJon Haddad
 
Introducing Systems Analysis Design Development
Introducing Systems Analysis Design DevelopmentIntroducing Systems Analysis Design Development
Introducing Systems Analysis Design Developmentbsadd
 
Snowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD PipelinesSnowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD PipelinesDrew Hansen
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...panagenda
 
Coding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper ElementaryCoding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper ElementaryBrittany Pike
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
 

Similar to Level UP your RDBMS Productivity in GO (20)

[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database Refactoring
 
A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5
 
Domain Specific Languages
Domain Specific LanguagesDomain Specific Languages
Domain Specific Languages
 
Optimizing Browser Rendering
Optimizing Browser RenderingOptimizing Browser Rendering
Optimizing Browser Rendering
 
Introducing systems analysis, design & development Concepts
Introducing systems analysis, design & development ConceptsIntroducing systems analysis, design & development Concepts
Introducing systems analysis, design & development Concepts
 
Dell Webinar 2014-06-24: Subqueries For Superheroes
Dell Webinar 2014-06-24: Subqueries For SuperheroesDell Webinar 2014-06-24: Subqueries For Superheroes
Dell Webinar 2014-06-24: Subqueries For Superheroes
 
Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)
 
PostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real DifferencesPostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real Differences
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid World
 
Python performance profiling
Python performance profilingPython performance profiling
Python performance profiling
 
Introducing Systems Analysis Design Development
Introducing Systems Analysis Design DevelopmentIntroducing Systems Analysis Design Development
Introducing Systems Analysis Design Development
 
Oracle's Take On NoSQL
Oracle's Take On NoSQLOracle's Take On NoSQL
Oracle's Take On NoSQL
 
Snowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD PipelinesSnowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD Pipelines
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
 
CQRS recepies
CQRS recepiesCQRS recepies
CQRS recepies
 
Coding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper ElementaryCoding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper Elementary
 
Code detox
Code detoxCode detox
Code detox
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

Recently uploaded

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Level UP your RDBMS Productivity in GO

  • 1. 1 Davide Imola • Ludovico Russo Level UP your RDBMS Productivity in GO
  • 2. 2 Davide Imola Software Engineer @ RedCarbon CM @ Schrödinger Hat
  • 3. 3 Ludovico Russo VP of Engineering @ RedCarbon
  • 4. 4 A little Disclaimer about this talk All the things inside this talk are highly opinionated and they are not a standard. They are simply things we have discovered by working with DataBases and Go. Examples are in PostgreSQL, but all the stuff works for other SQL DBs. No DB have been harmed for the purpose of this talk, but a couple was truncated 🤫
  • 5. 5 Davide Imola • Ludovico Russo The Actual Status What might go(lang) wrong this time?
  • 6. 6 Let's be honest! Who loves writing again and again all this code? No, Copilot (or any generative AI 🤖) is not the answer. Handling the DB Code Davide Imola • Ludovico Russo
  • 7. 7 Finding hidden errors in SQL Davide Imola • Ludovico Russo
  • 8. 8 SQL Injection Davide Imola • Ludovico Russo 5 OR 1=1
  • 9. 9 ALTER TABLE users ADD column email varchar; error: sql: expected 3 destination arguments in Scan, not 2 Code and DB out of sync Davide Imola • Ludovico Russo
  • 10. 10 The problem is always between the chair and the monitor Manual type sync and possible downtimes Davide Imola • Ludovico Russo
  • 11. 11 You don't want to bring up a DB? Ok let's mock it. But, if you decide to mock db.Query or all the ListUsers function you can't see the bug inside this Query. Automated Testing (Why mocking your DB will make you cry 😭) Davide Imola • Ludovico Russo
  • 12. 12 ● SQL-first paradigm ● Migrations ● Test Containers (or Docker Test) So… what we are covering today… Davide Imola • Ludovico Russo
  • 13. 13 Davide Imola • Ludovico Russo SQL-first Compile SQL to type-safe code
  • 14. 14 1. Write a SQL Query 2. Run a tool which generates type-safe code from your queries and schema 3. Enjoy writing your application by calling the generated methods! SQL-first Davide Imola • Ludovico Russo
  • 15. 15 ● ORM (Object-Relational Mapping) Programming technique that enables seamless interaction between object-oriented code and relational databases ● Query Builders Tools or libraries that provide a programmatic and often fluent interface for generating db queries Other approaches Davide Imola • Ludovico Russo
  • 16. 16 ● You don't have the chance to use SQL ● We don't like so much the APIs built for Go ● You can't use all the DBs features (e.g., JSONB filtering in Postgres) Why we don't like ORM in Go? Davide Imola • Ludovico Russo
  • 17. 17 ● Not type-safe ● Mixed approach between SQL and Code that can be complex to read and understand ● You still need to map data and maintain the types manually Why we don't like Query Builders? Davide Imola • Ludovico Russo
  • 18. 18 SQL-first vs ORM vs Query Builders Davide Imola • Ludovico Russo SQL First ORM Query Builder Type-safe Code ✅ ✅ ❌ Learn SQL ✅ ❌ ✅ Protect from SQL Injection ✅ ✅ ❌ All DB features ✅ ❌ ✅ Clean Api ✅ ❌ (in Go) ❌ Code Generation 🤖 ✅ ❌ ❌ We like it 🤫 ✅✅✅✅✅✅✅ ❌ ❌
  • 19. 19 SQL-first may be an interesting approach. But it has major outsides when it comes to complex queries. In this case using an ORM/Query Builders as a fallback for some specific cases might work very well! Don't hate ORM or Query Builders! Use it as fallback! Davide Imola • Ludovico Russo
  • 20. 20 Davide Imola • Ludovico Russo Migrations dbmate up your DB!
  • 21. 21 ● Write your migration in SQL code ○ UP: queries to run for applying some changes to a DB ○ DOWN: if you want to revert them ● Commit in your migrations ● Run it ○ Manullay ○ In a Job ○ In your CD pipeline ● That’s all UP and DOWN your DB automatically Davide Imola • Ludovico Russo
  • 22. 22 A technique to avoid breaking DB interactions between releases. Rules: ● Automated testing ● Small migrations ● Breaking changes introduced in two steps Evolutionary Database Design Davide Imola • Ludovico Russo
  • 23. 23 Davide Imola • Ludovico Russo Test Containers (or Docker Test) Dockerize your Integration tests
  • 24. 24 Containerize your Infrastructure into Testing Davide Imola • Ludovico Russo
  • 25. 25 Davide Imola • Ludovico Russo Demo Time May the Demo God be with US ❤️
  • 26. 26 Davide Imola • Ludovico Russo The New Status What might we have fixed?
  • 27. 27 Let's be honest! Who loves writing again and again all this code? No, Copilot (or any generative AI 🤖) is not the answer. Handling the DB Code Davide Imola • Ludovico Russo ✅
  • 28. 28 Errors in SQL syntax Davide Imola • Ludovico Russo ✅
  • 29. 29 SQL Injection Davide Imola • Ludovico Russo 5 OR 1=1 ✅
  • 30. 30 ALTER TABLE users ADD column email varchar; error: sql: expected 3 destination arguments in Scan, not 2 Code and DB out of sync Davide Imola • Ludovico Russo ✅
  • 31. 31 The problem is always between the chair and the monitor Manual type sync and possible downtimes Davide Imola • Ludovico Russo ✅
  • 32. 32 You don't want to bring up a DB? Ok let's mock it. But, if you decide to mock db.Query or all the ListUsers function you can't see the bug inside this Query. Automated Testing (Why mocking your DB will make you cry 😭) Davide Imola • Ludovico Russo ✅
  • 33. 33 Open Source Day 7-8 March 2024 @ Florence
  • 35. 35 Q&A Don't be shy! We don't bite! Please consider to give us a feedback!
  • 36. 42 So long, and Thanks for all the 🐠