SQLC in Go - Auto-Generating Database Code in Golang

Sdílet
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

Komentáře • 32

  • @oerickmuller
    @oerickmuller Před 3 měsíci +2

    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.

    • @bugbytes3923
      @bugbytes3923  Před 3 měsíci

      Thanks a lot, glad to hear that this is helpful! Thanks for the nice comment!

  • @keenoogodlike
    @keenoogodlike Před 3 měsíci +1

    I'm just learning Go and finding sql tools. This is the video for me. Great content.

  • @AmoahDevLabs
    @AmoahDevLabs Před 3 měsíci +1

    New gist everyday makes me exploring. Thanks very much

  • @Charly9K
    @Charly9K Před 2 měsíci

    very helpful! struggled to understand the documentation. you led me in the right direction. thank you.

  • @rootdefault6263
    @rootdefault6263 Před měsícem

    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

    • @bugbytes3923
      @bugbytes3923  Před měsícem

      Awesome - glad to hear it! Thanks a lot for the comment!

  • @plashless3406
    @plashless3406 Před 3 měsíci +2

    That's amazing. Thanks for sharing.

  • @AliHassan-wc6nb
    @AliHassan-wc6nb Před 3 měsíci +2

    Great person, great content.

  • @devgauravjatt
    @devgauravjatt Před 23 dny +2

    Thank you 👍🙏

  • @EneasHunguana
    @EneasHunguana Před 2 měsíci

    Awesome!! Thank You!!

  • @deado7282
    @deado7282 Před 3 měsíci +3

    Go Content🎉

  • @HoangVo7
    @HoangVo7 Před 3 měsíci +1

    Do you have any intention building big projects using htmx + go + sqlc in the future?

    • @bugbytes3923
      @bugbytes3923  Před 3 měsíci +1

      Yes, in this summer I want to release a series on this, but it is still in progress!

    • @HoangVo7
      @HoangVo7 Před 3 měsíci

      @@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

  • @AbegazNap
    @AbegazNap Před 3 měsíci +3

    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.

    • @bugbytes3923
      @bugbytes3923  Před 3 měsíci +1

      Interesting, thanks for sharing. I’ve not tried sqlc with CASE statements to be honest, so I’ve never experienced that.

    • @AbegazNap
      @AbegazNap Před 3 měsíci

      @@bugbytes3923 yeah, wanted to do partial updates on some entities. It is aa very nice compiler all in all, tnx for the video

  • @x53LL33
    @x53LL33 Před 3 měsíci

    would love to see you cover the Ent package for Go as alternative to SQLC !

    • @brunokingz
      @brunokingz Před 3 měsíci +1

      You don't need frameworks in Go

  • @ardawanx
    @ardawanx Před 10 dny

    5:01 why we don't need that?

  • @arilson.santos
    @arilson.santos Před měsícem

    I'd like to see an example getting data from join sql to two structs (without Gorm). Has anyone already tried that?