Go - SQL Databases in Golang with the database/sql package
BugBytes BugBytes
31K subscribers
33,414 views
865

 Published On Sep 4, 2023

Playlist ▶️:    • Go Programming  

In this video, we'll look at the database/sql package in Go, and how to use this package to work with SQL relational databases.

We will look at how to connect to a PostgreSQL database running in a Docker container, and how to create tables, insert data and query data using the Go database package. We'll look at the difference between three database functions:

db.Exec()
db.Query()
db.QueryRow()

And will outline when to use each.

Playlist:
   • Go Programming  

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
https://ko-fi.com/bugbytes

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
00:49 Setting up PostgreSQL Docker container
04:20 Connecting to Postgres from Go app with sql.Open
09:36 Creating table in database with CREATE TABLE SQL
14:28 Inserting data into table with Go
22:02 Querying single row with db.QueryRow()
26:21 Querying for multiple rows with db.Query()

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: https://bugbytes.io/posts/
👾 Github: https://github.com/bugbytes-io
🐦 Twitter:   / bugbytesio  

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Go database/sql package: https://pkg.go.dev/database/sql
Go Postgres driver pq: https://pkg.go.dev/github.com/lib/pq

#golang #webdevelopment #database #sql

show more

Share/Embed