SQLC in Go - Auto-Generating Database Code in Golang
Vložit
- čas přidán 19. 06. 2024
- Playlist ▶️: • Go Programming
In this video, we'll look at the SQLC package for auto-generating Go code, based on SQL queries that we define in our application codebase.
☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
ko-fi.com/bugbytes
📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
00:31 SQLC Overview
02:56 SQLC with PostgreSQL
03:41 Adding sqlc.yaml configuration file
05:11 Adding schema.sql file to define database schema
06:06 Adding query.sql file to define SQL queries
09:50 Generating Go code with sqlc generate
13:32 Creating PostgreSQL database
15:21 Querying database with generated Go code
22:52 Generating code with SQLC to add new records to a table
26:51 Generating code with SQLC to delete record from table
28:41 Generating code with SQLC for basic aggregation
𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: bugbytes.io/posts/
👾 Github: github.com/bugbytes-io
🐦 Twitter: / bugbytesio
📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
SQLC: sqlc.dev/
SQL with PostgreSQL: docs.sqlc.dev/en/latest/tutor...
pq driver: github.com/lib/pq
Go database/sql package: pkg.go.dev/database/sql
#golang #webdevelopment #database #sql
Aside the great content, you explain what you do and why you do, and do not expect that the viewer already knows (17:09, you enter the \q command and explains why). This makes a huge difference for beginners. Thank you, and congratulations.
Thanks a lot, glad to hear that this is helpful! Thanks for the nice comment!
I'm just learning Go and finding sql tools. This is the video for me. Great content.
Thanks a lot, glad you liked it!
New gist everyday makes me exploring. Thanks very much
Thanks as always!
very helpful! struggled to understand the documentation. you led me in the right direction. thank you.
Thanks a lot!
Brother, Your an angel. I was exhausted writing all the sql, preparing the statments and the scanning it was just exhausting. You saved me alot of time. Thanks alot
Awesome - glad to hear it! Thanks a lot for the comment!
That's amazing. Thanks for sharing.
No worries, thanks for watching!
Great person, great content.
Thanks a lot!
Thank you 👍🙏
Thanks for watching!
Awesome!! Thank You!!
Thanks for watching!
Go Content🎉
Damn im using that already
More Go coming up soon!
Do you have any intention building big projects using htmx + go + sqlc in the future?
Yes, in this summer I want to release a series on this, but it is still in progress!
@@bugbytes3923 I know that you have many running projects so you're quiet busy. Recently, I've been building a toy project using these tech stacks for learning purpose. If you need an assistant/teammate, feel free to contact me. I'm happy to support you to make the project better
tried using it in a CRUD heavy app, it has certain quirks on "case when" statements as well as when using the "sqlc.narg" macro on enum columns. "sqlc.slice" macro is also not wholly compatible where arrays can be passed in postgresql. Apart from that it was adequate per my experience.
Interesting, thanks for sharing. I’ve not tried sqlc with CASE statements to be honest, so I’ve never experienced that.
@@bugbytes3923 yeah, wanted to do partial updates on some entities. It is aa very nice compiler all in all, tnx for the video
would love to see you cover the Ent package for Go as alternative to SQLC !
You don't need frameworks in Go
5:01 why we don't need that?
I'd like to see an example getting data from join sql to two structs (without Gorm). Has anyone already tried that?