You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7e813b7
Browse filesBrowse the repository at this point in the historyBrowse files
Fix bugs found by the pre-release sweep, update docs (#46)
## Summary
Fixes the bugs found by a pre-release sweep of `main` (real PostgreSQL
16 / MySQL 8.3 / SQLite apps on Ruby 3.1–3.4), and brings the docs up to
date.
**Fixes**
- **pg `:batchexec` / `:batchone` / `:batchmany`** now encode parameters
like every other command (`Driver#encode_param`), so `bytea`, `json` and
arrays work. Before: `string contains null byte` / type errors.
- **pg transactions:** a block that rescues a failed statement and
returns normally used to "commit" (the server answered `ROLLBACK`,
silently). It now raises `PG::InFailedSqlTransaction`.
- **mysql2 `:copyfrom`:** binary-safe (`CHARACTER SET binary`),
all-or-nothing (transaction, or savepoint inside one), and `LOAD DATA
LOCAL` warnings (skipped duplicate keys, coerced invalid values) raise
`Mysql2::Error`.
- **sqlite3 `:copyfrom`** runs in a savepoint: a failing row no longer
leaves earlier batches committed.
- **sqlite3 transactions:** threads / fibers sharing one
`SQLite3::Database` take turns (one reentrant lock per database, in the
new `connection.rb`) instead of breaking each other's savepoints.
Unknown `mode:` values raise `ArgumentError` instead of producing
invalid SQL.
- **Types:** SQLite `JSON` / `JSONB` / `UUID` columns are `String` (were
`Float`); a `db_type` override now types the elements of arrays of that
type (`uuid[]` → `Array[String]`) instead of replacing the array type.
- **RuboCop:** schema names that break a naming cop (`"UserId"`,
two-letter or non-ASCII parameters) get a `rubocop:disable` / `enable`
pair around only the class or method using them.
- **WASM:** an empty `syntax_suggest/core_ext.rb` stub, so plugin errors
are no longer prefixed by "`syntax_suggest' was not loaded".
- **Options:** unknown keys in an override are rejected (with a "did you
mean" hint); clearer `rubyVersion` range errors.
**Behaviour changes worth a release note:** pg code that swallowed a
failed statement inside `transaction` now raises; MySQL loads that
skipped duplicates now fail; users running Steep on generated SQLite
code need `library "monitor"`.
**Docs:** README reorganised (quick start, one options table,
transactions / types / names / limitations sections) without dropping
content; Design / Architecture / Testing / Releasing, CLAUDE.md and the
PR template updated to the current code (new commands and hooks, stale
limitations removed, labels matching the repo).
**Tests:** unit tests for each generator change; new E2E tests for batch
encoding, the rescued pg statement, MySQL binary / duplicate / invalid /
nested `:copyfrom`, SQLite copy atomicity, thread-shared transactions
and invalid modes. `examples/`, golden files, request fixtures and Steep
expectations regenerated. Locally (Ruby 3.3): `rake test` 85 runs,
RuboCop and Steep clean, `sqlc diff` clean with the rebuilt WASM, E2E
SQLite 35 / PostgreSQL 49 / MySQL 41 runs green.
## Checklist
- [x] `examples/` is regenerated (`rake sqlc_generate_process`) and
committed
- [x] Tests added or updated (`rake test`, and `rake end2end_*` when the
generated code changes)
- [x] The generated code stays RuboCop-clean (`rake rubocop`) and
Steep-clean (`rake steep`)
- [x] Labelled (`bug`, `enhancement`, `documentation`, or `breaking`) so
the release notes are grouped correctly
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Doron Eli Rachman <doron050@gmail.com>
* Develop on a feature branch, small commits; PRs target `main`. Label PRs (`feature`, `bug`, `breaking`, `documentation`).
39
+
* Develop on a feature branch, small commits; PRs target `main`. Label PRs (`bug`, `enhancement`, `documentation`; `breaking` for incompatible changes, see `.github/release.yml`).
40
40
* CI: `build.yml` (WASM, lint, `sqlc diff`, Steep, option matrix) and `tests.yml` (unit, Ruby 3.1/3.2/3.4, E2E on real
41
41
PostgreSQL/MySQL/SQLite). Both must be green.
42
42
***Never create tags or releases by hand and never add release markers to commit messages.** Releases are started by a
|`exe/plugin.rb`| entry point. Errors go to stderr with exit code 1 (sqlc shows them); `SQLC_GEN_RUBY_DEBUG=1` adds a backtrace |
22
22
|`proto.rb`, `plugin_pb.rb`| a ~150 line protobuf wire codec and the subset of sqlc's `codegen.proto` we read. Field numbers must match upstream. `google-protobuf` is a C extension and cannot run inside ruby.wasm |
23
23
|`options.rb`, `ruby_version.rb`| parse + validate the `options:` JSON (`driver`, `rubyVersion`, `overrides`, `rename`, ...; unknown keys are errors) |
24
-
|`generator.rb`| the orchestrator: one file per query file (`query_sql.rb`), plus `models.rb`, `connection.rb`, `Gemfile`; builds the module / class / `Data` skeleton |
25
-
|`method_gen.rb`| the code of one query: signature (keyword arguments), SQL constant, command (`:one`, `:many`, `:exec`, `:execrows`, `:execlastid`, `:copyfrom`), `sqlc.slice`, bang finder, and the RBS signature |
24
+
|`generator.rb`| the orchestrator: one file per query file (`query_sql.rb`), plus `models.rb`, `connection.rb` (per-connection state and helpers the query classes share), `Gemfile`; builds the module / class / `Data` skeleton |
25
+
|`method_gen.rb`| the code of one query: signature (keyword arguments), SQL constant, command (`:one`, `:many`, `:exec`, `:execrows`, `:execlastid`, `:execresult`, `:batchexec` / `:batchone` / `:batchmany`, `:copyfrom`), `sqlc.slice`, bang finder, and the RBS signature |
26
26
|`row_layout.rb`| turns result columns into row attributes; `sqlc.embed` collapses a table's columns into one model attribute |
27
-
|`type_resolver.rb`| RBS type of a column / parameter: driver type table, arrays, nullability (`T?`), `overrides:`|
27
+
|`type_resolver.rb`| RBS type of a column / parameter: driver type table, arrays, nullability (`T?`), `overrides:`(a `db_type` override types array elements too) |
28
28
|`catalog.rb`| the schema's tables and enums, and their Ruby names |
29
29
|`drivers/base.rb`| the driver interface and what all drivers share: `instrument` logging, `NotFound`, transaction RBS |
30
30
|`drivers/{pg,mysql2,sqlite3}.rb`| the per-library parts: type mapping, connecting / pooling, preparing and executing statements, transactions, `:copyfrom`|
31
-
|`code.rb`| text helpers: indentation, `snake_case`, `camelize`, Ruby-keyword-safe parameter names |
31
+
|`code.rb`| text helpers: indentation, `snake_case`, `camelize`, Ruby-keyword-safe parameter names, `rubocop:disable` pairs for schema names that break a naming cop|
32
32
33
33
**Rule of thumb:**`MethodGen` / `Generator` decide *what* is generated and are the same for every database; a driver only
34
34
supplies *snippets* (how to prepare a statement, how to read the affected rows, ...). If you find a `case driver` in
@@ -67,6 +67,10 @@ Design decisions worth knowing (the *why* is in the comments of `drivers/base.rb
67
67
* **Pool injection.** `QuerySql.new(pool)` accepts anything that responds to `#with`, so an app can share its pool
68
68
and tests can pass a fake. `connect(...)` is only a convenience that builds a `connection_pool`.
69
69
***Statements are closed.**SQLite/MySQL statements are closed in`ensure` (an openSQLite statement blocks `COMMIT`).
70
+
***Parameters are encoded by the driver.**`Driver#encode_param` (e.g. `bytea`, `json`and arrays on `pg`) is used by
71
+
every command, batches included; add a type's encoding there, not in `MethodGen`.
72
+
* **`:copyfrom` is all or nothing** on every driver (a savepoint / transaction around the load), and MySQL's
73
+
`LOAD DATA` warnings (skipped duplicates, coerced values) are raised as errors.
70
74
***Nothing from the plugin leaks into the app.**The generated code only requires the driver gem and`connection_pool`.
Copy file name to clipboardExpand all lines: docs/Design.md
+14-22Lines changed: 14 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,30 +4,22 @@ sqlc plugins receive a protobuf `GenerateRequest` on stdin and answer with a `Ge
4
4
process or as a WASI module. This plugin is pure Ruby and is distributed as a WASI module (`plugin.wasm`).
5
5
6
6
## Source layout
7
-
8
-
| File | Role |
9
-
|---|---|
10
-
|`exe/plugin.rb`| entry point (stdin → `Generator` → stdout) |
11
-
|`lib/sqlc_gen_ruby/proto.rb`|~150 line protobuf wire codec. `google-protobuf` is a C extension and cannot be loaded inside ruby.wasm, so the plugin brings its own |
12
-
|`lib/sqlc_gen_ruby/plugin_pb.rb`| the subset of sqlc's `codegen.proto` the generator needs (field numbers must match upstream) |
13
-
|`lib/sqlc_gen_ruby/options.rb`, `ruby_version.rb`| the `options:` JSON, `rubyVersion` parsing / validation (3.1 – 3.4; `Struct` below 3.2, `Data` from 3.2) |
|`lib/sqlc_gen_ruby/method_gen.rb`| one generated method per query: `:one`, `:many`, `:exec`, `:execrows`, `:execlastid`, `:copyfrom`, `sqlc.slice`|
16
-
|`lib/sqlc_gen_ruby/row_layout.rb`| how result columns become `<Query>Row` attributes (`sqlc.embed` expands a table into one model attribute) |
17
-
|`lib/sqlc_gen_ruby/type_resolver.rb`, `catalog.rb`| RBS type of a column (DB type mapping + array + nullability + `overrides:`), tables / enums of the catalog |
0 commit comments