From f169b12d0cc1a958f8046cf905765f32acccce9d Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Fri, 10 Jul 2026 14:50:23 +0300 Subject: [PATCH 1/5] fix: resolve NotSupportedException for schema-qualified PostgreSQL enum types When a PostgreSQL column references an enum type with schema qualification (e.g., `block_type public.post_block_type`), sqlc sets `column.Type.Schema` to `public`. However, `ConstructEnumsLookup` normalizes default schema enums under key `` (empty string), causing `GetEnumType` to fail the lookup and throw `NotSupportedException`. Fixed by normalizing the schema name in `GetEnumSchemaAndName` to empty string when it matches the driver's DefaultSchema. Changes: - Drivers/NpgsqlDriver.cs: normalize default schema in GetEnumSchemaAndName - unit-tests/CodegenTests/CodegenSchemaTests.cs: add failing-then-passing test - examples/config/postgresql/types/: add schema-qualified enum table + queries - examples/Npgsql*Example/: regenerated code with new model/queries - end2end/: add truncation for new table in e2e TearDown --- Drivers/NpgsqlDriver.cs | 4 +- end2end/EndToEndTests/NpgsqlDapperTester.cs | 1 + end2end/EndToEndTests/NpgsqlTester.cs | 1 + examples/NpgsqlDapperExample/Models.cs | 4 + examples/NpgsqlDapperExample/QuerySql.cs | 70 +++++++++++ examples/NpgsqlDapperExample/request.json | 65 ++++++++++ examples/NpgsqlDapperExample/request.message | 22 +++- examples/NpgsqlDapperLegacyExample/Models.cs | 4 + .../NpgsqlDapperLegacyExample/QuerySql.cs | 70 +++++++++++ .../NpgsqlDapperLegacyExample/request.json | 65 ++++++++++ .../NpgsqlDapperLegacyExample/request.message | 22 +++- examples/NpgsqlExample/Models.cs | 1 + examples/NpgsqlExample/QuerySql.cs | 113 +++++++++++++++++ examples/NpgsqlExample/request.json | 65 ++++++++++ examples/NpgsqlExample/request.message | 22 +++- examples/NpgsqlLegacyExample/Models.cs | 4 + examples/NpgsqlLegacyExample/QuerySql.cs | 119 ++++++++++++++++++ examples/NpgsqlLegacyExample/request.json | 65 ++++++++++ examples/NpgsqlLegacyExample/request.message | 22 +++- examples/config/postgresql/types/query.sql | 18 +++ examples/config/postgresql/types/schema.sql | 4 + unit-tests/CodegenTests/CodegenSchemaTests.cs | 60 +++++++++ 22 files changed, 808 insertions(+), 13 deletions(-) diff --git a/Drivers/NpgsqlDriver.cs b/Drivers/NpgsqlDriver.cs index 323185fc..46f95436 100644 --- a/Drivers/NpgsqlDriver.cs +++ b/Drivers/NpgsqlDriver.cs @@ -730,7 +730,7 @@ public override string AddParametersToCommand(Query query) }).JoinByNewLine(); } - private static (string, string) GetEnumSchemaAndName(Column column) + private (string, string) GetEnumSchemaAndName(Column column) { var schemaName = column.Type.Schema; var enumName = column.Type.Name; @@ -740,6 +740,8 @@ private static (string, string) GetEnumSchemaAndName(Column column) schemaName = schemaAndEnum[0]; enumName = schemaAndEnum[1]; } + if (schemaName == DefaultSchema) + schemaName = string.Empty; return (schemaName, enumName); } diff --git a/end2end/EndToEndTests/NpgsqlDapperTester.cs b/end2end/EndToEndTests/NpgsqlDapperTester.cs index 67edbbc3..1fd1f03c 100644 --- a/end2end/EndToEndTests/NpgsqlDapperTester.cs +++ b/end2end/EndToEndTests/NpgsqlDapperTester.cs @@ -21,5 +21,6 @@ public async Task EmptyTestsTable() await QuerySql.TruncatePostgresNetworkTypesAsync(); await QuerySql.TruncatePostgresArrayTypesAsync(); await QuerySql.TruncatePostgresSpecialTypesAsync(); + await QuerySql.TruncatePostgresQualifiedEnumTypesAsync(); } } \ No newline at end of file diff --git a/end2end/EndToEndTests/NpgsqlTester.cs b/end2end/EndToEndTests/NpgsqlTester.cs index e497f265..a4b14719 100644 --- a/end2end/EndToEndTests/NpgsqlTester.cs +++ b/end2end/EndToEndTests/NpgsqlTester.cs @@ -22,5 +22,6 @@ public async Task EmptyTestsTables() await QuerySql.TruncatePostgresArrayTypesAsync(); await QuerySql.TruncatePostgresSpecialTypesAsync(); await QuerySql.TruncatePostgresNotNullTypesAsync(); + await QuerySql.TruncatePostgresQualifiedEnumTypesAsync(); } } \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/Models.cs b/examples/NpgsqlDapperExample/Models.cs index c04761d9..c48d05e4 100644 --- a/examples/NpgsqlDapperExample/Models.cs +++ b/examples/NpgsqlDapperExample/Models.cs @@ -96,6 +96,10 @@ public class PostgresNotNullType { public required CEnum CEnumNotNull { get; init; } }; +public class PostgresQualifiedEnumType +{ + public CEnum? CQualifiedEnum { get; init; } +}; public class ExtendedBio { public required string AuthorName { get; init; } diff --git a/examples/NpgsqlDapperExample/QuerySql.cs b/examples/NpgsqlDapperExample/QuerySql.cs index 9312d8c8..4439eb57 100644 --- a/examples/NpgsqlDapperExample/QuerySql.cs +++ b/examples/NpgsqlDapperExample/QuerySql.cs @@ -1887,4 +1887,74 @@ public async Task TruncatePostgresGeoTypesAsync() throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); } + + private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types + ( + c_qualified_enum + ) + VALUES ( + @c_qualified_enum::c_enum + )"; + public class InsertPostgresQualifiedEnumTypesArgs + { + public CEnum? CQualifiedEnum { get; init; } + }; + public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : null); + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + await connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams); + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresQualifiedEnumTypesSql = @"SELECT + c_qualified_enum + FROM postgres_qualified_enum_types + LIMIT 1"; + public class GetPostgresQualifiedEnumTypesRow + { + public CEnum? CQualifiedEnum { get; init; } + }; + public async Task GetPostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; + public async Task TruncatePostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + await connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql); + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql, transaction: this.Transaction); + } } \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/request.json b/examples/NpgsqlDapperExample/request.json index 5506c5e1..38027688 100644 --- a/examples/NpgsqlDapperExample/request.json +++ b/examples/NpgsqlDapperExample/request.json @@ -686,6 +686,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_qualified_enum_types" + }, + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -36229,6 +36247,53 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresQualifiedEnumTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_qualified_enum_types" + } + }, + { + "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", + "name": "GetPostgresQualifiedEnumTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_qualified_enum_types", + "name": "TruncatePostgresQualifiedEnumTypes", + "cmd": ":exec", + "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlDapperExample/request.message b/examples/NpgsqlDapperExample/request.message index 4f4573de..fec3a982 100644 --- a/examples/NpgsqlDapperExample/request.message +++ b/examples/NpgsqlDapperExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlb‡ examples/NpgsqlDapperExamplecsharpШ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"net8.0","useDapper":true}* -./dist/LocalRunnerЁю public"уpublicƒ +./dist/LocalRunner–я public"иpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -98,7 +98,9 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums +postgres_qualified_enum_typesP +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10917,4 +10919,18 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*К{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlDapperExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр +\INSERT INTO postgres_qualified_enum_types +( + c_qualified_enum +) +VALUES ( + $1::c_enum +) InsertPostgresQualifiedEnumTypes:exec*+' +c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм +FSELECT + c_qualified_enum +FROM postgres_qualified_enum_types +LIMIT 1GetPostgresQualifiedEnumTypes:one"b +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld +,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*К{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlDapperExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/Models.cs b/examples/NpgsqlDapperLegacyExample/Models.cs index 879d51d1..f11c2026 100644 --- a/examples/NpgsqlDapperLegacyExample/Models.cs +++ b/examples/NpgsqlDapperLegacyExample/Models.cs @@ -97,6 +97,10 @@ public class PostgresNotNullType { public CEnum CEnumNotNull { get; set; } }; + public class PostgresQualifiedEnumType + { + public CEnum? CQualifiedEnum { get; set; } + }; public class ExtendedBio { public string AuthorName { get; set; } diff --git a/examples/NpgsqlDapperLegacyExample/QuerySql.cs b/examples/NpgsqlDapperLegacyExample/QuerySql.cs index 39ab5771..ef99a902 100644 --- a/examples/NpgsqlDapperLegacyExample/QuerySql.cs +++ b/examples/NpgsqlDapperLegacyExample/QuerySql.cs @@ -1888,5 +1888,75 @@ public async Task TruncatePostgresGeoTypesAsync() throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); } + + private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types + ( + c_qualified_enum + ) + VALUES ( + @c_qualified_enum::c_enum + )"; + public class InsertPostgresQualifiedEnumTypesArgs + { + public CEnum? CQualifiedEnum { get; set; } + }; + public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : null); + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + await connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams); + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresQualifiedEnumTypesSql = @"SELECT + c_qualified_enum + FROM postgres_qualified_enum_types + LIMIT 1"; + public class GetPostgresQualifiedEnumTypesRow + { + public CEnum? CQualifiedEnum { get; set; } + }; + public async Task GetPostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; + public async Task TruncatePostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + await connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql); + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql, transaction: this.Transaction); + } } } \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/request.json b/examples/NpgsqlDapperLegacyExample/request.json index 5284a64d..c37896db 100644 --- a/examples/NpgsqlDapperLegacyExample/request.json +++ b/examples/NpgsqlDapperLegacyExample/request.json @@ -686,6 +686,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_qualified_enum_types" + }, + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -36229,6 +36247,53 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresQualifiedEnumTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_qualified_enum_types" + } + }, + { + "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", + "name": "GetPostgresQualifiedEnumTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_qualified_enum_types", + "name": "TruncatePostgresQualifiedEnumTypes", + "cmd": ":exec", + "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlDapperLegacyExample/request.message b/examples/NpgsqlDapperLegacyExample/request.message index ffaf95f7..f299acf4 100644 --- a/examples/NpgsqlDapperLegacyExample/request.message +++ b/examples/NpgsqlDapperLegacyExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlb› "examples/NpgsqlDapperLegacyExamplecsharpж{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"netstandard2.0","useDapper":true}* -./dist/LocalRunnerЁю public"уpublicƒ +./dist/LocalRunner–я public"иpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -98,7 +98,9 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums +postgres_qualified_enum_typesP +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10917,4 +10919,18 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*Ш{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlDapperLegacyExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр +\INSERT INTO postgres_qualified_enum_types +( + c_qualified_enum +) +VALUES ( + $1::c_enum +) InsertPostgresQualifiedEnumTypes:exec*+' +c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм +FSELECT + c_qualified_enum +FROM postgres_qualified_enum_types +LIMIT 1GetPostgresQualifiedEnumTypes:one"b +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld +,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*Ш{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlDapperLegacyExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/NpgsqlExample/Models.cs b/examples/NpgsqlExample/Models.cs index 966152d7..933572fb 100644 --- a/examples/NpgsqlExample/Models.cs +++ b/examples/NpgsqlExample/Models.cs @@ -21,6 +21,7 @@ namespace NpgsqlExampleGen; public readonly record struct PostgresGeometricType(NpgsqlPoint? CPoint, NpgsqlLine? CLine, NpgsqlLSeg? CLseg, NpgsqlBox? CBox, NpgsqlPath? CPath, NpgsqlPolygon? CPolygon, NpgsqlCircle? CCircle); public readonly record struct PostgresSpecialType(Guid? CUuid, CEnum? CEnum, JsonElement? CJson, JsonElement? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, XmlDocument? CXmlStringOverride); public readonly record struct PostgresNotNullType(CEnum CEnumNotNull); +public readonly record struct PostgresQualifiedEnumType(CEnum? CQualifiedEnum); public readonly record struct ExtendedBio(string AuthorName, string Name, ExtendedBioType? BioType); public enum CEnum { diff --git a/examples/NpgsqlExample/QuerySql.cs b/examples/NpgsqlExample/QuerySql.cs index 29011982..6d7c56d0 100644 --- a/examples/NpgsqlExample/QuerySql.cs +++ b/examples/NpgsqlExample/QuerySql.cs @@ -2660,4 +2660,117 @@ public async Task TruncatePostgresGeoTypesAsync() await command.ExecuteNonQueryAsync(); } } + + private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types + ( + c_qualified_enum + ) + VALUES ( + @c_qualified_enum::c_enum + )"; + public readonly record struct InsertPostgresQualifiedEnumTypesArgs(CEnum? CQualifiedEnum); + public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + using (var command = connection.CreateCommand()) + { + command.CommandText = InsertPostgresQualifiedEnumTypesSql; + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresQualifiedEnumTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresQualifiedEnumTypesSql = @"SELECT + c_qualified_enum + FROM postgres_qualified_enum_types + LIMIT 1"; + public readonly record struct GetPostgresQualifiedEnumTypesRow(CEnum? CQualifiedEnum); + public async Task GetPostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + using (var command = connection.CreateCommand()) + { + command.CommandText = GetPostgresQualifiedEnumTypesSql; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresQualifiedEnumTypesRow + { + CQualifiedEnum = reader.IsDBNull(0) ? null : reader.GetString(0).ToCEnum() + }; + } + } + } + }; + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresQualifiedEnumTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresQualifiedEnumTypesRow + { + CQualifiedEnum = reader.IsDBNull(0) ? null : reader.GetString(0).ToCEnum() + }; + } + } + } + + return null; + } + + private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; + public async Task TruncatePostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + using (var command = connection.CreateCommand()) + { + command.CommandText = TruncatePostgresQualifiedEnumTypesSql; + await command.ExecuteNonQueryAsync(); + } + + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresQualifiedEnumTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } } \ No newline at end of file diff --git a/examples/NpgsqlExample/request.json b/examples/NpgsqlExample/request.json index c359bd43..e88d6d62 100644 --- a/examples/NpgsqlExample/request.json +++ b/examples/NpgsqlExample/request.json @@ -686,6 +686,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_qualified_enum_types" + }, + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -36229,6 +36247,53 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresQualifiedEnumTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_qualified_enum_types" + } + }, + { + "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", + "name": "GetPostgresQualifiedEnumTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_qualified_enum_types", + "name": "TruncatePostgresQualifiedEnumTypes", + "cmd": ":exec", + "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlExample/request.message b/examples/NpgsqlExample/request.message index b46e6595..a9191654 100644 --- a/examples/NpgsqlExample/request.message +++ b/examples/NpgsqlExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlbќ examples/NpgsqlExamplecsharpУ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"net8.0","useDapper":false}* -./dist/LocalRunnerЁю public"уpublicƒ +./dist/LocalRunner–я public"иpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -98,7 +98,9 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums +postgres_qualified_enum_typesP +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10917,4 +10919,18 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*Е{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр +\INSERT INTO postgres_qualified_enum_types +( + c_qualified_enum +) +VALUES ( + $1::c_enum +) InsertPostgresQualifiedEnumTypes:exec*+' +c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм +FSELECT + c_qualified_enum +FROM postgres_qualified_enum_types +LIMIT 1GetPostgresQualifiedEnumTypes:one"b +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld +,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*Е{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/NpgsqlLegacyExample/Models.cs b/examples/NpgsqlLegacyExample/Models.cs index 67d27bf2..81ef272b 100644 --- a/examples/NpgsqlLegacyExample/Models.cs +++ b/examples/NpgsqlLegacyExample/Models.cs @@ -97,6 +97,10 @@ public class PostgresNotNullType { public CEnum CEnumNotNull { get; set; } }; + public class PostgresQualifiedEnumType + { + public CEnum? CQualifiedEnum { get; set; } + }; public class ExtendedBio { public string AuthorName { get; set; } diff --git a/examples/NpgsqlLegacyExample/QuerySql.cs b/examples/NpgsqlLegacyExample/QuerySql.cs index 788c25a6..bb5efbea 100644 --- a/examples/NpgsqlLegacyExample/QuerySql.cs +++ b/examples/NpgsqlLegacyExample/QuerySql.cs @@ -3016,5 +3016,124 @@ public async Task TruncatePostgresGeoTypesAsync() await command.ExecuteNonQueryAsync(); } } + + private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types + ( + c_qualified_enum + ) + VALUES ( + @c_qualified_enum::c_enum + )"; + public class InsertPostgresQualifiedEnumTypesArgs + { + public CEnum? CQualifiedEnum { get; set; } + }; + public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + using (var command = connection.CreateCommand()) + { + command.CommandText = InsertPostgresQualifiedEnumTypesSql; + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresQualifiedEnumTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresQualifiedEnumTypesSql = @"SELECT + c_qualified_enum + FROM postgres_qualified_enum_types + LIMIT 1"; + public class GetPostgresQualifiedEnumTypesRow + { + public CEnum? CQualifiedEnum { get; set; } + }; + public async Task GetPostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + using (var command = connection.CreateCommand()) + { + command.CommandText = GetPostgresQualifiedEnumTypesSql; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresQualifiedEnumTypesRow + { + CQualifiedEnum = reader.IsDBNull(0) ? (CEnum? )null : reader.GetString(0).ToCEnum() + }; + } + } + } + }; + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresQualifiedEnumTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresQualifiedEnumTypesRow + { + CQualifiedEnum = reader.IsDBNull(0) ? (CEnum? )null : reader.GetString(0).ToCEnum() + }; + } + } + } + + return null; + } + + private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; + public async Task TruncatePostgresQualifiedEnumTypesAsync() + { + if (this.Transaction == null) + { + using (var connection = await GetDataSource().OpenConnectionAsync()) + { + using (var command = connection.CreateCommand()) + { + command.CommandText = TruncatePostgresQualifiedEnumTypesSql; + await command.ExecuteNonQueryAsync(); + } + + return; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresQualifiedEnumTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } } } \ No newline at end of file diff --git a/examples/NpgsqlLegacyExample/request.json b/examples/NpgsqlLegacyExample/request.json index bc5a8311..457510e8 100644 --- a/examples/NpgsqlLegacyExample/request.json +++ b/examples/NpgsqlLegacyExample/request.json @@ -686,6 +686,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_qualified_enum_types" + }, + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -36229,6 +36247,53 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresQualifiedEnumTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_qualified_enum_types" + } + }, + { + "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", + "name": "GetPostgresQualifiedEnumTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_qualified_enum_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_qualified_enum_types", + "name": "TruncatePostgresQualifiedEnumTypes", + "cmd": ":exec", + "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlLegacyExample/request.message b/examples/NpgsqlLegacyExample/request.message index 51759dfb..8b3dfd4b 100644 --- a/examples/NpgsqlLegacyExample/request.message +++ b/examples/NpgsqlLegacyExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlb examples/NpgsqlLegacyExamplecsharpб{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"netstandard2.0","useDapper":false}* -./dist/LocalRunnerЁю public"уpublicƒ +./dist/LocalRunner–я public"иpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -98,7 +98,9 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums +postgres_qualified_enum_typesP +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10917,4 +10919,18 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*У{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlLegacyExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр +\INSERT INTO postgres_qualified_enum_types +( + c_qualified_enum +) +VALUES ( + $1::c_enum +) InsertPostgresQualifiedEnumTypes:exec*+' +c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм +FSELECT + c_qualified_enum +FROM postgres_qualified_enum_types +LIMIT 1GetPostgresQualifiedEnumTypes:one"b +c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld +,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*У{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlLegacyExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/config/postgresql/types/query.sql b/examples/config/postgresql/types/query.sql index 0b482159..eb22195b 100644 --- a/examples/config/postgresql/types/query.sql +++ b/examples/config/postgresql/types/query.sql @@ -412,3 +412,21 @@ SELECT * FROM postgres_geometric_types LIMIT 1; -- name: TruncatePostgresGeoTypes :exec TRUNCATE TABLE postgres_geometric_types; + +-- name: InsertPostgresQualifiedEnumTypes :exec +INSERT INTO postgres_qualified_enum_types +( + c_qualified_enum +) +VALUES ( + sqlc.narg('c_qualified_enum')::c_enum +); + +-- name: GetPostgresQualifiedEnumTypes :one +SELECT + c_qualified_enum +FROM postgres_qualified_enum_types +LIMIT 1; + +-- name: TruncatePostgresQualifiedEnumTypes :exec +TRUNCATE TABLE postgres_qualified_enum_types; diff --git a/examples/config/postgresql/types/schema.sql b/examples/config/postgresql/types/schema.sql index dfcb92c5..7f11a723 100644 --- a/examples/config/postgresql/types/schema.sql +++ b/examples/config/postgresql/types/schema.sql @@ -77,4 +77,8 @@ CREATE TABLE postgres_special_types ( CREATE TABLE postgres_not_null_types ( c_enum_not_null c_enum NOT NULL DEFAULT 'small' +); + +CREATE TABLE postgres_qualified_enum_types ( + c_qualified_enum public.c_enum ); \ No newline at end of file diff --git a/unit-tests/CodegenTests/CodegenSchemaTests.cs b/unit-tests/CodegenTests/CodegenSchemaTests.cs index 0597220a..3af99c9e 100644 --- a/unit-tests/CodegenTests/CodegenSchemaTests.cs +++ b/unit-tests/CodegenTests/CodegenSchemaTests.cs @@ -1,6 +1,9 @@ +using Google.Protobuf; using Microsoft.CodeAnalysis.CSharp.Syntax; using NUnit.Framework; +using Plugin; using SqlcGenCsharp; +using System.Text; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace CodegenTests; @@ -55,6 +58,63 @@ public void TestSchemaScopedEnum() Assert.That(actual.IsSupersetOf(expected)); } + [Test] + public void TestDefaultSchemaEnumWithSchemaQualifiedType() + { + var request = new GenerateRequest + { + Settings = new Settings + { + Engine = "postgresql", + Codegen = new Codegen { Out = "DummyProject" } + }, + Catalog = new Catalog + { + DefaultSchema = "public", + Schemas = + { + new Schema + { + Name = "public", + Enums = + { + new Plugin.Enum + { + Name = "post_block_type", + Vals = { "text", "markdown", "media" } + } + }, + Tables = + { + new Table + { + Rel = new Identifier { Name = "post_block" }, + Columns = + { + new Column + { + Name = "block_type", + Type = new Identifier + { + Name = "post_block_type", + Schema = "public" + }, + NotNull = true + } + } + } + } + } + } + }, + PluginOptions = ByteString.CopyFrom("{}", Encoding.UTF8) + }; + + var response = CodeGenerator.Generate(request); + var generatedModelsFile = response.Result.Files.First(f => f.Name == "Models.cs"); + Assert.That(generatedModelsFile, Is.Not.Null); + } + private static HashSet GetMemberNames(CompilationUnitSyntax compilationUnit) { var members = compilationUnit.DescendantNodes().OfType().ToList(); From f8f9b36a5febd2cd7d5c62e33127c35f9e569a7b Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Fri, 10 Jul 2026 14:59:03 +0300 Subject: [PATCH 2/5] fixup: use Any() instead of First() + null assertion in test --- unit-tests/CodegenTests/CodegenSchemaTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unit-tests/CodegenTests/CodegenSchemaTests.cs b/unit-tests/CodegenTests/CodegenSchemaTests.cs index 3af99c9e..ae6b8dd1 100644 --- a/unit-tests/CodegenTests/CodegenSchemaTests.cs +++ b/unit-tests/CodegenTests/CodegenSchemaTests.cs @@ -111,8 +111,7 @@ public void TestDefaultSchemaEnumWithSchemaQualifiedType() }; var response = CodeGenerator.Generate(request); - var generatedModelsFile = response.Result.Files.First(f => f.Name == "Models.cs"); - Assert.That(generatedModelsFile, Is.Not.Null); + Assert.That(response.Result.Files.Any(f => f.Name == "Models.cs"), Is.True); } private static HashSet GetMemberNames(CompilationUnitSyntax compilationUnit) From 9ea36756dadab5a6993603e943d65d09e9607b2f Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Fri, 10 Jul 2026 14:59:59 +0300 Subject: [PATCH 3/5] fix: bump MySQL version from 8.4.6 to 8.4.9 in legacy CI workflow 8.4.6 was removed from the MySQL CDN (404), causing Chocolatey install to fail. 8.4.9 is the latest 8.4.x patch available. --- .github/workflows/legacy-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/legacy-tests.yml b/.github/workflows/legacy-tests.yml index 6f99931d..68f49872 100644 --- a/.github/workflows/legacy-tests.yml +++ b/.github/workflows/legacy-tests.yml @@ -71,7 +71,7 @@ jobs: shell: pwsh command: | $mysqlJob = Start-Job -ScriptBlock { - choco install mysql --no-progress --version=8.4.6 -y --params "/serviceName:MySQL" + choco install mysql --no-progress --version=8.4.9 -y --params "/serviceName:MySQL" return $LASTEXITCODE } From 4728286f618c2ddd854ff93b626455a0f5aae1b3 Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Fri, 10 Jul 2026 15:10:50 +0300 Subject: [PATCH 4/5] fix: remove MySQL version pin in legacy CI workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pinned versions 8.4.6 and 8.4.9 both fail т€” 8.4.6 downloads from a dead CDN URL, and 8.4.9 doesn't exist on Chocolatey. Removing the pin lets Chocolatey resolve the latest approved version with a valid URL. --- .github/workflows/legacy-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/legacy-tests.yml b/.github/workflows/legacy-tests.yml index 68f49872..d791e5f2 100644 --- a/.github/workflows/legacy-tests.yml +++ b/.github/workflows/legacy-tests.yml @@ -71,7 +71,7 @@ jobs: shell: pwsh command: | $mysqlJob = Start-Job -ScriptBlock { - choco install mysql --no-progress --version=8.4.9 -y --params "/serviceName:MySQL" + choco install mysql --no-progress -y --params "/serviceName:MySQL" return $LASTEXITCODE } From cb575f9069cdb64221109dbd3f81556917936e8a Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Fri, 10 Jul 2026 15:25:38 +0300 Subject: [PATCH 5/5] refactor: merge qualified enum column into existing postgres_special_types table Move c_qualified_enum (public.c_enum) into the existing postgres_special_types table instead of a separate postgres_qualified_enum_types table, per PR feedback. The schema-qualified enum type is tested alongside the existing unqualified c_enum column in the same table and its queries. This avoids adding a new table to the schema. --- end2end/EndToEndTests/NpgsqlDapperTester.cs | 1 - end2end/EndToEndTests/NpgsqlTester.cs | 1 - examples/NpgsqlDapperExample/Models.cs | 5 +- examples/NpgsqlDapperExample/QuerySql.cs | 82 ++--------- examples/NpgsqlDapperExample/request.json | 102 +++++-------- examples/NpgsqlDapperExample/request.message | 50 +++---- examples/NpgsqlDapperLegacyExample/Models.cs | 5 +- .../NpgsqlDapperLegacyExample/QuerySql.cs | 82 ++--------- .../NpgsqlDapperLegacyExample/request.json | 102 +++++-------- .../NpgsqlDapperLegacyExample/request.message | 50 +++---- examples/NpgsqlExample/Models.cs | 3 +- examples/NpgsqlExample/QuerySql.cs | 134 ++--------------- examples/NpgsqlExample/request.json | 102 +++++-------- examples/NpgsqlExample/request.message | 50 +++---- examples/NpgsqlLegacyExample/Models.cs | 5 +- examples/NpgsqlLegacyExample/QuerySql.cs | 138 ++---------------- examples/NpgsqlLegacyExample/request.json | 102 +++++-------- examples/NpgsqlLegacyExample/request.message | 50 +++---- examples/config/postgresql/types/query.sql | 26 +--- examples/config/postgresql/types/schema.sql | 5 +- 20 files changed, 277 insertions(+), 818 deletions(-) diff --git a/end2end/EndToEndTests/NpgsqlDapperTester.cs b/end2end/EndToEndTests/NpgsqlDapperTester.cs index 1fd1f03c..67edbbc3 100644 --- a/end2end/EndToEndTests/NpgsqlDapperTester.cs +++ b/end2end/EndToEndTests/NpgsqlDapperTester.cs @@ -21,6 +21,5 @@ public async Task EmptyTestsTable() await QuerySql.TruncatePostgresNetworkTypesAsync(); await QuerySql.TruncatePostgresArrayTypesAsync(); await QuerySql.TruncatePostgresSpecialTypesAsync(); - await QuerySql.TruncatePostgresQualifiedEnumTypesAsync(); } } \ No newline at end of file diff --git a/end2end/EndToEndTests/NpgsqlTester.cs b/end2end/EndToEndTests/NpgsqlTester.cs index a4b14719..e497f265 100644 --- a/end2end/EndToEndTests/NpgsqlTester.cs +++ b/end2end/EndToEndTests/NpgsqlTester.cs @@ -22,6 +22,5 @@ public async Task EmptyTestsTables() await QuerySql.TruncatePostgresArrayTypesAsync(); await QuerySql.TruncatePostgresSpecialTypesAsync(); await QuerySql.TruncatePostgresNotNullTypesAsync(); - await QuerySql.TruncatePostgresQualifiedEnumTypesAsync(); } } \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/Models.cs b/examples/NpgsqlDapperExample/Models.cs index c48d05e4..94893736 100644 --- a/examples/NpgsqlDapperExample/Models.cs +++ b/examples/NpgsqlDapperExample/Models.cs @@ -85,6 +85,7 @@ public class PostgresSpecialType { public Guid? CUuid { get; init; } public CEnum? CEnum { get; init; } + public CEnum? CQualifiedEnum { get; init; } public JsonElement? CJson { get; init; } public JsonElement? CJsonStringOverride { get; init; } public JsonElement? CJsonb { get; init; } @@ -96,10 +97,6 @@ public class PostgresNotNullType { public required CEnum CEnumNotNull { get; init; } }; -public class PostgresQualifiedEnumType -{ - public CEnum? CQualifiedEnum { get; init; } -}; public class ExtendedBio { public required string AuthorName { get; init; } diff --git a/examples/NpgsqlDapperExample/QuerySql.cs b/examples/NpgsqlDapperExample/QuerySql.cs index 4439eb57..43470dd8 100644 --- a/examples/NpgsqlDapperExample/QuerySql.cs +++ b/examples/NpgsqlDapperExample/QuerySql.cs @@ -1358,7 +1358,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( @c_json, @@ -1368,7 +1369,8 @@ INSERT INTO postgres_special_types @c_xml::xml, @c_xml_string_override::xml, @c_uuid, - @c_enum::c_enum + @c_enum::c_enum, + @c_qualified_enum::c_enum )"; public class InsertPostgresSpecialTypesArgs { @@ -1380,6 +1382,7 @@ public class InsertPostgresSpecialTypesArgs public string? CXmlStringOverride { get; init; } public Guid? CUuid { get; init; } public CEnum? CEnum { get; init; } + public CEnum? CQualifiedEnum { get; init; } }; public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs args) { @@ -1392,6 +1395,7 @@ public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs queryParams.Add("c_xml_string_override", args.CXmlStringOverride); queryParams.Add("c_uuid", args.CUuid); queryParams.Add("c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : null); + queryParams.Add("c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : null); if (this.Transaction == null) { using (var connection = await GetDataSource().OpenConnectionAsync()) @@ -1484,7 +1488,8 @@ public async Task TruncatePostgresNotNullTypesAsync() c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1"; public class GetPostgresSpecialTypesRow @@ -1497,6 +1502,7 @@ public class GetPostgresSpecialTypesRow public string? CXmlStringOverride { get; init; } public Guid? CUuid { get; init; } public CEnum? CEnum { get; init; } + public CEnum? CQualifiedEnum { get; init; } }; public async Task GetPostgresSpecialTypesAsync() { @@ -1887,74 +1893,4 @@ public async Task TruncatePostgresGeoTypesAsync() throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); } - - private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types - ( - c_qualified_enum - ) - VALUES ( - @c_qualified_enum::c_enum - )"; - public class InsertPostgresQualifiedEnumTypesArgs - { - public CEnum? CQualifiedEnum { get; init; } - }; - public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) - { - var queryParams = new Dictionary(); - queryParams.Add("c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : null); - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - await connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams); - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - await this.Transaction.Connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams, transaction: this.Transaction); - } - - private const string GetPostgresQualifiedEnumTypesSql = @"SELECT - c_qualified_enum - FROM postgres_qualified_enum_types - LIMIT 1"; - public class GetPostgresQualifiedEnumTypesRow - { - public CEnum? CQualifiedEnum { get; init; } - }; - public async Task GetPostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql); - return result; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql, transaction: this.Transaction); - } - - private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; - public async Task TruncatePostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - await connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql); - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql, transaction: this.Transaction); - } } \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/request.json b/examples/NpgsqlDapperExample/request.json index 38027688..bc4d922d 100644 --- a/examples/NpgsqlDapperExample/request.json +++ b/examples/NpgsqlDapperExample/request.json @@ -605,6 +605,17 @@ "name": "c_enum" } }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + }, { "name": "c_json", "length": -1, @@ -686,24 +697,6 @@ } } ] - }, - { - "rel": { - "name": "postgres_qualified_enum_types" - }, - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - } - } - ] } ], "enums": [ @@ -35108,7 +35101,7 @@ } }, { - "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum,\n $9::c_enum\n)", "name": "InsertPostgresSpecialTypes", "cmd": ":exec", "parameters": [ @@ -35210,6 +35203,16 @@ "name": "c_enum" } } + }, + { + "number": 9, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } } ], "comments": [ @@ -35269,7 +35272,7 @@ "filename": "query.sql" }, { - "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\nFROM postgres_special_types \nLIMIT 1", "name": "GetPostgresSpecialTypes", "cmd": ":one", "columns": [ @@ -35362,6 +35365,18 @@ "name": "c_enum" }, "originalName": "c_enum" + }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" } ], "filename": "query.sql" @@ -36247,53 +36262,6 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", - "name": "InsertPostgresQualifiedEnumTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_qualified_enum", - "length": -1, - "type": { - "name": "c_enum" - } - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_qualified_enum_types" - } - }, - { - "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", - "name": "GetPostgresQualifiedEnumTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - }, - "originalName": "c_qualified_enum" - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_qualified_enum_types", - "name": "TruncatePostgresQualifiedEnumTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlDapperExample/request.message b/examples/NpgsqlDapperExample/request.message index fec3a982..5336a450 100644 --- a/examples/NpgsqlDapperExample/request.message +++ b/examples/NpgsqlDapperExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlb‡ examples/NpgsqlDapperExamplecsharpШ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"net8.0","useDapper":true}* -./dist/LocalRunner–я public"иpublicƒ +./dist/LocalRunnerью public"Ўpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -83,10 +83,11 @@ pg_catalog timestamp c_box0џџџџџџџџџRpostgres_geometric_typesbbox7 c_path0џџџџџџџџџRpostgres_geometric_typesbpath= c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygon; -c_circle0џџџџџџџџџRpostgres_geometric_typesbcircle’ +c_circle0џџџџџџџџџRpostgres_geometric_typesbcircleн postgres_special_types5 c_uuid0џџџџџџџџџRpostgres_special_typesbuuid7 -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumA +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumI +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumA c_json0џџџџџџџџџRpostgres_special_typesb pg_catalogjsonQ c_json_string_override0џџџџџџџџџRpostgres_special_typesb @@ -98,9 +99,7 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums -postgres_qualified_enum_typesP -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10682,8 +10681,8 @@ LIMIT 1GetPostgresNetworkTypesCnt:one"= ) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE c_cidr0џџџџџџџџџR publicpostgres_network_typesbcidrzc_cidr*IE c_inet0џџџџџџџџџR publicpostgres_network_typesbinetzc_inet*RN - c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesП -— + c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_types’ +Н INSERT INTO postgres_special_types ( c_json, @@ -10693,7 +10692,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( $1, @@ -10703,7 +10703,8 @@ VALUES ( $5::xml, $6::xml, $7, - $8::c_enum + $8::c_enum, + $9::c_enum )InsertPostgresSpecialTypes:exec*VR c_json0џџџџџџџџџ8R publicpostgres_special_typesbpg_catalog.jsonzc_json*;7 c_json_string_override0џџџџџџџџџb @@ -10715,7 +10716,8 @@ c_jsonpath0 c_xml0џџџџџџџџџbxml*-) c_xml_string_override0џџџџџџџџџbxml*KG c_uuid0џџџџџџџџџ8R publicpostgres_special_typesbuuidzc_uuid*! -c_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ +c_enum0џџџџџџџџџbc_enum*+ ' +c_qualified_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ UINSERT INTO postgres_not_null_types ( c_enum_not_null @@ -10729,8 +10731,8 @@ VALUES ( FROM postgres_not_null_types LIMIT 1GetPostgresNotNullTypes:one"T c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enumzc_enum_not_null: query.sqlX -&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЕ -­SELECT +&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЈ +УSELECT c_json, c_json_string_override, c_jsonb, @@ -10738,7 +10740,8 @@ LIMIT 1GetPostgresNotNullTypes:one"T c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1GetPostgresSpecialTypes:one"I c_json0џџџџџџџџџRpostgres_special_typesb @@ -10753,7 +10756,8 @@ c_jsonpath": c_xml0џџџџџџџџџRpostgres_special_typesbxmlzc_xml"Z c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxmlzc_xml_string_override"= c_uuid0џџџџџџџџџRpostgres_special_typesbuuidzc_uuid"? -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum: query.sqlW +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum"[ +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumzc_qualified_enum: query.sqlW %TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlЎ lINSERT INTO postgres_special_types ( @@ -10919,18 +10923,4 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр -\INSERT INTO postgres_qualified_enum_types -( - c_qualified_enum -) -VALUES ( - $1::c_enum -) InsertPostgresQualifiedEnumTypes:exec*+' -c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм -FSELECT - c_qualified_enum -FROM postgres_qualified_enum_types -LIMIT 1GetPostgresQualifiedEnumTypes:one"b -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld -,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*К{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlDapperExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*К{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlDapperExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/Models.cs b/examples/NpgsqlDapperLegacyExample/Models.cs index f11c2026..5371ec8e 100644 --- a/examples/NpgsqlDapperLegacyExample/Models.cs +++ b/examples/NpgsqlDapperLegacyExample/Models.cs @@ -86,6 +86,7 @@ public class PostgresSpecialType { public Guid? CUuid { get; set; } public CEnum? CEnum { get; set; } + public CEnum? CQualifiedEnum { get; set; } public JsonElement? CJson { get; set; } public JsonElement? CJsonStringOverride { get; set; } public JsonElement? CJsonb { get; set; } @@ -97,10 +98,6 @@ public class PostgresNotNullType { public CEnum CEnumNotNull { get; set; } }; - public class PostgresQualifiedEnumType - { - public CEnum? CQualifiedEnum { get; set; } - }; public class ExtendedBio { public string AuthorName { get; set; } diff --git a/examples/NpgsqlDapperLegacyExample/QuerySql.cs b/examples/NpgsqlDapperLegacyExample/QuerySql.cs index ef99a902..e1671b22 100644 --- a/examples/NpgsqlDapperLegacyExample/QuerySql.cs +++ b/examples/NpgsqlDapperLegacyExample/QuerySql.cs @@ -1359,7 +1359,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( @c_json, @@ -1369,7 +1370,8 @@ INSERT INTO postgres_special_types @c_xml::xml, @c_xml_string_override::xml, @c_uuid, - @c_enum::c_enum + @c_enum::c_enum, + @c_qualified_enum::c_enum )"; public class InsertPostgresSpecialTypesArgs { @@ -1381,6 +1383,7 @@ public class InsertPostgresSpecialTypesArgs public string CXmlStringOverride { get; set; } public Guid? CUuid { get; set; } public CEnum? CEnum { get; set; } + public CEnum? CQualifiedEnum { get; set; } }; public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs args) { @@ -1393,6 +1396,7 @@ public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs queryParams.Add("c_xml_string_override", args.CXmlStringOverride); queryParams.Add("c_uuid", args.CUuid); queryParams.Add("c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : null); + queryParams.Add("c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : null); if (this.Transaction == null) { using (var connection = await GetDataSource().OpenConnectionAsync()) @@ -1485,7 +1489,8 @@ public async Task TruncatePostgresNotNullTypesAsync() c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1"; public class GetPostgresSpecialTypesRow @@ -1498,6 +1503,7 @@ public class GetPostgresSpecialTypesRow public string CXmlStringOverride { get; set; } public Guid? CUuid { get; set; } public CEnum? CEnum { get; set; } + public CEnum? CQualifiedEnum { get; set; } }; public async Task GetPostgresSpecialTypesAsync() { @@ -1888,75 +1894,5 @@ public async Task TruncatePostgresGeoTypesAsync() throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); } - - private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types - ( - c_qualified_enum - ) - VALUES ( - @c_qualified_enum::c_enum - )"; - public class InsertPostgresQualifiedEnumTypesArgs - { - public CEnum? CQualifiedEnum { get; set; } - }; - public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) - { - var queryParams = new Dictionary(); - queryParams.Add("c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : null); - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - await connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams); - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - await this.Transaction.Connection.ExecuteAsync(InsertPostgresQualifiedEnumTypesSql, queryParams, transaction: this.Transaction); - } - - private const string GetPostgresQualifiedEnumTypesSql = @"SELECT - c_qualified_enum - FROM postgres_qualified_enum_types - LIMIT 1"; - public class GetPostgresQualifiedEnumTypesRow - { - public CEnum? CQualifiedEnum { get; set; } - }; - public async Task GetPostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql); - return result; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresQualifiedEnumTypesSql, transaction: this.Transaction); - } - - private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; - public async Task TruncatePostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - await connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql); - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresQualifiedEnumTypesSql, transaction: this.Transaction); - } } } \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/request.json b/examples/NpgsqlDapperLegacyExample/request.json index c37896db..a5048fe8 100644 --- a/examples/NpgsqlDapperLegacyExample/request.json +++ b/examples/NpgsqlDapperLegacyExample/request.json @@ -605,6 +605,17 @@ "name": "c_enum" } }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + }, { "name": "c_json", "length": -1, @@ -686,24 +697,6 @@ } } ] - }, - { - "rel": { - "name": "postgres_qualified_enum_types" - }, - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - } - } - ] } ], "enums": [ @@ -35108,7 +35101,7 @@ } }, { - "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum,\n $9::c_enum\n)", "name": "InsertPostgresSpecialTypes", "cmd": ":exec", "parameters": [ @@ -35210,6 +35203,16 @@ "name": "c_enum" } } + }, + { + "number": 9, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } } ], "comments": [ @@ -35269,7 +35272,7 @@ "filename": "query.sql" }, { - "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\nFROM postgres_special_types \nLIMIT 1", "name": "GetPostgresSpecialTypes", "cmd": ":one", "columns": [ @@ -35362,6 +35365,18 @@ "name": "c_enum" }, "originalName": "c_enum" + }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" } ], "filename": "query.sql" @@ -36247,53 +36262,6 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", - "name": "InsertPostgresQualifiedEnumTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_qualified_enum", - "length": -1, - "type": { - "name": "c_enum" - } - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_qualified_enum_types" - } - }, - { - "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", - "name": "GetPostgresQualifiedEnumTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - }, - "originalName": "c_qualified_enum" - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_qualified_enum_types", - "name": "TruncatePostgresQualifiedEnumTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlDapperLegacyExample/request.message b/examples/NpgsqlDapperLegacyExample/request.message index f299acf4..d5e41b0e 100644 --- a/examples/NpgsqlDapperLegacyExample/request.message +++ b/examples/NpgsqlDapperLegacyExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlb› "examples/NpgsqlDapperLegacyExamplecsharpж{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"netstandard2.0","useDapper":true}* -./dist/LocalRunner–я public"иpublicƒ +./dist/LocalRunnerью public"Ўpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -83,10 +83,11 @@ pg_catalog timestamp c_box0џџџџџџџџџRpostgres_geometric_typesbbox7 c_path0џџџџџџџџџRpostgres_geometric_typesbpath= c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygon; -c_circle0џџџџџџџџџRpostgres_geometric_typesbcircle’ +c_circle0џџџџџџџџџRpostgres_geometric_typesbcircleн postgres_special_types5 c_uuid0џџџџџџџџџRpostgres_special_typesbuuid7 -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumA +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumI +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumA c_json0џџџџџџџџџRpostgres_special_typesb pg_catalogjsonQ c_json_string_override0џџџџџџџџџRpostgres_special_typesb @@ -98,9 +99,7 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums -postgres_qualified_enum_typesP -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10682,8 +10681,8 @@ LIMIT 1GetPostgresNetworkTypesCnt:one"= ) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE c_cidr0џџџџџџџџџR publicpostgres_network_typesbcidrzc_cidr*IE c_inet0џџџџџџџџџR publicpostgres_network_typesbinetzc_inet*RN - c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesП -— + c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_types’ +Н INSERT INTO postgres_special_types ( c_json, @@ -10693,7 +10692,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( $1, @@ -10703,7 +10703,8 @@ VALUES ( $5::xml, $6::xml, $7, - $8::c_enum + $8::c_enum, + $9::c_enum )InsertPostgresSpecialTypes:exec*VR c_json0џџџџџџџџџ8R publicpostgres_special_typesbpg_catalog.jsonzc_json*;7 c_json_string_override0џџџџџџџџџb @@ -10715,7 +10716,8 @@ c_jsonpath0 c_xml0џџџџџџџџџbxml*-) c_xml_string_override0џџџџџџџџџbxml*KG c_uuid0џџџџџџџџџ8R publicpostgres_special_typesbuuidzc_uuid*! -c_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ +c_enum0џџџџџџџџџbc_enum*+ ' +c_qualified_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ UINSERT INTO postgres_not_null_types ( c_enum_not_null @@ -10729,8 +10731,8 @@ VALUES ( FROM postgres_not_null_types LIMIT 1GetPostgresNotNullTypes:one"T c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enumzc_enum_not_null: query.sqlX -&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЕ -­SELECT +&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЈ +УSELECT c_json, c_json_string_override, c_jsonb, @@ -10738,7 +10740,8 @@ LIMIT 1GetPostgresNotNullTypes:one"T c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1GetPostgresSpecialTypes:one"I c_json0џџџџџџџџџRpostgres_special_typesb @@ -10753,7 +10756,8 @@ c_jsonpath": c_xml0џџџџџџџџџRpostgres_special_typesbxmlzc_xml"Z c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxmlzc_xml_string_override"= c_uuid0џџџџџџџџџRpostgres_special_typesbuuidzc_uuid"? -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum: query.sqlW +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum"[ +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumzc_qualified_enum: query.sqlW %TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlЎ lINSERT INTO postgres_special_types ( @@ -10919,18 +10923,4 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр -\INSERT INTO postgres_qualified_enum_types -( - c_qualified_enum -) -VALUES ( - $1::c_enum -) InsertPostgresQualifiedEnumTypes:exec*+' -c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм -FSELECT - c_qualified_enum -FROM postgres_qualified_enum_types -LIMIT 1GetPostgresQualifiedEnumTypes:one"b -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld -,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*Ш{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlDapperLegacyExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*Ш{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlDapperLegacyExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/NpgsqlExample/Models.cs b/examples/NpgsqlExample/Models.cs index 933572fb..f5ef582f 100644 --- a/examples/NpgsqlExample/Models.cs +++ b/examples/NpgsqlExample/Models.cs @@ -19,9 +19,8 @@ namespace NpgsqlExampleGen; public readonly record struct PostgresNetworkType(NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, string? CMacaddr8); public readonly record struct PostgresArrayType(byte[]? CBytea, bool[]? CBooleanArray, string[]? CTextArray, int[]? CIntegerArray, decimal[]? CDecimalArray, DateTime[]? CDateArray, DateTime[]? CTimestampArray); public readonly record struct PostgresGeometricType(NpgsqlPoint? CPoint, NpgsqlLine? CLine, NpgsqlLSeg? CLseg, NpgsqlBox? CBox, NpgsqlPath? CPath, NpgsqlPolygon? CPolygon, NpgsqlCircle? CCircle); -public readonly record struct PostgresSpecialType(Guid? CUuid, CEnum? CEnum, JsonElement? CJson, JsonElement? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, XmlDocument? CXmlStringOverride); +public readonly record struct PostgresSpecialType(Guid? CUuid, CEnum? CEnum, CEnum? CQualifiedEnum, JsonElement? CJson, JsonElement? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, XmlDocument? CXmlStringOverride); public readonly record struct PostgresNotNullType(CEnum CEnumNotNull); -public readonly record struct PostgresQualifiedEnumType(CEnum? CQualifiedEnum); public readonly record struct ExtendedBio(string AuthorName, string Name, ExtendedBioType? BioType); public enum CEnum { diff --git a/examples/NpgsqlExample/QuerySql.cs b/examples/NpgsqlExample/QuerySql.cs index 6d7c56d0..9fcf3439 100644 --- a/examples/NpgsqlExample/QuerySql.cs +++ b/examples/NpgsqlExample/QuerySql.cs @@ -1891,7 +1891,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( @c_json, @@ -1901,9 +1902,10 @@ INSERT INTO postgres_special_types @c_xml::xml, @c_xml_string_override::xml, @c_uuid, - @c_enum::c_enum + @c_enum::c_enum, + @c_qualified_enum::c_enum )"; - public readonly record struct InsertPostgresSpecialTypesArgs(JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, string? CXmlStringOverride, Guid? CUuid, CEnum? CEnum); + public readonly record struct InsertPostgresSpecialTypesArgs(JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, string? CXmlStringOverride, Guid? CUuid, CEnum? CEnum, CEnum? CQualifiedEnum); public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs args) { if (this.Transaction == null) @@ -1921,6 +1923,7 @@ public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs command.Parameters.AddWithValue("@c_xml_string_override", NpgsqlDbType.Xml, args.CXmlStringOverride ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } @@ -1942,6 +1945,7 @@ public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs command.Parameters.AddWithValue("@c_xml_string_override", NpgsqlDbType.Xml, args.CXmlStringOverride ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -2067,10 +2071,11 @@ public async Task TruncatePostgresNotNullTypesAsync() c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1"; - public readonly record struct GetPostgresSpecialTypesRow(JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, string? CXmlStringOverride, Guid? CUuid, CEnum? CEnum); + public readonly record struct GetPostgresSpecialTypesRow(JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, string? CXmlStringOverride, Guid? CUuid, CEnum? CEnum, CEnum? CQualifiedEnum); public async Task GetPostgresSpecialTypesAsync() { if (this.Transaction == null) @@ -2098,7 +2103,8 @@ FROM postgres_special_types }))(reader, 4), CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), CUuid = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), - CEnum = reader.IsDBNull(7) ? null : reader.GetString(7).ToCEnum() + CEnum = reader.IsDBNull(7) ? null : reader.GetString(7).ToCEnum(), + CQualifiedEnum = reader.IsDBNull(8) ? null : reader.GetString(8).ToCEnum() }; } } @@ -2131,7 +2137,8 @@ FROM postgres_special_types }))(reader, 4), CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), CUuid = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), - CEnum = reader.IsDBNull(7) ? null : reader.GetString(7).ToCEnum() + CEnum = reader.IsDBNull(7) ? null : reader.GetString(7).ToCEnum(), + CQualifiedEnum = reader.IsDBNull(8) ? null : reader.GetString(8).ToCEnum() }; } } @@ -2660,117 +2667,4 @@ public async Task TruncatePostgresGeoTypesAsync() await command.ExecuteNonQueryAsync(); } } - - private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types - ( - c_qualified_enum - ) - VALUES ( - @c_qualified_enum::c_enum - )"; - public readonly record struct InsertPostgresQualifiedEnumTypesArgs(CEnum? CQualifiedEnum); - public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - using (var command = connection.CreateCommand()) - { - command.CommandText = InsertPostgresQualifiedEnumTypesSql; - command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); - } - - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = InsertPostgresQualifiedEnumTypesSql; - command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); - } - } - - private const string GetPostgresQualifiedEnumTypesSql = @"SELECT - c_qualified_enum - FROM postgres_qualified_enum_types - LIMIT 1"; - public readonly record struct GetPostgresQualifiedEnumTypesRow(CEnum? CQualifiedEnum); - public async Task GetPostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - using (var command = connection.CreateCommand()) - { - command.CommandText = GetPostgresQualifiedEnumTypesSql; - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetPostgresQualifiedEnumTypesRow - { - CQualifiedEnum = reader.IsDBNull(0) ? null : reader.GetString(0).ToCEnum() - }; - } - } - } - }; - return null; - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = GetPostgresQualifiedEnumTypesSql; - command.Transaction = this.Transaction; - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetPostgresQualifiedEnumTypesRow - { - CQualifiedEnum = reader.IsDBNull(0) ? null : reader.GetString(0).ToCEnum() - }; - } - } - } - - return null; - } - - private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; - public async Task TruncatePostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - using (var command = connection.CreateCommand()) - { - command.CommandText = TruncatePostgresQualifiedEnumTypesSql; - await command.ExecuteNonQueryAsync(); - } - - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = TruncatePostgresQualifiedEnumTypesSql; - command.Transaction = this.Transaction; - await command.ExecuteNonQueryAsync(); - } - } } \ No newline at end of file diff --git a/examples/NpgsqlExample/request.json b/examples/NpgsqlExample/request.json index e88d6d62..26b5e72b 100644 --- a/examples/NpgsqlExample/request.json +++ b/examples/NpgsqlExample/request.json @@ -605,6 +605,17 @@ "name": "c_enum" } }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + }, { "name": "c_json", "length": -1, @@ -686,24 +697,6 @@ } } ] - }, - { - "rel": { - "name": "postgres_qualified_enum_types" - }, - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - } - } - ] } ], "enums": [ @@ -35108,7 +35101,7 @@ } }, { - "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum,\n $9::c_enum\n)", "name": "InsertPostgresSpecialTypes", "cmd": ":exec", "parameters": [ @@ -35210,6 +35203,16 @@ "name": "c_enum" } } + }, + { + "number": 9, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } } ], "comments": [ @@ -35269,7 +35272,7 @@ "filename": "query.sql" }, { - "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\nFROM postgres_special_types \nLIMIT 1", "name": "GetPostgresSpecialTypes", "cmd": ":one", "columns": [ @@ -35362,6 +35365,18 @@ "name": "c_enum" }, "originalName": "c_enum" + }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" } ], "filename": "query.sql" @@ -36247,53 +36262,6 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", - "name": "InsertPostgresQualifiedEnumTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_qualified_enum", - "length": -1, - "type": { - "name": "c_enum" - } - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_qualified_enum_types" - } - }, - { - "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", - "name": "GetPostgresQualifiedEnumTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - }, - "originalName": "c_qualified_enum" - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_qualified_enum_types", - "name": "TruncatePostgresQualifiedEnumTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlExample/request.message b/examples/NpgsqlExample/request.message index a9191654..5e1dd48e 100644 --- a/examples/NpgsqlExample/request.message +++ b/examples/NpgsqlExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlbќ examples/NpgsqlExamplecsharpУ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"net8.0","useDapper":false}* -./dist/LocalRunner–я public"иpublicƒ +./dist/LocalRunnerью public"Ўpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -83,10 +83,11 @@ pg_catalog timestamp c_box0џџџџџџџџџRpostgres_geometric_typesbbox7 c_path0џџџџџџџџџRpostgres_geometric_typesbpath= c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygon; -c_circle0џџџџџџџџџRpostgres_geometric_typesbcircle’ +c_circle0џџџџџџџџџRpostgres_geometric_typesbcircleн postgres_special_types5 c_uuid0џџџџџџџџџRpostgres_special_typesbuuid7 -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumA +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumI +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumA c_json0џџџџџџџџџRpostgres_special_typesb pg_catalogjsonQ c_json_string_override0џџџџџџџџџRpostgres_special_typesb @@ -98,9 +99,7 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums -postgres_qualified_enum_typesP -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10682,8 +10681,8 @@ LIMIT 1GetPostgresNetworkTypesCnt:one"= ) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE c_cidr0џџџџџџџџџR publicpostgres_network_typesbcidrzc_cidr*IE c_inet0џџџџџџџџџR publicpostgres_network_typesbinetzc_inet*RN - c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesП -— + c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_types’ +Н INSERT INTO postgres_special_types ( c_json, @@ -10693,7 +10692,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( $1, @@ -10703,7 +10703,8 @@ VALUES ( $5::xml, $6::xml, $7, - $8::c_enum + $8::c_enum, + $9::c_enum )InsertPostgresSpecialTypes:exec*VR c_json0џџџџџџџџџ8R publicpostgres_special_typesbpg_catalog.jsonzc_json*;7 c_json_string_override0џџџџџџџџџb @@ -10715,7 +10716,8 @@ c_jsonpath0 c_xml0џџџџџџџџџbxml*-) c_xml_string_override0џџџџџџџџџbxml*KG c_uuid0џџџџџџџџџ8R publicpostgres_special_typesbuuidzc_uuid*! -c_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ +c_enum0џџџџџџџџџbc_enum*+ ' +c_qualified_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ UINSERT INTO postgres_not_null_types ( c_enum_not_null @@ -10729,8 +10731,8 @@ VALUES ( FROM postgres_not_null_types LIMIT 1GetPostgresNotNullTypes:one"T c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enumzc_enum_not_null: query.sqlX -&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЕ -­SELECT +&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЈ +УSELECT c_json, c_json_string_override, c_jsonb, @@ -10738,7 +10740,8 @@ LIMIT 1GetPostgresNotNullTypes:one"T c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1GetPostgresSpecialTypes:one"I c_json0џџџџџџџџџRpostgres_special_typesb @@ -10753,7 +10756,8 @@ c_jsonpath": c_xml0џџџџџџџџџRpostgres_special_typesbxmlzc_xml"Z c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxmlzc_xml_string_override"= c_uuid0џџџџџџџџџRpostgres_special_typesbuuidzc_uuid"? -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum: query.sqlW +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum"[ +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumzc_qualified_enum: query.sqlW %TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlЎ lINSERT INTO postgres_special_types ( @@ -10919,18 +10923,4 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр -\INSERT INTO postgres_qualified_enum_types -( - c_qualified_enum -) -VALUES ( - $1::c_enum -) InsertPostgresQualifiedEnumTypes:exec*+' -c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм -FSELECT - c_qualified_enum -FROM postgres_qualified_enum_types -LIMIT 1GetPostgresQualifiedEnumTypes:one"b -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld -,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*Е{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*Е{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/NpgsqlLegacyExample/Models.cs b/examples/NpgsqlLegacyExample/Models.cs index 81ef272b..413490ec 100644 --- a/examples/NpgsqlLegacyExample/Models.cs +++ b/examples/NpgsqlLegacyExample/Models.cs @@ -86,6 +86,7 @@ public class PostgresSpecialType { public Guid? CUuid { get; set; } public CEnum? CEnum { get; set; } + public CEnum? CQualifiedEnum { get; set; } public JsonElement? CJson { get; set; } public JsonElement? CJsonStringOverride { get; set; } public JsonElement? CJsonb { get; set; } @@ -97,10 +98,6 @@ public class PostgresNotNullType { public CEnum CEnumNotNull { get; set; } }; - public class PostgresQualifiedEnumType - { - public CEnum? CQualifiedEnum { get; set; } - }; public class ExtendedBio { public string AuthorName { get; set; } diff --git a/examples/NpgsqlLegacyExample/QuerySql.cs b/examples/NpgsqlLegacyExample/QuerySql.cs index bb5efbea..e6c80edf 100644 --- a/examples/NpgsqlLegacyExample/QuerySql.cs +++ b/examples/NpgsqlLegacyExample/QuerySql.cs @@ -2148,7 +2148,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( @c_json, @@ -2158,7 +2159,8 @@ INSERT INTO postgres_special_types @c_xml::xml, @c_xml_string_override::xml, @c_uuid, - @c_enum::c_enum + @c_enum::c_enum, + @c_qualified_enum::c_enum )"; public class InsertPostgresSpecialTypesArgs { @@ -2170,6 +2172,7 @@ public class InsertPostgresSpecialTypesArgs public string CXmlStringOverride { get; set; } public Guid? CUuid { get; set; } public CEnum? CEnum { get; set; } + public CEnum? CQualifiedEnum { get; set; } }; public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs args) { @@ -2188,6 +2191,7 @@ public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs command.Parameters.AddWithValue("@c_xml_string_override", NpgsqlDbType.Xml, args.CXmlStringOverride ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } @@ -2209,6 +2213,7 @@ public async Task InsertPostgresSpecialTypesAsync(InsertPostgresSpecialTypesArgs command.Parameters.AddWithValue("@c_xml_string_override", NpgsqlDbType.Xml, args.CXmlStringOverride ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -2340,7 +2345,8 @@ public async Task TruncatePostgresNotNullTypesAsync() c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1"; public class GetPostgresSpecialTypesRow @@ -2353,6 +2359,7 @@ public class GetPostgresSpecialTypesRow public string CXmlStringOverride { get; set; } public Guid? CUuid { get; set; } public CEnum? CEnum { get; set; } + public CEnum? CQualifiedEnum { get; set; } }; public async Task GetPostgresSpecialTypesAsync() { @@ -2381,7 +2388,8 @@ public async Task GetPostgresSpecialTypesAsync() }))(reader, 4), CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), CUuid = reader.IsDBNull(6) ? (Guid? )null : reader.GetFieldValue(6), - CEnum = reader.IsDBNull(7) ? (CEnum? )null : reader.GetString(7).ToCEnum() + CEnum = reader.IsDBNull(7) ? (CEnum? )null : reader.GetString(7).ToCEnum(), + CQualifiedEnum = reader.IsDBNull(8) ? (CEnum? )null : reader.GetString(8).ToCEnum() }; } } @@ -2414,7 +2422,8 @@ public async Task GetPostgresSpecialTypesAsync() }))(reader, 4), CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), CUuid = reader.IsDBNull(6) ? (Guid? )null : reader.GetFieldValue(6), - CEnum = reader.IsDBNull(7) ? (CEnum? )null : reader.GetString(7).ToCEnum() + CEnum = reader.IsDBNull(7) ? (CEnum? )null : reader.GetString(7).ToCEnum(), + CQualifiedEnum = reader.IsDBNull(8) ? (CEnum? )null : reader.GetString(8).ToCEnum() }; } } @@ -3016,124 +3025,5 @@ public async Task TruncatePostgresGeoTypesAsync() await command.ExecuteNonQueryAsync(); } } - - private const string InsertPostgresQualifiedEnumTypesSql = @"INSERT INTO postgres_qualified_enum_types - ( - c_qualified_enum - ) - VALUES ( - @c_qualified_enum::c_enum - )"; - public class InsertPostgresQualifiedEnumTypesArgs - { - public CEnum? CQualifiedEnum { get; set; } - }; - public async Task InsertPostgresQualifiedEnumTypesAsync(InsertPostgresQualifiedEnumTypesArgs args) - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - using (var command = connection.CreateCommand()) - { - command.CommandText = InsertPostgresQualifiedEnumTypesSql; - command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); - } - - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = InsertPostgresQualifiedEnumTypesSql; - command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_qualified_enum", args.CQualifiedEnum != null ? args.CQualifiedEnum.Value.Stringify() : (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); - } - } - - private const string GetPostgresQualifiedEnumTypesSql = @"SELECT - c_qualified_enum - FROM postgres_qualified_enum_types - LIMIT 1"; - public class GetPostgresQualifiedEnumTypesRow - { - public CEnum? CQualifiedEnum { get; set; } - }; - public async Task GetPostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - using (var command = connection.CreateCommand()) - { - command.CommandText = GetPostgresQualifiedEnumTypesSql; - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetPostgresQualifiedEnumTypesRow - { - CQualifiedEnum = reader.IsDBNull(0) ? (CEnum? )null : reader.GetString(0).ToCEnum() - }; - } - } - } - }; - return null; - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = GetPostgresQualifiedEnumTypesSql; - command.Transaction = this.Transaction; - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetPostgresQualifiedEnumTypesRow - { - CQualifiedEnum = reader.IsDBNull(0) ? (CEnum? )null : reader.GetString(0).ToCEnum() - }; - } - } - } - - return null; - } - - private const string TruncatePostgresQualifiedEnumTypesSql = "TRUNCATE TABLE postgres_qualified_enum_types"; - public async Task TruncatePostgresQualifiedEnumTypesAsync() - { - if (this.Transaction == null) - { - using (var connection = await GetDataSource().OpenConnectionAsync()) - { - using (var command = connection.CreateCommand()) - { - command.CommandText = TruncatePostgresQualifiedEnumTypesSql; - await command.ExecuteNonQueryAsync(); - } - - return; - } - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = TruncatePostgresQualifiedEnumTypesSql; - command.Transaction = this.Transaction; - await command.ExecuteNonQueryAsync(); - } - } } } \ No newline at end of file diff --git a/examples/NpgsqlLegacyExample/request.json b/examples/NpgsqlLegacyExample/request.json index 457510e8..bb5d6f71 100644 --- a/examples/NpgsqlLegacyExample/request.json +++ b/examples/NpgsqlLegacyExample/request.json @@ -605,6 +605,17 @@ "name": "c_enum" } }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + } + }, { "name": "c_json", "length": -1, @@ -686,24 +697,6 @@ } } ] - }, - { - "rel": { - "name": "postgres_qualified_enum_types" - }, - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - } - } - ] } ], "enums": [ @@ -35108,7 +35101,7 @@ } }, { - "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\n)\nVALUES (\n $1, \n $2::json, \n $3,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum,\n $9::c_enum\n)", "name": "InsertPostgresSpecialTypes", "cmd": ":exec", "parameters": [ @@ -35210,6 +35203,16 @@ "name": "c_enum" } } + }, + { + "number": 9, + "column": { + "name": "c_qualified_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } } ], "comments": [ @@ -35269,7 +35272,7 @@ "filename": "query.sql" }, { - "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum,\n c_qualified_enum\nFROM postgres_special_types \nLIMIT 1", "name": "GetPostgresSpecialTypes", "cmd": ":one", "columns": [ @@ -35362,6 +35365,18 @@ "name": "c_enum" }, "originalName": "c_enum" + }, + { + "name": "c_qualified_enum", + "length": -1, + "table": { + "name": "postgres_special_types" + }, + "type": { + "schema": "public", + "name": "c_enum" + }, + "originalName": "c_qualified_enum" } ], "filename": "query.sql" @@ -36247,53 +36262,6 @@ "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_qualified_enum_types\n(\n c_qualified_enum\n)\nVALUES (\n $1::c_enum\n)", - "name": "InsertPostgresQualifiedEnumTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_qualified_enum", - "length": -1, - "type": { - "name": "c_enum" - } - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_qualified_enum_types" - } - }, - { - "text": "SELECT\n c_qualified_enum\nFROM postgres_qualified_enum_types\nLIMIT 1", - "name": "GetPostgresQualifiedEnumTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_qualified_enum", - "length": -1, - "table": { - "name": "postgres_qualified_enum_types" - }, - "type": { - "schema": "public", - "name": "c_enum" - }, - "originalName": "c_qualified_enum" - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_qualified_enum_types", - "name": "TruncatePostgresQualifiedEnumTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.30.0", diff --git a/examples/NpgsqlLegacyExample/request.message b/examples/NpgsqlLegacyExample/request.message index 8b3dfd4b..ed99c5dd 100644 --- a/examples/NpgsqlLegacyExample/request.message +++ b/examples/NpgsqlLegacyExample/request.message @@ -3,7 +3,7 @@ 2 postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlb examples/NpgsqlLegacyExamplecsharpб{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"notNull":false,"type":"JsonElement"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"notNull":false,"type":"Instant"}}],"targetFramework":"netstandard2.0","useDapper":false}* -./dist/LocalRunner–я public"иpublicƒ +./dist/LocalRunnerью public"Ўpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -83,10 +83,11 @@ pg_catalog timestamp c_box0џџџџџџџџџRpostgres_geometric_typesbbox7 c_path0џџџџџџџџџRpostgres_geometric_typesbpath= c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygon; -c_circle0џџџџџџџџџRpostgres_geometric_typesbcircle’ +c_circle0џџџџџџџџџRpostgres_geometric_typesbcircleн postgres_special_types5 c_uuid0џџџџџџџџџRpostgres_special_typesbuuid7 -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumA +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumI +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumA c_json0џџџџџџџџџRpostgres_special_typesb pg_catalogjsonQ c_json_string_override0џџџџџџџџџRpostgres_special_typesb @@ -98,9 +99,7 @@ c_jsonpath0 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` postgres_not_null_typesC -c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enums -postgres_qualified_enum_typesP -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enum" +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10682,8 +10681,8 @@ LIMIT 1GetPostgresNetworkTypesCnt:one"= ) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE c_cidr0џџџџџџџџџR publicpostgres_network_typesbcidrzc_cidr*IE c_inet0џџџџџџџџџR publicpostgres_network_typesbinetzc_inet*RN - c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesП -— + c_macaddr0џџџџџџџџџR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_types’ +Н INSERT INTO postgres_special_types ( c_json, @@ -10693,7 +10692,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( $1, @@ -10703,7 +10703,8 @@ VALUES ( $5::xml, $6::xml, $7, - $8::c_enum + $8::c_enum, + $9::c_enum )InsertPostgresSpecialTypes:exec*VR c_json0џџџџџџџџџ8R publicpostgres_special_typesbpg_catalog.jsonzc_json*;7 c_json_string_override0џџџџџџџџџb @@ -10715,7 +10716,8 @@ c_jsonpath0 c_xml0џџџџџџџџџbxml*-) c_xml_string_override0џџџџџџџџџbxml*KG c_uuid0џџџџџџџџџ8R publicpostgres_special_typesbuuidzc_uuid*! -c_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ +c_enum0џџџџџџџџџbc_enum*+ ' +c_qualified_enum0џџџџџџџџџbc_enum2 Special types : query.sqlBpostgres_special_typesЮ UINSERT INTO postgres_not_null_types ( c_enum_not_null @@ -10729,8 +10731,8 @@ VALUES ( FROM postgres_not_null_types LIMIT 1GetPostgresNotNullTypes:one"T c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enumzc_enum_not_null: query.sqlX -&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЕ -­SELECT +&TRUNCATE TABLE postgres_not_null_typesTruncatePostgresNotNullTypes:exec: query.sqlЈ +УSELECT c_json, c_json_string_override, c_jsonb, @@ -10738,7 +10740,8 @@ LIMIT 1GetPostgresNotNullTypes:one"T c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1GetPostgresSpecialTypes:one"I c_json0џџџџџџџџџRpostgres_special_typesb @@ -10753,7 +10756,8 @@ c_jsonpath": c_xml0џџџџџџџџџRpostgres_special_typesbxmlzc_xml"Z c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxmlzc_xml_string_override"= c_uuid0џџџџџџџџџRpostgres_special_typesbuuidzc_uuid"? -c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum: query.sqlW +c_enum0џџџџџџџџџRpostgres_special_typesbc_enumzc_enum"[ +c_qualified_enum0џџџџџџџџџRpostgres_special_typesbpublicc_enumzc_qualified_enum: query.sqlW %TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlЎ lINSERT INTO postgres_special_types ( @@ -10919,18 +10923,4 @@ hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgre c_path0џџџџџџџџџRpostgres_geometric_typesbpathzc_path"H c_polygon0џџџџџџџџџRpostgres_geometric_typesb polygonz c_polygon"E c_circle0џџџџџџџџџRpostgres_geometric_typesbcirclezc_circle: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlр -\INSERT INTO postgres_qualified_enum_types -( - c_qualified_enum -) -VALUES ( - $1::c_enum -) InsertPostgresQualifiedEnumTypes:exec*+' -c_qualified_enum0џџџџџџџџџbc_enum: query.sqlBpostgres_qualified_enum_typesм -FSELECT - c_qualified_enum -FROM postgres_qualified_enum_types -LIMIT 1GetPostgresQualifiedEnumTypes:one"b -c_qualified_enum0џџџџџџџџџRpostgres_qualified_enum_typesbpublicc_enumzc_qualified_enum: query.sqld -,TRUNCATE TABLE postgres_qualified_enum_types"TruncatePostgresQualifiedEnumTypes:exec: query.sql"v1.30.0*У{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlLegacyExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.30.0*У{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlLegacyExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"GetPostgresSpecialTypesCnt:c_json","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"GetPostgresSpecialTypesCnt:c_jsonb","csharp_type":{"type":"JsonElement","notNull":false}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_timestamp_noda_instant_override","csharp_type":{"type":"Instant","notNull":false}}],"debugRequest":false,"useCentralPackageManagement":false,"withAsyncSuffix":true} \ No newline at end of file diff --git a/examples/config/postgresql/types/query.sql b/examples/config/postgresql/types/query.sql index eb22195b..29de1a15 100644 --- a/examples/config/postgresql/types/query.sql +++ b/examples/config/postgresql/types/query.sql @@ -241,7 +241,8 @@ INSERT INTO postgres_special_types c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum ) VALUES ( sqlc.narg('c_json'), @@ -251,7 +252,8 @@ VALUES ( sqlc.narg('c_xml')::xml, sqlc.narg('c_xml_string_override')::xml, sqlc.narg('c_uuid'), - sqlc.narg('c_enum')::c_enum + sqlc.narg('c_enum')::c_enum, + sqlc.narg('c_qualified_enum')::c_enum ); -- name: InsertPostgresNotNullTypes :exec @@ -281,7 +283,8 @@ SELECT c_xml, c_xml_string_override, c_uuid, - c_enum + c_enum, + c_qualified_enum FROM postgres_special_types LIMIT 1; @@ -413,20 +416,3 @@ SELECT * FROM postgres_geometric_types LIMIT 1; -- name: TruncatePostgresGeoTypes :exec TRUNCATE TABLE postgres_geometric_types; --- name: InsertPostgresQualifiedEnumTypes :exec -INSERT INTO postgres_qualified_enum_types -( - c_qualified_enum -) -VALUES ( - sqlc.narg('c_qualified_enum')::c_enum -); - --- name: GetPostgresQualifiedEnumTypes :one -SELECT - c_qualified_enum -FROM postgres_qualified_enum_types -LIMIT 1; - --- name: TruncatePostgresQualifiedEnumTypes :exec -TRUNCATE TABLE postgres_qualified_enum_types; diff --git a/examples/config/postgresql/types/schema.sql b/examples/config/postgresql/types/schema.sql index 7f11a723..069c5545 100644 --- a/examples/config/postgresql/types/schema.sql +++ b/examples/config/postgresql/types/schema.sql @@ -67,6 +67,7 @@ CREATE TYPE c_enum AS ENUM ('small', 'medium', 'big'); CREATE TABLE postgres_special_types ( c_uuid UUID, c_enum c_enum, + c_qualified_enum public.c_enum, c_json JSON, c_json_string_override JSON, c_jsonb JSONB, @@ -77,8 +78,4 @@ CREATE TABLE postgres_special_types ( CREATE TABLE postgres_not_null_types ( c_enum_not_null c_enum NOT NULL DEFAULT 'small' -); - -CREATE TABLE postgres_qualified_enum_types ( - c_qualified_enum public.c_enum ); \ No newline at end of file