Live data from Hacker News

Show HN: sqlc-gen-sqlx, a sqlc plugin for generating sqlx Rust code

github.com

1–3 of 3 posts

Show HN: sqlc-gen-sqlx, a sqlc plugin for generating sqlx Rust code

#1
`sqlc-gen-sqlx` is a `sqlc` (https://sqlc.dev) plugin that generates `sqlx`-oriented Rust code from annotated SQL queries.

The generated API is intentionally small:

- a `const SQL`

- row structs for `:one` and `:many`

- params structs when a query has multiple parameters

- methods on `Queries` that work with `&PgPool`, `&mut PgConnection`, or `&mut Transaction`

Current scope is PostgreSQL. It supports the usual `sqlc` query annotations, plus enums, composite types, batch queries, `COPY FROM`, `sqlc.slice()`, `sqlc.embed()`, and type overrides.

Show HN: sqlc-gen-sqlx, a sqlc plugin for generating sqlx Rust code
github.com

Re: Show HN: sqlc-gen-sqlx, a sqlc plugin for generating sqlx Rust code

#2
How does this handle prepared statement caching compared to writing sqlx queries directly? Been burned before by N+1 prepared statement creation in high-throughput services. Also curious if there's a migration story since sqlc plugins are relatively new, did you hit any gotchas moving existing sqlx codebases over?

Re: Show HN: sqlc-gen-sqlx, a sqlc plugin for generating sqlx Rust code

#3
post #2

How does this handle prepared statement caching compared to writing sqlx queries directly? Been burned before by N+1 prepared statement creation in high-throughput services. Also curious if there's a migration story since sqlc plugins are relatively new, did you hit any gotchas moving existing sqlx codebases over?

This plugin uses sqlx underneath which handles prepared statement caching. Regarding migration, we just used a coding agent to migrate our database infrastructure to it. It takes Tip: you can use case statements and etc. to create static queries even when you have conditionals.

Also, read https://news.ycombinator.com/newsguidelines.html#generated