Things I wish I knew about sqlc

A while back, I was able to convince my team to use sqlc. I already used it on some personal projects, but those weren’t complex queries whatsoever. Using sqlc in a commercial setting allowed me to see some of its limitations, or perhaps the shift in the paradigm that you experience while using it. In this article, I want to show you some hacks I found to be useful. Configuring the project First things first, if you have a lot of packages, here’s a cool trick on how to make sure similar config is reused accross different queries: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 --- version: "2" sql: - engine: postgresql queries: internal/account/repository/query.sql schema: &schema db/postgres/migrations gen: go: &go_gen_opts package: repository out: internal/account/repository emit_enum_valid_method: true emit_all_enum_values: true emit_sql_as_comment: true omit_unused_structs: true overrides: # numeric is decimal.Decimal - db_type: pg_catalog.numeric go_type: import: github.com/shopspring/decimal type: Decimal - db_type: pg_catalog.numeric go_type: import: github.com/shopspring/decimal type: Decimal nullable: true # nullable decimal is valid too, need to add it separately - engine: postgresql queries: internal/order/repository/query.sql schema: *schema gen: go: <<: *go_gen_opts out: internal/order/repository overrides: - column: "order.currency" go_type: import: "gitlab.com/letssay/our/custom/moneylib" type: "Currency" ...

February 12, 2025 · 5 min · Zemfira

Go PGO Workshop

Today I invite you to do a hands-on exercise and check out how PGO works in Golang. This demo is based on this repo, which I encourage you to clone: fira.curie/go-pgo-app. Prerequisites You would need the following tools installed on your machine: Docker or Podman - if you’re using podman, you need to enable insecure registry (see below). kind to provision a local k8s cluster in a container. Helm - for deploying our app, Pyroscope, and optionally Grafana. ohayou - for simulating production load. profilecli - for collecting profile data from the app. Assumptions I assume that you know how to work with git, bash, kubernetes, helm, and docker. If you don’t, you can check out the official documentation and helm documentation. ...

September 21, 2024 · 5 min · Zemfira