-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Description
When using sqlc-gen-csharp with a Postgres enum that is declared as non-nullable in the schema, the generated C# code does not compile.
Specifically, the generated class references .Value.Stringify() on the enum property, which is invalid when the enum type is not nullable.
Generated cs:
public class CreateBoogerSampleArgs
{
public required int Id { get; init; }
public required Booger BoogerType { get; init; }
};
public async Task CreateBoogerSample(CreateBoogerSampleArgs args)
{
var queryParams = new Dictionary<string, object?>();
queryParams.Add("id", args.Id);
queryParams.Add("booger_type", args.BoogerType.Value.Stringify());
...
}
query.sql:
-- name: CreateBoogerSample :exec
INSERT INTO booger_sample (id, type)
VALUES (@id, @booger_type);
schema.sql:
CREATE TYPE booger AS ENUM (
'fresh',
'old'
);
CREATE TABLE booger_sample (
id INT NOT NULL,
type booger NOT NULL
);
Expected Behavior
For a non-nullable enum column, the generated code should not reference .Value. Instead, it should call .Stringify() directly on the enum property.
Correct code should look like:
queryParams.Add("booger_type", args.BoogerType.Stringify());
Environment
sqlc docker image: latest
Database: PostgreSQL
Target: C# (Dapper + Npgsql)
sqlc-gen-csharp: v0.21.2
- 98990c2a46b0e315c7f062f5643e3404ed4150a5ef2808c47a4e10084443506e
Metadata
Metadata
Assignees
Labels
No labels