Skip to content

Commit 04acf9a

Browse files
authored
fix: emit rustfmt-compliant #![allow] header (#13)
## Summary - The single-line `#![allow(dead_code, reason = "…")]` attribute the generator emitted in v0.1.4/v0.1.5 exceeded rustfmt's 100-col default, so `cargo fmt --check` failed the release workflow and the v0.1.5 wasm asset was never uploaded. See the failed run: https://github.com/mathematic-inc/sqlc-gen-sqlx/actions/runs/24376376904 - Pre-wrap the attribute across multiple lines at emit time so the output is idempotent under rustfmt. - Regenerate the committed example snapshots and expand the root `sqlc.yaml` so `sqlc generate` covers all four examples (previously only `basic` was wired up). ## Test plan - [x] `cargo fmt --all --check` clean - [x] `cargo clippy --workspace --all-targets -- -D warnings` clean - [x] `cargo test --lib --bins` passes - [x] `cargo build --target wasm32-wasip1` produces a valid plugin - [x] `sqlc generate` with the rebuilt wasm regenerates every example cleanly (sqlc.yaml sha updated to match) Once merged, release-please should open a 0.1.6 PR; merging that will re-trigger `release.yml` with the format check passing and publish the wasm. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 648580c commit 04acf9a

27 files changed

Lines changed: 142 additions & 41 deletions

examples/advanced-types/src/queries.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// Code generated by sqlc-gen-sqlx v0.1.4. DO NOT EDIT.
1+
// Code generated by sqlc-gen-sqlx v0.1.5. DO NOT EDIT.
22
// sqlc version: v1.30.0
33

4-
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
4+
#![allow(
5+
dead_code,
6+
reason = "generated queries may expose items a caller does not use"
7+
)]
58

69
const GET_EVENT: &str = "SELECT id, name, flags, event_window FROM events WHERE id = $1";
710
#[derive(Debug, Clone, sqlx::FromRow)]

examples/basic/src/queries.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// Code generated by sqlc-gen-sqlx v0.1.4. DO NOT EDIT.
1+
// Code generated by sqlc-gen-sqlx v0.1.5. DO NOT EDIT.
22
// sqlc version: v1.30.0
33

4-
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
4+
#![allow(
5+
dead_code,
6+
reason = "generated queries may expose items a caller does not use"
7+
)]
58

69
const GET_AUTHOR: &str = "SELECT id, name, bio FROM authors WHERE id = $1";
710
#[derive(Debug, Clone, sqlx::FromRow)]
@@ -22,7 +25,8 @@ pub struct CreateAuthorParams {
2225
pub name: String,
2326
pub bio: Option<String>,
2427
}
25-
const CREATE_AUTHOR: &str = "INSERT INTO authors (name, bio) VALUES ($1, $2) RETURNING id, name, bio";
28+
const CREATE_AUTHOR: &str =
29+
"INSERT INTO authors (name, bio) VALUES ($1, $2) RETURNING id, name, bio";
2630
#[derive(Debug, Clone, sqlx::FromRow)]
2731
pub struct CreateAuthorRow {
2832
pub id: i64,
@@ -99,7 +103,10 @@ impl<E: AsExecutor> Queries<E> {
99103
.await
100104
}
101105
pub async fn delete_author(&mut self, id: i64) -> Result<(), sqlx::Error> {
102-
sqlx::query(DELETE_AUTHOR).bind(id).execute(self.db.as_executor()).await?;
106+
sqlx::query(DELETE_AUTHOR)
107+
.bind(id)
108+
.execute(self.db.as_executor())
109+
.await?;
103110
Ok(())
104111
}
105112
pub async fn delete_author_rows(&mut self, id: i64) -> Result<u64, sqlx::Error> {

examples/batch/src/queries.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// Code generated by sqlc-gen-sqlx v0.1.4. DO NOT EDIT.
1+
// Code generated by sqlc-gen-sqlx v0.1.5. DO NOT EDIT.
22
// sqlc version: v1.30.0
33

4-
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
4+
#![allow(
5+
dead_code,
6+
reason = "generated queries may expose items a caller does not use"
7+
)]
58

69
const BATCH_GET_AUTHOR: &str = "SELECT id, name, bio FROM authors WHERE id = $1";
710
#[derive(Debug, Clone, sqlx::FromRow)]
@@ -60,9 +63,7 @@ impl<E: AsExecutor> Queries<E> {
6063
pub fn batch_get_author<'a, I>(
6164
&'a mut self,
6265
items: I,
63-
) -> impl futures_core::stream::Stream<
64-
Item = Result<BatchGetAuthorRow, sqlx::Error>,
65-
> + 'a
66+
) -> impl futures_core::stream::Stream<Item = Result<BatchGetAuthorRow, sqlx::Error>> + 'a
6667
where
6768
I: IntoIterator<Item = i64> + 'a,
6869
I::IntoIter: 'a,

examples/enums/src/queries.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// Code generated by sqlc-gen-sqlx v0.1.4. DO NOT EDIT.
1+
// Code generated by sqlc-gen-sqlx v0.1.5. DO NOT EDIT.
22
// sqlc version: v1.30.0
33

4-
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
4+
#![allow(
5+
dead_code,
6+
reason = "generated queries may expose items a caller does not use"
7+
)]
58

69
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, sqlx::Type)]
710
#[sqlx(type_name = "status")]
@@ -94,10 +97,7 @@ impl<E: AsExecutor> Queries<E> {
9497
.fetch_all(self.db.as_executor())
9598
.await
9699
}
97-
pub async fn create_user(
98-
&mut self,
99-
arg: CreateUserParams,
100-
) -> Result<(), sqlx::Error> {
100+
pub async fn create_user(&mut self, arg: CreateUserParams) -> Result<(), sqlx::Error> {
101101
sqlx::query(CREATE_USER)
102102
.bind(arg.name)
103103
.bind(arg.status)

sqlc.yaml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
- name: sqlc-gen-sqlx
44
wasm:
55
url: file://target/wasm32-wasip1/debug/sqlc-gen-sqlx.wasm
6-
sha256: "8e453f461e97ef85246e94b56842efbda064380bfa672a1396c229cc57f0a1e7"
6+
sha256: "837a7ff89040ce7bded3d87abaaa83591353eadc99c4cd46ed9572a450b09fd2"
77

88
sql:
99
- schema: examples/basic/schema.sql
@@ -14,3 +14,30 @@ sql:
1414
out: examples/basic/src
1515
options:
1616
output: queries.rs
17+
18+
- schema: examples/advanced-types/schema.sql
19+
queries: examples/advanced-types/queries.sql
20+
engine: postgresql
21+
codegen:
22+
- plugin: sqlc-gen-sqlx
23+
out: examples/advanced-types/src
24+
options:
25+
output: queries.rs
26+
27+
- schema: examples/batch/schema.sql
28+
queries: examples/batch/queries.sql
29+
engine: postgresql
30+
codegen:
31+
- plugin: sqlc-gen-sqlx
32+
out: examples/batch/src
33+
options:
34+
output: queries.rs
35+
36+
- schema: examples/enums/schema.sql
37+
queries: examples/enums/queries.sql
38+
engine: postgresql
39+
codegen:
40+
- plugin: sqlc-gen-sqlx
41+
out: examples/enums/src
42+
options:
43+
output: queries.rs

src/emit.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ impl FileEmitter {
3434

3535
let formatted = prettyplease::unparse(&file);
3636

37+
// Pre-wrapped to satisfy `cargo fmt --check` at the default 100-col
38+
// max_width — the single-line form exceeds the limit and rustfmt
39+
// rewrites it.
3740
let header = format!(
3841
"// Code generated by sqlc-gen-sqlx v{}. DO NOT EDIT.\n\
3942
// sqlc version: {}\n\n\
40-
#![allow(dead_code, reason = \"generated queries may expose items a caller does not use\")]\n\n",
43+
#![allow(\n dead_code,\n reason = \"generated queries may expose items a caller does not use\"\n)]\n\n",
4144
self.plugin_version, self.sqlc_version,
4245
);
4346

@@ -61,7 +64,7 @@ mod tests {
6164
assert!(code.contains("sqlc-gen-sqlx vsqlc-test"));
6265
assert!(code.contains("sqlc version: 0.0.0-test"));
6366
assert!(code.contains(
64-
"#![allow(dead_code, reason = \"generated queries may expose items a caller does not use\")]"
67+
"#![allow(\n dead_code,\n reason = \"generated queries may expose items a caller does not use\"\n)]"
6568
));
6669
}
6770

tests/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn snapshot_one() {
9292
let code = String::from_utf8(resp.files[0].contents.clone()).unwrap();
9393
assert_codegen_snapshot("one", &code);
9494
assert!(
95-
code.contains("#![allow(dead_code, reason = \"generated queries may expose items a caller does not use\")]"),
95+
code.contains("#![allow(\n dead_code,\n reason = \"generated queries may expose items a caller does not use\"\n)]"),
9696
"expected dead_code allow in:\n{code}"
9797
);
9898
assert!(

tests/snapshots/codegen__batch_dynamic_slice_param.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ expression: code
55
// Code generated by sqlc-gen-sqlx v[VERSION]. DO NOT EDIT.
66
// sqlc version: [VERSION]
77

8-
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
8+
#![allow(
9+
dead_code,
10+
reason = "generated queries may expose items a caller does not use"
11+
)]
912

1013
const BATCH_LIST_AUTHORS_BY_DYNAMIC_IDS: &str = "SELECT id, name, bio FROM authors WHERE id IN ($1)";
1114
#[derive(Debug, Clone, sqlx::FromRow)]

tests/snapshots/codegen__batchexec.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ expression: code
55
// Code generated by sqlc-gen-sqlx v[VERSION]. DO NOT EDIT.
66
// sqlc version: [VERSION]
77

8-
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
8+
#![allow(
9+
dead_code,
10+
reason = "generated queries may expose items a caller does not use"
11+
)]
912

1013
const BATCH_DELETE_AUTHOR: &str = "DELETE FROM authors WHERE id = $1";
1114
pub trait AsExecutor {

tests/snapshots/codegen__batchmany.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ expression: code
55
// Code generated by sqlc-gen-sqlx v[VERSION]. DO NOT EDIT.
66
// sqlc version: [VERSION]
77

8-
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
8+
#![allow(
9+
dead_code,
10+
reason = "generated queries may expose items a caller does not use"
11+
)]
912

1013
const BATCH_LIST_AUTHORS: &str = "SELECT id, name, bio FROM authors WHERE bio LIKE $1";
1114
#[derive(Debug, Clone, sqlx::FromRow)]

0 commit comments

Comments
 (0)