Learning Golang: Relational Databases - Introduction to database/sql

preview_player
Показать описание
Let's learn about accessing Relational Databases in Go/Golang using the standard library, specifically using "database/sql" and a concrete driver, which in this case is going to be "pgx".

This first episode introduces you to "database/sql" the default way to access Relational Databases in Go/Golang, I will cover the basic instructions to:
* Open a Connection using "sql.Open"
* Ping the connection using "db.PingContext" (also "db.Ping" works)
* Query one row using "db.QueryRowContext" (also "db.QueryRow" works)
* Query multiple rows using "db.QueryContext" (also "db.Query works)
* Inserting records using "db.ExecContext" (also "db.Exec" works)

This is the foundation of future videos that will come, also a few things to keep in mind regarding Relational Databases in Go/Golang:
* Go/Golang does not provide any official drivers, however it provides database/sql
* Typically drivers implement only that interface, but some like pgx add their own
* Nowadays we should be using the context-like methods when accessing databases

== Relevant links

== All Go/Golang video series covered

== Socials

00:00 - Start
02:34 - Importing pgx for PostgreSQL in Golang
07:00 - Connecting to PostgreSQL using pgx in Golang
11:10 - Selecting row in PostgreSQL using pgx in Golang
15:20 - Inserting records in PostgreSQL using pgx in Golang
20:50 - Selecting multiple rows in PostgreSQL using pgx in Golang
24:40 - Conclusions

---

Who am I:

Hello👋🏼! I'm Mario, a Hands-on Software Architect and Lead Backend Engineer with more than 16 years of professional experience building all kinds of software including on-premise Industrial Automation Systems, Linux Accessibility Desktop and Browser Components as well as Distributed Advertising Microservices.

Every week I will share with you different topics I've learned while working for small startups and large companies including the processes I've followed over the years for successfully delivering complex enterprise systems from start to end.

Subscribe if you like Software Development, Software Architecture and Systems Design!

Keep it up. Don't give up!

#golang #tutorial #databases

=== Our Vlog Channel

=== Our affiliate links below

DISCLAIMER: Some of the links shared in the description are affiliate links. As a member of these affiliate programs, I earn a small commission from your purchases at no additional cost to you. I appreciate your support! 💖
Рекомендации по теме
Комментарии
Автор

Nice tip for using url.URL and converting to a string rather than directly creating a string

farzadmf
Автор

Really cool videos. My question will be kinda bad one because I dont understand this enough, but if I use pgx I dont need to use GORM or those are totally unrelated things?

matkomilic
Автор

vc é brasileiro? achei o sotaque mto parecido kkk

EduardoTorresMedeirosdeAraujo
Автор

The most infuriating thing as a new learning of golang is how do you deal with nullables from a db? I always get a scan error and have worked around this by using string.nullable and then checking if valid. Seems like lot of if conditions tho with multiple columns. Any better way?

dawizze
Автор

Hello sir,
Can you please start a data structures and algorithms series

bavan
Автор

yeah this code shows we less tedious error handling in Go :) On the one hand, this is simple, yeah, but the repetition of this trivial stuff... not fun.

adicide
visit shbcf.ru