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

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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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 🐠