pggen VS chi

Compare pggen vs chi and see what are their differences.

pggen

Generate type-safe Go for any Postgres query. If Postgres can run the query, pggen can generate code for it. (by jschaf)

chi

lightweight, idiomatic and composable router for building Go HTTP services (by go-chi)
Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
pggen chi
11 100
262 16,857
- 2.5%
6.6 7.2
2 months ago 19 days ago
Go Go
MIT License MIT License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

pggen

Posts with mentions or reviews of pggen. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-01-06.
  • Ask HN: ORM or Native SQL?
    10 projects | news.ycombinator.com | 6 Jan 2023
    Cornucopia is neat. I wrote a similar library in Go [1] 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.

    The cons:

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

    [1]: https://github.com/jschaf/pggen

  • What are the things with Go that have made you wish you were back in Spring/.NET/Django etc?
    3 projects | /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 [1] like data-mapper, active record, and table-data gateway.

    [1]: https://martinfowler.com/eaaCatalog/

    7 projects | news.ycombinator.com | 26 Nov 2021
    Having written a non-ORM Go-Postgres tool [1] 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.

    [1]: https://github.com/jschaf/pggen

    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 | /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 [1] 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.

    [1]: https://docs.google.com/document/d/1NvVKD6cyXvJLWUfqFYad76CW...

    Disclaimer: author of pggen (https://github.com/jschaf/pggen), inspired by sqlc

    31 projects | news.ycombinator.com | 8 Sep 2021
  • What are your favorite packages to use?
    55 projects | /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[1] which was inspired by sqlc[2]. 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.

    [1]: https://github.com/jschaf/pggen

    [2]: https://github.com/kyleconroy/sqlc

chi

Posts with mentions or reviews of chi. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-03-26.

What are some alternatives?

When comparing pggen and chi you can also consider the following projects:

Gin - 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.

Echo - High performance, minimalist Go web framework

mux - A powerful HTTP router and URL matcher for building Go web servers with 🦍

Fiber - ⚡️ Express inspired web framework written in Go

httprouter - A high performance HTTP request router that scales well

go-kit - A standard library for microservices.

websocket - A fast, well-tested and widely used WebSocket implementation for Go.

kin-openapi - OpenAPI 3.0 (and Swagger v2) implementation for Go (parsing, converting, validation, and more)

Iris - The fastest HTTP/2 Go Web Framework. New, modern and easy to learn. Fast development with Code you control. Unbeatable cost-performance ratio :rocket:

negroni - Idiomatic HTTP Middleware for Golang

Goji - Goji is a minimalistic and flexible HTTP request multiplexer for Go (golang)

zerolog - Zero Allocation JSON Logger