Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defaults:
env:
SQLC_VERSION: 1.30.0
WASI_SDK_VERSION: 22
DOTNET_VERSION: '8.0.x'

on:
push:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions end2end/EndToEndScaffold/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public enum KnownTestType
PostgresJsonDataTypes,
PostgresXmlDataTypes,
PostgresEnumDataType,
PostgresNotNullTypes,

// :copyfrom (Batch)
PostgresStringCopyFrom,
Expand Down Expand Up @@ -171,6 +172,7 @@ internal static class Config
KnownTestType.PostgresNetworkDataTypes,
KnownTestType.PostgresXmlDataTypes,
KnownTestType.PostgresEnumDataType,
KnownTestType.PostgresNotNullTypes,
KnownTestType.PostgresFullTextSearchDataTypes,

// :copyfrom (Batch)
Expand Down
30 changes: 29 additions & 1 deletion end2end/EndToEndScaffold/Templates/PostgresTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 = $$"""
Expand Down
21 changes: 20 additions & 1 deletion end2end/EndToEndTests/NpgsqlDapperTester.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions end2end/EndToEndTests/NpgsqlTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public async Task EmptyTestsTables()
await QuerySql.TruncatePostgresNetworkTypes();
await QuerySql.TruncatePostgresArrayTypes();
await QuerySql.TruncatePostgresSpecialTypes();
await QuerySql.TruncatePostgresNotNullTypes();
}
}
21 changes: 20 additions & 1 deletion end2end/EndToEndTests/NpgsqlTester.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]
Expand Down
21 changes: 20 additions & 1 deletion end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]
Expand Down
21 changes: 20 additions & 1 deletion end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]
Expand Down
4 changes: 4 additions & 0 deletions examples/NpgsqlDapperExample/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
57 changes: 57 additions & 0 deletions examples/NpgsqlDapperExample/QuerySql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object?>();
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<GetPostgresNotNullTypesRow?> GetPostgresNotNullTypes()
{
if (this.Transaction == null)
{
using (var connection = new NpgsqlConnection(ConnectionString))
{
var result = await connection.QueryFirstOrDefaultAsync<GetPostgresNotNullTypesRow?>(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<GetPostgresNotNullTypesRow?>(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
{
Expand Down
Loading
Loading