diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11b88b36..fed4c605 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,6 @@ defaults: env: SQLC_VERSION: 1.30.0 WASI_SDK_VERSION: 22 - DOTNET_VERSION: '8.0.x' on: push: @@ -33,7 +32,7 @@ jobs: - name: Setup Dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: ${{ env.DOTNET_VERSION }} + global-json-file: global.json - name: install Wasi workload run: dotnet workload install wasi-experimental @@ -74,7 +73,7 @@ jobs: - name: Set up .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: ${{ env.DOTNET_VERSION }} + global-json-file: global.json - name: .NET Lint uses: zyactions/dotnet-lint@v1 @@ -101,7 +100,7 @@ jobs: - name: Setup Dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: ${{ env.DOTNET_VERSION }} + global-json-file: global.json - uses: sqlc-dev/setup-sqlc@v4 with: diff --git a/end2end/EndToEndScaffold/Config.cs b/end2end/EndToEndScaffold/Config.cs index 3d734c95..c529a977 100644 --- a/end2end/EndToEndScaffold/Config.cs +++ b/end2end/EndToEndScaffold/Config.cs @@ -56,6 +56,7 @@ public enum KnownTestType PostgresJsonDataTypes, PostgresXmlDataTypes, PostgresEnumDataType, + PostgresNotNullTypes, // :copyfrom (Batch) PostgresStringCopyFrom, @@ -171,6 +172,7 @@ internal static class Config KnownTestType.PostgresNetworkDataTypes, KnownTestType.PostgresXmlDataTypes, KnownTestType.PostgresEnumDataType, + KnownTestType.PostgresNotNullTypes, KnownTestType.PostgresFullTextSearchDataTypes, // :copyfrom (Batch) diff --git a/end2end/EndToEndScaffold/Templates/PostgresTests.cs b/end2end/EndToEndScaffold/Templates/PostgresTests.cs index 2f39564d..01f8f2a6 100644 --- a/end2end/EndToEndScaffold/Templates/PostgresTests.cs +++ b/end2end/EndToEndScaffold/Templates/PostgresTests.cs @@ -1192,9 +1192,11 @@ void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesCntRow x, QuerySql.Get { Impl = $$""" [Test] + [TestCase(CEnum.Small)] [TestCase(CEnum.Medium)] + [TestCase(CEnum.Big)] [TestCase(null)] - public async Task TestPostgresStringTypes(CEnum? cEnum) + public async Task TestPostgresEnumTypes(CEnum? cEnum) { await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { @@ -1215,6 +1217,32 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } """ }, + [KnownTestType.PostgresNotNullTypes] = new TestImpl + { + Impl = $$""" + [Test] + [TestCase(CEnum.Small)] + public async Task TestPostgresNotNullTypes(CEnum cEnumNotNull) + { + await QuerySql.InsertPostgresNotNullTypes(new QuerySql.InsertPostgresNotNullTypesArgs + { + CEnumNotNull = cEnumNotNull + }); + + var expected = new QuerySql.GetPostgresNotNullTypesRow + { + CEnumNotNull = cEnumNotNull + }; + var actual = await QuerySql.GetPostgresNotNullTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetPostgresNotNullTypesRow x, QuerySql.GetPostgresNotNullTypesRow y) + { + Assert.That(x.CEnumNotNull, Is.EqualTo(y.CEnumNotNull)); + } + } + """ + }, [KnownTestType.PostgresFullTextSearchDataTypes] = new TestImpl { Impl = $$""" diff --git a/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs b/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs index 9846951f..4d667348 100644 --- a/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs +++ b/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs @@ -729,9 +729,11 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } [Test] + [TestCase(CEnum.Small)] [TestCase(CEnum.Medium)] + [TestCase(CEnum.Big)] [TestCase(null)] - public async Task TestPostgresStringTypes(CEnum? cEnum) + public async Task TestPostgresEnumTypes(CEnum? cEnum) { await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); var expected = new QuerySql.GetPostgresSpecialTypesRow @@ -746,6 +748,23 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } } + [Test] + [TestCase(CEnum.Small)] + public async Task TestPostgresNotNullTypes(CEnum cEnumNotNull) + { + await QuerySql.InsertPostgresNotNullTypes(new QuerySql.InsertPostgresNotNullTypesArgs { CEnumNotNull = cEnumNotNull }); + var expected = new QuerySql.GetPostgresNotNullTypesRow + { + CEnumNotNull = cEnumNotNull + }; + var actual = await QuerySql.GetPostgresNotNullTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresNotNullTypesRow x, QuerySql.GetPostgresNotNullTypesRow y) + { + Assert.That(x.CEnumNotNull, Is.EqualTo(y.CEnumNotNull)); + } + } + [Test] [TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Yoshimi Battles the Pink Robots", "Never Mind the Bollocks...")] [TestCase(10, null, null, null, null, null)] diff --git a/end2end/EndToEndTests/NpgsqlTester.cs b/end2end/EndToEndTests/NpgsqlTester.cs index adddd5ba..25c73241 100644 --- a/end2end/EndToEndTests/NpgsqlTester.cs +++ b/end2end/EndToEndTests/NpgsqlTester.cs @@ -21,5 +21,6 @@ public async Task EmptyTestsTables() await QuerySql.TruncatePostgresNetworkTypes(); await QuerySql.TruncatePostgresArrayTypes(); await QuerySql.TruncatePostgresSpecialTypes(); + await QuerySql.TruncatePostgresNotNullTypes(); } } \ No newline at end of file diff --git a/end2end/EndToEndTests/NpgsqlTester.generated.cs b/end2end/EndToEndTests/NpgsqlTester.generated.cs index 4986884b..1a467a17 100644 --- a/end2end/EndToEndTests/NpgsqlTester.generated.cs +++ b/end2end/EndToEndTests/NpgsqlTester.generated.cs @@ -729,9 +729,11 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } [Test] + [TestCase(CEnum.Small)] [TestCase(CEnum.Medium)] + [TestCase(CEnum.Big)] [TestCase(null)] - public async Task TestPostgresStringTypes(CEnum? cEnum) + public async Task TestPostgresEnumTypes(CEnum? cEnum) { await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); var expected = new QuerySql.GetPostgresSpecialTypesRow @@ -746,6 +748,23 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } } + [Test] + [TestCase(CEnum.Small)] + public async Task TestPostgresNotNullTypes(CEnum cEnumNotNull) + { + await QuerySql.InsertPostgresNotNullTypes(new QuerySql.InsertPostgresNotNullTypesArgs { CEnumNotNull = cEnumNotNull }); + var expected = new QuerySql.GetPostgresNotNullTypesRow + { + CEnumNotNull = cEnumNotNull + }; + var actual = await QuerySql.GetPostgresNotNullTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresNotNullTypesRow x, QuerySql.GetPostgresNotNullTypesRow y) + { + Assert.That(x.CEnumNotNull, Is.EqualTo(y.CEnumNotNull)); + } + } + [Test] [TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Yoshimi Battles the Pink Robots", "Never Mind the Bollocks...")] [TestCase(10, null, null, null, null, null)] diff --git a/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs b/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs index b7d6db63..9138efad 100644 --- a/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs @@ -729,9 +729,11 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } [Test] + [TestCase(CEnum.Small)] [TestCase(CEnum.Medium)] + [TestCase(CEnum.Big)] [TestCase(null)] - public async Task TestPostgresStringTypes(CEnum? cEnum) + public async Task TestPostgresEnumTypes(CEnum? cEnum) { await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); var expected = new QuerySql.GetPostgresSpecialTypesRow @@ -746,6 +748,23 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } } + [Test] + [TestCase(CEnum.Small)] + public async Task TestPostgresNotNullTypes(CEnum cEnumNotNull) + { + await QuerySql.InsertPostgresNotNullTypes(new QuerySql.InsertPostgresNotNullTypesArgs { CEnumNotNull = cEnumNotNull }); + var expected = new QuerySql.GetPostgresNotNullTypesRow + { + CEnumNotNull = cEnumNotNull + }; + var actual = await QuerySql.GetPostgresNotNullTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresNotNullTypesRow x, QuerySql.GetPostgresNotNullTypesRow y) + { + Assert.That(x.CEnumNotNull, Is.EqualTo(y.CEnumNotNull)); + } + } + [Test] [TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Yoshimi Battles the Pink Robots", "Never Mind the Bollocks...")] [TestCase(10, null, null, null, null, null)] diff --git a/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs b/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs index 74db6e76..e40e92e5 100644 --- a/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs @@ -729,9 +729,11 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } [Test] + [TestCase(CEnum.Small)] [TestCase(CEnum.Medium)] + [TestCase(CEnum.Big)] [TestCase(null)] - public async Task TestPostgresStringTypes(CEnum? cEnum) + public async Task TestPostgresEnumTypes(CEnum? cEnum) { await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); var expected = new QuerySql.GetPostgresSpecialTypesRow @@ -746,6 +748,23 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos } } + [Test] + [TestCase(CEnum.Small)] + public async Task TestPostgresNotNullTypes(CEnum cEnumNotNull) + { + await QuerySql.InsertPostgresNotNullTypes(new QuerySql.InsertPostgresNotNullTypesArgs { CEnumNotNull = cEnumNotNull }); + var expected = new QuerySql.GetPostgresNotNullTypesRow + { + CEnumNotNull = cEnumNotNull + }; + var actual = await QuerySql.GetPostgresNotNullTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresNotNullTypesRow x, QuerySql.GetPostgresNotNullTypesRow y) + { + Assert.That(x.CEnumNotNull, Is.EqualTo(y.CEnumNotNull)); + } + } + [Test] [TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Yoshimi Battles the Pink Robots", "Never Mind the Bollocks...")] [TestCase(10, null, null, null, null, null)] diff --git a/examples/NpgsqlDapperExample/Models.cs b/examples/NpgsqlDapperExample/Models.cs index b99e2fa3..1be88179 100644 --- a/examples/NpgsqlDapperExample/Models.cs +++ b/examples/NpgsqlDapperExample/Models.cs @@ -89,6 +89,10 @@ public class PostgresSpecialType public XmlDocument? CXml { get; init; } public XmlDocument? CXmlStringOverride { get; init; } }; +public class PostgresNotNullType +{ + public required CEnum CEnumNotNull { get; init; } +}; public class ExtendedBio { public required string AuthorName { get; init; } diff --git a/examples/NpgsqlDapperExample/QuerySql.cs b/examples/NpgsqlDapperExample/QuerySql.cs index 3d5ad031..c3577ca0 100644 --- a/examples/NpgsqlDapperExample/QuerySql.cs +++ b/examples/NpgsqlDapperExample/QuerySql.cs @@ -1183,6 +1183,63 @@ public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args await this.Transaction.Connection.ExecuteAsync(InsertPostgresSpecialTypesSql, queryParams, transaction: this.Transaction); } + private const string InsertPostgresNotNullTypesSql = "INSERT INTO postgres_not_null_types ( c_enum_not_null ) VALUES ( @c_enum_not_null::c_enum )"; + public class InsertPostgresNotNullTypesArgs + { + public required CEnum CEnumNotNull { get; init; } + }; + public async Task InsertPostgresNotNullTypes(InsertPostgresNotNullTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_enum_not_null", args.CEnumNotNull.Stringify()); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresNotNullTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresNotNullTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresNotNullTypesSql = "SELECT c_enum_not_null FROM postgres_not_null_types LIMIT 1"; + public class GetPostgresNotNullTypesRow + { + public required CEnum CEnumNotNull { get; init; } + }; + public async Task GetPostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNotNullTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNotNullTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresNotNullTypesSql = "TRUNCATE TABLE postgres_not_null_types"; + public async Task TruncatePostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresNotNullTypesSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresNotNullTypesSql, transaction: this.Transaction); + } + private const string GetPostgresSpecialTypesSql = "SELECT c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_xml_string_override, c_uuid, c_enum FROM postgres_special_types LIMIT 1"; public class GetPostgresSpecialTypesRow { diff --git a/examples/NpgsqlDapperExample/request.json b/examples/NpgsqlDapperExample/request.json index 8ace9fd4..6d9405cf 100644 --- a/examples/NpgsqlDapperExample/request.json +++ b/examples/NpgsqlDapperExample/request.json @@ -657,6 +657,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_not_null_types" + }, + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -35146,6 +35164,54 @@ "name": "postgres_special_types" } }, + { + "text": "INSERT INTO postgres_not_null_types\n(\n c_enum_not_null\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresNotNullTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_not_null_types" + } + }, + { + "text": "SELECT\n c_enum_not_null\nFROM postgres_not_null_types \nLIMIT 1", + "name": "GetPostgresNotNullTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + }, + "originalName": "c_enum_not_null" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_not_null_types", + "name": "TruncatePostgresNotNullTypes", + "cmd": ":exec", + "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", "name": "GetPostgresSpecialTypes", diff --git a/examples/NpgsqlDapperExample/request.message b/examples/NpgsqlDapperExample/request.message index cd48e311..f88a261e 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"}}],"targetFramework":"net8.0","useDapper":true}* -./dist/LocalRunnerль public"publicƒ +./dist/LocalRunnerНэ public"џpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -94,7 +94,9 @@ pg_catalogjson7 c_jsonpath0џџџџџџџџџRpostgres_special_typesb jsonpath3 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC -c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml" +c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` +postgres_not_null_typesC +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10705,7 +10707,21 @@ 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_enum2 Special types : query.sqlBpostgres_special_typesЮ +UINSERT INTO postgres_not_null_types +( + c_enum_not_null +) +VALUES ( + $1::c_enum +)InsertPostgresNotNullTypes:exec*,( +c_enum_not_null0џџџџџџџџџbc_enum: query.sqlBpostgres_not_null_typesТ +@SELECT + c_enum_not_null +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 c_json, c_json_string_override, diff --git a/examples/NpgsqlDapperLegacyExample/Models.cs b/examples/NpgsqlDapperLegacyExample/Models.cs index eddac678..aa6d7b9f 100644 --- a/examples/NpgsqlDapperLegacyExample/Models.cs +++ b/examples/NpgsqlDapperLegacyExample/Models.cs @@ -90,6 +90,10 @@ public class PostgresSpecialType public XmlDocument CXml { get; set; } public XmlDocument CXmlStringOverride { get; set; } }; + public class PostgresNotNullType + { + public CEnum CEnumNotNull { get; set; } + }; public class ExtendedBio { public string AuthorName { get; set; } diff --git a/examples/NpgsqlDapperLegacyExample/QuerySql.cs b/examples/NpgsqlDapperLegacyExample/QuerySql.cs index 710e5997..4f076194 100644 --- a/examples/NpgsqlDapperLegacyExample/QuerySql.cs +++ b/examples/NpgsqlDapperLegacyExample/QuerySql.cs @@ -1184,6 +1184,63 @@ public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args await this.Transaction.Connection.ExecuteAsync(InsertPostgresSpecialTypesSql, queryParams, transaction: this.Transaction); } + private const string InsertPostgresNotNullTypesSql = "INSERT INTO postgres_not_null_types ( c_enum_not_null ) VALUES ( @c_enum_not_null::c_enum )"; + public class InsertPostgresNotNullTypesArgs + { + public CEnum CEnumNotNull { get; set; } + }; + public async Task InsertPostgresNotNullTypes(InsertPostgresNotNullTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_enum_not_null", args.CEnumNotNull.Stringify()); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresNotNullTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresNotNullTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresNotNullTypesSql = "SELECT c_enum_not_null FROM postgres_not_null_types LIMIT 1"; + public class GetPostgresNotNullTypesRow + { + public CEnum CEnumNotNull { get; set; } + }; + public async Task GetPostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNotNullTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNotNullTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresNotNullTypesSql = "TRUNCATE TABLE postgres_not_null_types"; + public async Task TruncatePostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresNotNullTypesSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresNotNullTypesSql, transaction: this.Transaction); + } + private const string GetPostgresSpecialTypesSql = "SELECT c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_xml_string_override, c_uuid, c_enum FROM postgres_special_types LIMIT 1"; public class GetPostgresSpecialTypesRow { diff --git a/examples/NpgsqlDapperLegacyExample/request.json b/examples/NpgsqlDapperLegacyExample/request.json index ee160451..a0ee73f5 100644 --- a/examples/NpgsqlDapperLegacyExample/request.json +++ b/examples/NpgsqlDapperLegacyExample/request.json @@ -657,6 +657,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_not_null_types" + }, + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -35146,6 +35164,54 @@ "name": "postgres_special_types" } }, + { + "text": "INSERT INTO postgres_not_null_types\n(\n c_enum_not_null\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresNotNullTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_not_null_types" + } + }, + { + "text": "SELECT\n c_enum_not_null\nFROM postgres_not_null_types \nLIMIT 1", + "name": "GetPostgresNotNullTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + }, + "originalName": "c_enum_not_null" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_not_null_types", + "name": "TruncatePostgresNotNullTypes", + "cmd": ":exec", + "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", "name": "GetPostgresSpecialTypes", diff --git a/examples/NpgsqlDapperLegacyExample/request.message b/examples/NpgsqlDapperLegacyExample/request.message index dc27d44d..39b9ff61 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"}}],"targetFramework":"netstandard2.0","useDapper":true}* -./dist/LocalRunnerль public"publicƒ +./dist/LocalRunnerНэ public"џpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -94,7 +94,9 @@ pg_catalogjson7 c_jsonpath0џџџџџџџџџRpostgres_special_typesb jsonpath3 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC -c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml" +c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` +postgres_not_null_typesC +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10705,7 +10707,21 @@ 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_enum2 Special types : query.sqlBpostgres_special_typesЮ +UINSERT INTO postgres_not_null_types +( + c_enum_not_null +) +VALUES ( + $1::c_enum +)InsertPostgresNotNullTypes:exec*,( +c_enum_not_null0џџџџџџџџџbc_enum: query.sqlBpostgres_not_null_typesТ +@SELECT + c_enum_not_null +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 c_json, c_json_string_override, diff --git a/examples/NpgsqlExample/Models.cs b/examples/NpgsqlExample/Models.cs index 17dfe72a..ed9abc3d 100644 --- a/examples/NpgsqlExample/Models.cs +++ b/examples/NpgsqlExample/Models.cs @@ -18,6 +18,7 @@ namespace NpgsqlExampleGen; 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 PostgresNotNullType(CEnum CEnumNotNull); 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 9db523e5..fb06f2aa 100644 --- a/examples/NpgsqlExample/QuerySql.cs +++ b/examples/NpgsqlExample/QuerySql.cs @@ -1722,6 +1722,108 @@ public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args } } + private const string InsertPostgresNotNullTypesSql = "INSERT INTO postgres_not_null_types ( c_enum_not_null ) VALUES ( @c_enum_not_null::c_enum )"; + public readonly record struct InsertPostgresNotNullTypesArgs(CEnum CEnumNotNull); + public async Task InsertPostgresNotNullTypes(InsertPostgresNotNullTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(InsertPostgresNotNullTypesSql)) + { + command.Parameters.AddWithValue("@c_enum_not_null", args.CEnumNotNull.Stringify()); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresNotNullTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_enum_not_null", args.CEnumNotNull.Stringify()); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresNotNullTypesSql = "SELECT c_enum_not_null FROM postgres_not_null_types LIMIT 1"; + public readonly record struct GetPostgresNotNullTypesRow(CEnum CEnumNotNull); + public async Task GetPostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresNotNullTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNotNullTypesRow + { + CEnumNotNull = reader.GetString(0).ToCEnum() + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNotNullTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNotNullTypesRow + { + CEnumNotNull = reader.GetString(0).ToCEnum() + }; + } + } + } + + return null; + } + + private const string TruncatePostgresNotNullTypesSql = "TRUNCATE TABLE postgres_not_null_types"; + public async Task TruncatePostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(TruncatePostgresNotNullTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresNotNullTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + private const string GetPostgresSpecialTypesSql = "SELECT c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_xml_string_override, c_uuid, c_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 async Task GetPostgresSpecialTypes() diff --git a/examples/NpgsqlExample/request.json b/examples/NpgsqlExample/request.json index ab616394..2c2d156b 100644 --- a/examples/NpgsqlExample/request.json +++ b/examples/NpgsqlExample/request.json @@ -657,6 +657,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_not_null_types" + }, + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -35146,6 +35164,54 @@ "name": "postgres_special_types" } }, + { + "text": "INSERT INTO postgres_not_null_types\n(\n c_enum_not_null\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresNotNullTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_not_null_types" + } + }, + { + "text": "SELECT\n c_enum_not_null\nFROM postgres_not_null_types \nLIMIT 1", + "name": "GetPostgresNotNullTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + }, + "originalName": "c_enum_not_null" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_not_null_types", + "name": "TruncatePostgresNotNullTypes", + "cmd": ":exec", + "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", "name": "GetPostgresSpecialTypes", diff --git a/examples/NpgsqlExample/request.message b/examples/NpgsqlExample/request.message index b4c6e3a8..029e158b 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"}}],"targetFramework":"net8.0","useDapper":false}* -./dist/LocalRunnerль public"publicƒ +./dist/LocalRunnerНэ public"џpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -94,7 +94,9 @@ pg_catalogjson7 c_jsonpath0џџџџџџџџџRpostgres_special_typesb jsonpath3 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC -c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml" +c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` +postgres_not_null_typesC +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10705,7 +10707,21 @@ 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_enum2 Special types : query.sqlBpostgres_special_typesЮ +UINSERT INTO postgres_not_null_types +( + c_enum_not_null +) +VALUES ( + $1::c_enum +)InsertPostgresNotNullTypes:exec*,( +c_enum_not_null0џџџџџџџџџbc_enum: query.sqlBpostgres_not_null_typesТ +@SELECT + c_enum_not_null +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 c_json, c_json_string_override, diff --git a/examples/NpgsqlLegacyExample/Models.cs b/examples/NpgsqlLegacyExample/Models.cs index 2a06f586..8cac7f32 100644 --- a/examples/NpgsqlLegacyExample/Models.cs +++ b/examples/NpgsqlLegacyExample/Models.cs @@ -90,6 +90,10 @@ public class PostgresSpecialType public XmlDocument CXml { get; set; } public XmlDocument CXmlStringOverride { get; set; } }; + public class PostgresNotNullType + { + public CEnum CEnumNotNull { get; set; } + }; public class ExtendedBio { public string AuthorName { get; set; } diff --git a/examples/NpgsqlLegacyExample/QuerySql.cs b/examples/NpgsqlLegacyExample/QuerySql.cs index aab3edac..aaa0c4af 100644 --- a/examples/NpgsqlLegacyExample/QuerySql.cs +++ b/examples/NpgsqlLegacyExample/QuerySql.cs @@ -1987,6 +1987,114 @@ public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args } } + private const string InsertPostgresNotNullTypesSql = "INSERT INTO postgres_not_null_types ( c_enum_not_null ) VALUES ( @c_enum_not_null::c_enum )"; + public class InsertPostgresNotNullTypesArgs + { + public CEnum CEnumNotNull { get; set; } + }; + public async Task InsertPostgresNotNullTypes(InsertPostgresNotNullTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(InsertPostgresNotNullTypesSql)) + { + command.Parameters.AddWithValue("@c_enum_not_null", args.CEnumNotNull.Stringify()); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresNotNullTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_enum_not_null", args.CEnumNotNull.Stringify()); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresNotNullTypesSql = "SELECT c_enum_not_null FROM postgres_not_null_types LIMIT 1"; + public class GetPostgresNotNullTypesRow + { + public CEnum CEnumNotNull { get; set; } + }; + public async Task GetPostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresNotNullTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNotNullTypesRow + { + CEnumNotNull = reader.GetString(0).ToCEnum() + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNotNullTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNotNullTypesRow + { + CEnumNotNull = reader.GetString(0).ToCEnum() + }; + } + } + } + + return null; + } + + private const string TruncatePostgresNotNullTypesSql = "TRUNCATE TABLE postgres_not_null_types"; + public async Task TruncatePostgresNotNullTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(TruncatePostgresNotNullTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresNotNullTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + private const string GetPostgresSpecialTypesSql = "SELECT c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_xml_string_override, c_uuid, c_enum FROM postgres_special_types LIMIT 1"; public class GetPostgresSpecialTypesRow { diff --git a/examples/NpgsqlLegacyExample/request.json b/examples/NpgsqlLegacyExample/request.json index 8a47b829..81511b76 100644 --- a/examples/NpgsqlLegacyExample/request.json +++ b/examples/NpgsqlLegacyExample/request.json @@ -657,6 +657,24 @@ } } ] + }, + { + "rel": { + "name": "postgres_not_null_types" + }, + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + } + } + ] } ], "enums": [ @@ -35146,6 +35164,54 @@ "name": "postgres_special_types" } }, + { + "text": "INSERT INTO postgres_not_null_types\n(\n c_enum_not_null\n)\nVALUES (\n $1::c_enum\n)", + "name": "InsertPostgresNotNullTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_not_null_types" + } + }, + { + "text": "SELECT\n c_enum_not_null\nFROM postgres_not_null_types \nLIMIT 1", + "name": "GetPostgresNotNullTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_enum_not_null", + "notNull": true, + "length": -1, + "table": { + "name": "postgres_not_null_types" + }, + "type": { + "name": "c_enum" + }, + "originalName": "c_enum_not_null" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_not_null_types", + "name": "TruncatePostgresNotNullTypes", + "cmd": ":exec", + "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", "name": "GetPostgresSpecialTypes", diff --git a/examples/NpgsqlLegacyExample/request.message b/examples/NpgsqlLegacyExample/request.message index 5aeaa545..879ab23b 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"}}],"targetFramework":"netstandard2.0","useDapper":false}* -./dist/LocalRunnerль public"publicƒ +./dist/LocalRunnerНэ public"џpublicƒ authors) id0џџџџџџџџџR authorsb  bigserial& name0џџџџџџџџџR authorsbtext# @@ -94,7 +94,9 @@ pg_catalogjson7 c_jsonpath0џџџџџџџџџRpostgres_special_typesb jsonpath3 c_xml0џџџџџџџџџRpostgres_special_typesbxmlC -c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml" +c_xml_string_override0џџџџџџџџџRpostgres_special_typesbxml` +postgres_not_null_typesC +c_enum_not_null0џџџџџџџџџRpostgres_not_null_typesbc_enum" c_enumsmallmediumbig" pg_temp"цВ pg_catalog‰ & @@ -10705,7 +10707,21 @@ 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_enum2 Special types : query.sqlBpostgres_special_typesЮ +UINSERT INTO postgres_not_null_types +( + c_enum_not_null +) +VALUES ( + $1::c_enum +)InsertPostgresNotNullTypes:exec*,( +c_enum_not_null0џџџџџџџџџbc_enum: query.sqlBpostgres_not_null_typesТ +@SELECT + c_enum_not_null +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 c_json, c_json_string_override, diff --git a/examples/config/postgresql/types/query.sql b/examples/config/postgresql/types/query.sql index d43a9e2f..5f890076 100644 --- a/examples/config/postgresql/types/query.sql +++ b/examples/config/postgresql/types/query.sql @@ -253,6 +253,24 @@ VALUES ( sqlc.narg('c_enum')::c_enum ); +-- name: InsertPostgresNotNullTypes :exec +INSERT INTO postgres_not_null_types +( + c_enum_not_null +) +VALUES ( + sqlc.arg('c_enum_not_null')::c_enum +); + +-- name: GetPostgresNotNullTypes :one +SELECT + c_enum_not_null +FROM postgres_not_null_types +LIMIT 1; + +-- name: TruncatePostgresNotNullTypes :exec +TRUNCATE TABLE postgres_not_null_types; + -- name: GetPostgresSpecialTypes :one SELECT c_json, diff --git a/examples/config/postgresql/types/schema.sql b/examples/config/postgresql/types/schema.sql index e269c9a1..b35715c0 100644 --- a/examples/config/postgresql/types/schema.sql +++ b/examples/config/postgresql/types/schema.sql @@ -72,4 +72,8 @@ CREATE TABLE postgres_special_types ( c_jsonpath JSONPATH, c_xml XML, c_xml_string_override XML +); + +CREATE TABLE postgres_not_null_types ( + c_enum_not_null c_enum NOT NULL DEFAULT 'small' ); \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 00000000..1978c843 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "8.0.303" + } +} \ No newline at end of file