SQL Query Strategy for complex structs

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • sqlc

    Generate type-safe code from SQL

  • https://github.com/kyleconroy/sqlc will generate Go structs for inputs & outputs of Postgres queries, that'll get you type safety.

  • pgx

    PostgreSQL driver and toolkit for Go

  • Hi fellow Gophers, I have a question involving both (Postgre-) SQL and Go. For a hobby project, I so far have used plain SQL with some additional filtering logic and pgx to to retrieve rows and mapped these rows to structs manually. This worked quite well as the types were rather simple and only involved 1-3 SQL tables.However, I now do have a more complex struct type with 10 underlying SQL tables including some nested structs and slices. I feel that my prior strategy of plain SQL query strings doesn't scale to retrieve data from the SQL DB even for this moderatly complex struct type.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • jet

    Type safe SQL builder with code generation and automatic query result data mapping

  • Check https://github.com/go-jet/jet. It supports arbitrary nested structs. Also it works well with pgx, as a driver.

  • bun

    SQL-first Golang ORM (by uptrace)

  • bun and go-pg both seem to work fairly well for these kind of purposes.

  • go-pg

    Golang ORM with focus on PostgreSQL features and performance

  • bun and go-pg both seem to work fairly well for these kind of purposes.

  • SQLBoiler

    Generate a Go ORM tailored to your database schema.

  • didn’t know jet, any major difference with https://github.com/volatiletech/sqlboiler?

  • scany

    Library for scanning data from a database into Go structs and more

  • I like to use pgxscan from https://github.com/georgysavva/scany

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • go-formatter

    A curated list of awesome Go frameworks, libraries and software

  • https://github.com/avelino/awesome-go is good place to start.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts