Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free. Learn more →
Similar projects and alternatives to pggen
Generate type-safe code from SQL
Generate a Go ORM tailored to your database schema.
Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.
A database first code generator focused on postgres (by opendoor)
A type safe SQL template library for C++
SqlKata Query Builder
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
Parse SQL files with multiple named queries and automatically prepare and scan them into structs.
lightweight, idiomatic and composable router for building Go HTTP services
Access the most powerful time series database as a service. Ingest, store, & analyze all types of time series data in a fully-managed, purpose-built database. Keep data forever with low-cost storage and superior data compression.
The fantastic ORM library for Golang, aims to be developer friendly
Arbitrary-precision fixed-point decimal numbers in go
The Go programming language
Structured, pluggable logging for Go.
Pure Go Postgres driver for database/sql
PostgreSQL driver and toolkit for Go
Turn Clojure data structures into SQL
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
general purpose extensions to golang's database/sql
An entity framework for Go
Database migrations. CLI and Golang library.
Streaming replication for SQLite.
Zero Allocation JSON Logger
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
pggen reviews and mentions
Ask HN: ORM or Native SQL?
10 projects | news.ycombinator.com | 6 Jan 2023
Cornucopia is neat. I wrote a similar library in Go  so I'm very interested in comparing design decisions.
The pros of the generated code per query approach:
- App code is coupled to query outputs and inputs (an API of sorts), not database tables. Therefore, you can refactor your DB without changing app code.
- Real SQL with the full breadth of DB features.
- Real type-checking with what the DB supports.
- Type mapping is surprisingly hard to get right, especially with composite types and arrays and custom type converters. For example, a query might return multiple jsonb columns but the app code wants to parse them into different structs.
- Dynamic queries don't work with prepared statements. Prepared statements only support values, not identifiers or scalar SQL sub-queries, so the codegen layer needs a mechanism to template SQL. I haven't built this out yet but would like to.
What are the things with Go that have made you wish you were back in Spring/.NET/Django etc?
3 projects | reddit.com/r/golang | 12 Dec 2021
pggen is another fantastic library in this genre, which specifically targets postgres. It is driven by pgx. Can not recommend enough.
Exiting the Vietnam of Programming: Our Journey in Dropping the ORM (In Golang)
7 projects | news.ycombinator.com | 26 Nov 2021
> Do you write out 120 "INSERT" statements, 120 "UPDATE" statements, 120 "DELETE" statements as raw strings
Yes. For example: https://github.com/jschaf/pggen/blob/main/example/erp/order/....
> that is also using an ORM
ORM as a term covers a wide swathe of usage. In the smallest definition, an ORM converts DB tuples to Go structs. In common usage, most folks use ORM to mean a generic query builder plus the type conversion from tuples to structs. For other usages, I prefer the Patterns of Enterprise Application Architecture terms  like data-mapper, active record, and table-data gateway.7 projects | news.ycombinator.com | 26 Nov 2021
Having written a non-ORM Go-Postgres tool  similar to sqlc, I'm a big fan of this article, especially their acknowledgment that using SQL moves the eng culture towards data-centric engineering. Some thoughts:
- Application code should not rely on database table structure (like the ActiveRecord pattern). Modeling the database as a bunch of queries is a better bet since you can change the underlying table structure but keep the same query semantics to allow for database refactoring.
- Database code and queries should be defined in SQL. I'm not a fan of defining the database in another programming language that generates DDL for you since it's another layer of abstraction that usually leaks heavily.
- One of the main drawbacks of writing queries in plain SQL is that dynamic queries are more difficult to write. I haven't found that to be too much of a problem since you can use multiple queries or push some of the dynamic parts into a SQL predicate. Some things are easier with an ORM, like dynamic ordering or dynamic group-by clauses.
Similar comment from a few months ago comparing Go approaches to SQL: https://news.ycombinator.com/item?id=28463938
Back to basics: Writing an application using Go and PostgreSQL
15 projects | news.ycombinator.com | 22 Nov 2021
You might like pggen (I’m the author) which only supports Postgres and pgx. https://github.com/jschaf/pggen
pggen occupies the same design space as sqlc but the implementations are quite different. Sqlc figures out the query types using type inference in Go which is nice because you don’t need Postgres at build time. Pggen asks Postgres what the query types are which is nice because it works with any extensions and arbitrarily complex queries.
How We Went All In on sqlc/pgx for Postgres + Go
3 projects | reddit.com/r/golang | 9 Sep 2021
Any reason to use sqlc over pggen ? If you use Postgres, it seems like the superior option.
We Went All in on Sqlc/Pgx for Postgres and Go
31 projects | news.ycombinator.com | 8 Sep 2021
I agree whole-heartedly that writing SQL feels right. Broadly speaking, you can take the following approaches to mapping database queries to Go code:
- Write SQL queries, parse the SQL, generate Go from the queries (sqlc, pggen).
- Write SQL schema files, parse the SQL schema, generate active records based on the tables (gorm)
- Write Go structs, generate SQL schema from the structs, and use a custom query DSL (proteus).
- Write custom query language (YAML or other), generate SQL schema, queries, and Go query interface (xo).
- Skip generated code and use a non-type-safe query builder (squirrel, goqu).
I prefer writing SQL queries so that app logic doesn't depend on the the database table structure.
I started off with sqlc but ran into limitations with more complex queries. It's quite difficult to infer what a SQL query will output even with a proper parse tree. sqlc also didn't work with generated code.
I wrote pggen with the idea that you can just execute the query and have Postgres tell you what the output types and names will be. Here's the original design doc  that outlines the motivations. By comparison, sqlc starts from the parse tree, and has the complex task of computing the control flow graph for nullability and type outputs.
Disclaimer: author of pggen (https://github.com/jschaf/pggen), inspired by sqlc31 projects | news.ycombinator.com | 8 Sep 2021
What are your favorite packages to use?
55 projects | reddit.com/r/golang | 15 Aug 2021
Agree with your choices, except go-json which I never tried. pggen is fantastic. Love that library. The underlying driver, pgx, is also really well written.
I don't want to learn your garbage query language
9 projects | news.ycombinator.com | 10 Mar 2021
You might like the approach I took with pggen which was inspired by sqlc. You write a SQL query in regular SQL and the tool generates a type-safe Go querier struct with a method for each query.
The primary benefit of pggen and sqlc is that you don't need a different query model; it's just SQL and the tools automate the mapping between database rows and Go structs.
A note from our sponsor - SonarQube
www.sonarqube.org | 24 Mar 2023
jschaf/pggen is an open source project licensed under MIT License which is an OSI approved license.