{"id":50544088,"url":"https://github.com/mathematic-inc/sqlc-gen-sqlx","last_synced_at":"2026-06-03T22:30:44.137Z","repository":{"id":350999589,"uuid":"1209137899","full_name":"mathematic-inc/sqlc-gen-sqlx","owner":"mathematic-inc","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-09T12:09:46.000Z","size":188,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-09T14:20:06.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathematic-inc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-13T06:08:37.000Z","updated_at":"2026-05-09T12:09:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mathematic-inc/sqlc-gen-sqlx","commit_stats":null,"previous_names":["mathematic-inc/sqlc-gen-sqlx"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mathematic-inc/sqlc-gen-sqlx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fsqlc-gen-sqlx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fsqlc-gen-sqlx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fsqlc-gen-sqlx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fsqlc-gen-sqlx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathematic-inc","download_url":"https://codeload.github.com/mathematic-inc/sqlc-gen-sqlx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fsqlc-gen-sqlx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33883102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-03T02:00:06.370Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-03T22:30:43.506Z","updated_at":"2026-06-03T22:30:44.125Z","avatar_url":"https://github.com/mathematic-inc.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlc-gen-sqlx\n\nA [sqlc](https://sqlc.dev) plugin that generates type-safe [sqlx](https://github.com/launchbadge/sqlx) Rust code from SQL queries.\n\n## What it generates\n\nFor each SQL query annotated with a sqlc command, the plugin emits:\n\n- A `const SQL: \u0026str` holding the query text.\n- A strongly-typed row struct (`QueryNameRow`) for `:one` / `:many`.\n- An optional params struct (`QueryNameParams`) when a query has 2+ parameters.\n- A free `pub async fn` (or `pub fn` for batch streams) that executes the query, taking the executor as its first argument.\n\nThe executor argument is generic over the `AsExecutor` trait emitted in the same file. `AsExecutor` is implemented for `\u0026PgPool`, `\u0026mut PgConnection`, `\u0026mut Transaction\u003c'_, Postgres\u003e`, `\u0026mut PoolConnection\u003cPostgres\u003e`, and `\u0026mut T` of each — i.e. the natural sqlx reference types:\n\n```rust\n// From a pool:\nlet author = queries::get_author(\u0026pool, 1).await?;\n\n// Pool connection:\nlet mut conn = pool.acquire().await?;\nlet author = queries::get_author(\u0026mut conn, 1).await?;\n\n// Transaction:\nlet mut tx = pool.begin().await?;\nqueries::delete_author(\u0026mut tx, 1).await?;\ntx.commit().await?;\n```\n\n## Installation\n\nAdd the plugin to your `sqlc.yaml`:\n\n```yaml\nversion: \"2\"\nplugins:\n  - name: sqlc-gen-sqlx\n    wasm:\n      url: https://github.com/your-org/sqlc-gen-sqlx/releases/download/v0.1.0/sqlc-gen-sqlx.wasm\n      sha256: \"\u003csha256 of the wasm file\u003e\"\nsql:\n  - engine: postgresql\n    queries: queries.sql\n    schema: schema.sql\n    codegen:\n      - plugin: sqlc-gen-sqlx\n        out: src/\n        options:\n          output: queries.rs\n```\n\n## Configuration\n\nAll options are passed in `codegen[*].options`:\n\n| Key | Type | Default | Description |\n|---|---|---|---|\n| `output` | string | `queries.rs` | Output filename |\n| `overrides` | array | `[]` | Type overrides (`rs_type`, optional `borrowed_rs_type`; see below) |\n| `row_derives` | array | `[]` | Extra derives for row and params structs |\n| `enum_derives` | array | `[]` | Extra derives for generated enum types |\n| `composite_derives` | array | `[]` | Extra derives for generated composite types |\n| `copy_cheap_types` | array | `[]` | Type names to mark as copy-cheap |\n\n### Type overrides\n\nOverride the Rust type used for a PostgreSQL column type or a specific column:\n\n```yaml\noptions:\n  overrides:\n    - db_type: \"timestamptz\"\n      rs_type: \"time::OffsetDateTime\"\n      copy_cheap: false\n    - column: \"users.created_at\"\n      rs_type: \"chrono::DateTime\u003cchrono::Local\u003e\"\n      copy_cheap: false\n```\n\n### Borrowed parameters\n\nAdd `borrowed_rs_type` to a type or column override to take that type by\nreference in parameter positions. Row struct fields, array contents, and the\n`Item` of `:copyfrom` chunks continue to use the owned form:\n\n```yaml\noptions:\n  overrides:\n    - db_type: \"text\"\n      borrowed_rs_type: \"\u0026str\"\n```\n\nWith that override, generated signatures borrow scalar `text` parameters and\nthe codegen threads lifetimes only where needed:\n\n```rust\n// Scalar — lifetime elided\npub async fn get_author_by_name\u003cE: AsExecutor\u003e(\n    mut db: E, name: \u0026str,\n) -\u003e Result\u003cGetAuthorByNameRow, sqlx::Error\u003e { ... }\n\n// Multiple params — struct carries `'a`, fn uses `'_`\npub struct CreateAuthorParams\u003c'a\u003e {\n    pub name: \u0026'a str,\n    pub bio: Option\u003c\u0026'a str\u003e,\n}\npub async fn create_author\u003cE: AsExecutor\u003e(\n    mut db: E, arg: CreateAuthorParams\u003c'_\u003e,\n) -\u003e Result\u003cCreateAuthorRow, sqlx::Error\u003e { ... }\n\n// Row struct stays owned — results are returned by value\npub struct GetAuthorByNameRow { pub name: String, /* ... */ }\n```\n\n`rs_type` is optional alongside `borrowed_rs_type`. Omit it to keep the\nbuilt-in owned default; set both to fully customize:\n\n```yaml\noverrides:\n  - db_type: \"text\"\n    rs_type: \"MyStr\"           # used for row fields \u0026 array contents\n    borrowed_rs_type: \"\u0026MyStr\" # used for scalar params\n```\n\nFor `text[]` and `sqlc.slice(text)` the wrapper becomes a borrowed slice while\nthe inner item stays owned (`\u0026[String]`), so callers can pass `\u0026my_vec`\ndirectly without re-collecting.\n\n## Supported PostgreSQL types\n\n| PostgreSQL | Rust |\n|---|---|\n| `bool` | `bool` |\n| `int2` / `smallint` | `i16` |\n| `int4` / `integer` / `int` | `i32` |\n| `int8` / `bigint` | `i64` |\n| `float4` / `real` | `f32` |\n| `float8` / `double precision` | `f64` |\n| `numeric` / `decimal` | `bigdecimal::BigDecimal` |\n| `text` / `varchar` / `bpchar` / `citext` | `String` |\n| `bytea` | `Vec\u003cu8\u003e` |\n| `uuid` | `uuid::Uuid` |\n| `json` / `jsonb` | `serde_json::Value` |\n| `timestamptz` | `chrono::DateTime\u003cchrono::Utc\u003e` |\n| `timestamp` | `chrono::NaiveDateTime` |\n| `date` | `chrono::NaiveDate` |\n| `time` | `chrono::NaiveTime` |\n| `inet` / `cidr` | `ipnetwork::IpNetwork` |\n| `macaddr` | `mac_address::MacAddress` |\n| `hstore` | `std::collections::HashMap\u003cString, Option\u003cString\u003e\u003e` |\n| `interval` | `sqlx::postgres::types::PgInterval` |\n| `money` | `sqlx::postgres::types::PgMoney` |\n| `oid` | `sqlx::postgres::types::Oid` |\n| `int4range` | `sqlx::postgres::types::PgRange\u003ci32\u003e` |\n| `int8range` | `sqlx::postgres::types::PgRange\u003ci64\u003e` |\n| `numrange` | `sqlx::postgres::types::PgRange\u003cbigdecimal::BigDecimal\u003e` |\n| `tsrange` | `sqlx::postgres::types::PgRange\u003cchrono::NaiveDateTime\u003e` |\n| `tstzrange` | `sqlx::postgres::types::PgRange\u003cchrono::DateTime\u003cchrono::Utc\u003e\u003e` |\n| `daterange` | `sqlx::postgres::types::PgRange\u003cchrono::NaiveDate\u003e` |\n| `bit` / `varbit` | `bit_vec::BitVec` |\n| PostgreSQL ENUM | generated Rust enum |\n| PostgreSQL composite | generated Rust struct |\n\nArray types (`type[]`) become `Vec\u003cT\u003e`. Nullable columns become `Option\u003cT\u003e`.\n\n## Supported query annotations\n\n| Annotation | Return type | Description |\n|---|---|---|\n| `:exec` | `Result\u003c(), sqlx::Error\u003e` | Execute, discard result |\n| `:execrows` | `Result\u003cu64, sqlx::Error\u003e` | Execute, return rows affected |\n| `:execresult` | `Result\u003csqlx::postgres::PgQueryResult, sqlx::Error\u003e` | Execute, return full result |\n| `:execlastid` | `Result\u003cT, sqlx::Error\u003e` | Execute with RETURNING, return scalar |\n| `:one` | `Result\u003cQueryRow, sqlx::Error\u003e` | Fetch exactly one row |\n| `:many` | `Result\u003cVec\u003cQueryRow\u003e, sqlx::Error\u003e` | Fetch all rows |\n| `:batchexec` | `impl Stream\u003cItem = Result\u003c(), sqlx::Error\u003e\u003e` | Lazily execute once per item |\n| `:batchone` | `impl Stream\u003cItem = Result\u003cQueryRow, sqlx::Error\u003e\u003e` | Lazily fetch one row per item |\n| `:batchmany` | `impl Stream\u003cItem = Result\u003cVec\u003cQueryRow\u003e, sqlx::Error\u003e\u003e` | Lazily fetch all rows per item |\n| `:copyfrom` | `Result\u003cu64, sqlx::Error\u003e` | Chunked bulk insert from any `IntoIterator` |\n\nAll functions are free `pub async fn` (or `pub fn` for batch streams) at module scope, taking the executor as their first argument. The bound is `E: AsExecutor`, where `AsExecutor` is the trait emitted in each generated file. Impls cover `\u0026PgPool`, `\u0026mut PgConnection`, `\u0026mut Transaction\u003c'_, Postgres\u003e`, `\u0026mut PoolConnection\u003cPostgres\u003e`, and `\u0026mut T` of each.\n\nBatch methods generate `Stream`-returning APIs and reference `futures_core` and `futures_util` directly. Consumer crates should include those dependencies alongside `sqlx`.\n\n## sqlc extensions\n\n- **`sqlc.slice()`**: Parameters marked as slice expand to `Vec\u003cT\u003e` and support runtime placeholder expansion for `IN (sqlc.slice(...))`-style queries.\n- **`sqlc.embed(table)`**: Result columns from an embedded table become a nested struct with `#[sqlx(flatten)]`.\n\n## License\n\nMIT OR Apache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathematic-inc%2Fsqlc-gen-sqlx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathematic-inc%2Fsqlc-gen-sqlx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathematic-inc%2Fsqlc-gen-sqlx/lists"}