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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: dotnet tool install dotnet-ilverify --global --version 8.0.0

- name: Run build script
run: dotnet-script build/build.csx
run: dotnet-script build/build.csx --disable-isolated-load-context
env: # Or as an environment variable
GITHUB_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IS_SECURE_BUILDENVIRONMENT: ${{ secrets.IS_SECURE_BUILDENVIRONMENT }}
Expand Down
2 changes: 1 addition & 1 deletion build/build.csx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#load "nuget:Dotnet.Build, 0.24.0"
#load "nuget:Dotnet.Build, 0.26.0"
#load "nuget:dotnet-steps, 0.0.2"

Console.WriteLine($"Building with the latest tag {BuildContext.LatestTag}");
Expand Down
9 changes: 3 additions & 6 deletions src/DbReader.Tests/DbReader.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="moq" Version="4.20.72" />
<PackageReference Include="shouldly" Version="4.3.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.4" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.1" />
<PackageReference Include="ILVerifier" Version="0.0.1" />
</ItemGroup>
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**/*.sql" />
Expand All @@ -34,6 +33,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>


</Project>
12 changes: 12 additions & 0 deletions src/DbReader.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,18 @@ public async Task ShouldNotCacheCollection()
}
}

[Fact]
public async Task ShouldReadFirstOrDefaultAsync()
{
using (var connection = CreateConnection())
{
var customer = await connection.ReadFirstOrDefaultAsync<Customer>("SELECT * FROM Customers WHERE CustomerID = @CustomerID", new { CustomerID = "ALFKI" });
customer.ShouldNotBeNull();
customer.CustomerId.ShouldBe("ALFKI");
}
}


public class CustomerId
{
private string Value { get; set; }
Expand Down
16 changes: 6 additions & 10 deletions src/DbReader.Tracking/DbReader.Tracking.csproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.13.9" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="18.0.2" />
</ItemGroup>

<!-- Using Cecil directly via project reference generates package dependencies to non-existing cecil packages (https://github.com/NuGet/Home/issues/3891) => use ReferenceOutputAssembly="false" and reference the binaries directly -->
<ItemGroup>
<ProjectReference Include="../../cecil/Mono.Cecil.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="../../cecil/rocks/Mono.Cecil.Rocks.csproj" ReferenceOutputAssembly="false"/>
<ProjectReference Include="../../cecil/symbols/pdb/Mono.Cecil.Pdb.csproj" ReferenceOutputAssembly="false"/>
<ProjectReference Include="../../cecil/rocks/Mono.Cecil.Rocks.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="../../cecil/symbols/pdb/Mono.Cecil.Pdb.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<Reference Include="Mono.Cecil" HintPath="../../cecil/bin/$(Configuration)\netstandard2.0\Mono.Cecil.dll" />
<Reference Include="Mono.Cecil.Pdb" HintPath="../../cecil/symbols/pdb/bin/$(Configuration)\netstandard2.0\Mono.Cecil.Pdb.dll" />
<Reference Include="Mono.Cecil.Rocks" HintPath="../../cecil/rocks/bin/$(Configuration)\netstandard2.0\Mono.Cecil.Rocks.dll" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\DbReader\DbReader.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="build\*" PackagePath="build" />
</ItemGroup>
</Project>
</Project>
67 changes: 33 additions & 34 deletions src/DbReader.Tracking/DbReader.Tracking.nuspec
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<!-- Required: Package ID -->
<id>DbReader.Tracking</id>
<!-- Required: Package version -->
<version>0.0.1</version>
<!-- Required: Authors -->
<authors>Bernhard Richter</authors>
<!-- Required: Description -->
<description>A custom MSBuild task package.</description>
<!-- Optional: Project URL -->
<projectUrl>https://github.com/seesharper/DbReader</projectUrl>
<!-- Optional: License URL -->
<license type="expression">MIT</license>
<!-- Optional: Tags -->
<tags>DbReader Tracking</tags>

<developmentDependency>true</developmentDependency>
</metadata>
<dependencies>
<dependency id="DbReader" version="3.0.0" />
</dependencies>
<files>
<!-- Include the custom task assembly (DLL) -->
<file src="../DbReader/bin/Release/net8.0/DbReader.dll" target="lib/net8.0" />
<file src="bin/Release/net8.0/DbReader.Tracking.dll" target="lib/net8.0" />
<file src="../../cecil/bin/Release/netstandard2.0/Mono.Cecil.dll" target="lib/net8.0" />
<file src="../../cecil/symbols/pdb/bin/Release/netstandard2.0/Mono.Cecil.Pdb.dll" target="lib/net8.0" />
<file src="../../cecil/rocks/bin/Release/netstandard2.0/Mono.Cecil.Rocks.dll" target="lib/net8.0" />
<!-- Include the .targets file in the build folder -->
<!-- Optional: Include the .props file if you have one -->
<file src="DbReader.Tracking.targets" target="build" />
</files>
</package>
<metadata>
<!-- Required: Package ID -->
<id>DbReader.Tracking</id>
<!-- Required: Package version -->
<version>0.0.1</version>
<!-- Required: Authors -->
<authors>Bernhard Richter</authors>
<!-- Required: Description -->
<description>A custom MSBuild task package.</description>
<!-- Optional: Project URL -->
<projectUrl>https://github.com/seesharper/DbReader</projectUrl>
<!-- Optional: License URL -->
<license type="expression">MIT</license>
<!-- Optional: Tags -->
<tags>DbReader Tracking</tags>
<developmentDependency>true</developmentDependency>
</metadata>
<dependencies>
<dependency id="DbReader" version="4.0.1" />
</dependencies>
<files>
<!-- Include the custom task assembly (DLL) -->
<file src="../DbReader/bin/Release/net8.0/DbReader.dll" target="lib/net8.0" />
<file src="bin/Release/net8.0/DbReader.Tracking.dll" target="lib/net8.0" />
<file src="../../cecil/bin/Release/netstandard2.0/Mono.Cecil.dll" target="lib/net8.0" />
<file src="../../cecil/symbols/pdb/bin/Release/netstandard2.0/Mono.Cecil.Pdb.dll" target="lib/net8.0" />
<file src="../../cecil/rocks/bin/Release/netstandard2.0/Mono.Cecil.Rocks.dll" target="lib/net8.0" />
<!-- Include the .targets file in the build folder -->
<!-- Optional: Include the .props file if you have one -->
<file src="DbReader.Tracking.targets" target="build" />
</files>
</package>
52 changes: 42 additions & 10 deletions src/DbReader/DbConnectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@
/// <param name="configureCommand">A function used to configure the underlying <see cref="IDbCommand"/>.</param>
/// <returns><see cref="IDataReader"/></returns>
public static async Task<IDataReader> ExecuteReaderAsync(this IDbConnection dbConnection, string query, object arguments = null, Action<IDbCommand> configureCommand = default)
{
return await dbConnection.ExecuteReaderAsync(CancellationToken.None, query, arguments, configureCommand).ConfigureAwait(false);
}
=> await dbConnection.ExecuteReaderAsync(CancellationToken.None, query, arguments, configureCommand).ConfigureAwait(false);

/// <summary>
/// Executes the given <paramref name="query"/> asynchronously and returns an <see cref="IDataReader"/>.
Expand Down Expand Up @@ -162,8 +160,6 @@
return command;
}



/// <summary>
/// Executes the given <paramref name="query"/> and returns the number of rows affected.
/// </summary>
Expand All @@ -189,10 +185,7 @@
/// <param name="configureCommand">A function used to configure the underlying <see cref="IDbCommand"/>.</param>
/// <returns>The number of rows affected.</returns>
public static async Task<int> ExecuteAsync(this IDbConnection dbConnection, string query, object arguments = null, Action<IDbCommand> configureCommand = default)
{
return await dbConnection.ExecuteAsync(CancellationToken.None, query, arguments, configureCommand).ConfigureAwait(false);
}

=> await dbConnection.ExecuteAsync(CancellationToken.None, query, arguments, configureCommand).ConfigureAwait(false);

/// <summary>
/// Executes the given <paramref name="query"/> asynchronously and returns the number of rows affected.
Expand Down Expand Up @@ -221,16 +214,30 @@
/// <typeparam name="T"></typeparam>
/// <returns>The type of value to be returned.</returns>
public static async Task<T> ExecuteScalarAsync<T>(this IDbConnection dbConnection, string query, object arguments = null, Action<IDbCommand> configureCommand = default)
=> await dbConnection.ExecuteScalarAsync<T>(CancellationToken.None, query, arguments, configureCommand);

/// <summary>
/// Executes the query asynchronously , and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
/// </summary>
/// <param name="dbConnection">The <see cref="IDbConnection"/> to be used when executing the query.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="query">The query to be executed.</param>
/// <param name="arguments">The argument object that represents the arguments passed to the query.</param>
/// <param name="configureCommand">A function used to configure the underlying <see cref="IDbCommand"/>.</param>
/// <typeparam name="T"></typeparam>
/// <returns>The type of value to be returned.</returns>
public static async Task<T> ExecuteScalarAsync<T>(this IDbConnection dbConnection, CancellationToken cancellationToken, string query, object arguments = null, Action<IDbCommand> configureCommand = default)
{
using (var command = (DbCommand)CreateCommand(dbConnection, query, arguments, configureCommand))
{
using (var reader = await command.ExecuteReaderAsync())
using (var reader = await command.ExecuteReaderAsync(cancellationToken))
{
return ReadScalarValue<T>(reader);
}
}
}


/// <summary>
/// Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
/// </summary>
Expand All @@ -251,6 +258,31 @@
}
}

/// <summary>
/// Executes the given <paramref name="query"/> and returns an instance of {T} for the first row or null if no rows."/> that
/// </summary>
/// <typeparam name="T">The type to be projected from the query.</typeparam>
/// <param name="dbConnection">The target <see cref="IDbConnection"/>.</param>
/// <param name="query">The query to be executed.</param>
/// <param name="arguments">An object that represents the query arguments.</param>
/// <param name="configureCommand">A function used to configure the underlying <see cref="IDbCommand"/>.</param>
/// <returns>The first instance of {T}/> that represents the result of the query or null if not found.</returns>
public static async Task<T> ReadFirstOrDefaultAsync<T>(this IDbConnection dbConnection, string query, object? arguments = null, Action<IDbCommand>? configureCommand = null)

Check warning on line 270 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 270 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 270 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 270 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
=> await dbConnection.ReadFirstOrDefaultAsync<T>(CancellationToken.None, query, arguments, configureCommand);

/// <summary>
/// Executes the given <paramref name="query"/> and returns an {T} for the first row or null if no rows"/>
/// </summary>
/// <typeparam name="T">The type to be projected from the query.</typeparam>
/// <param name="dbConnection">The target <see cref="IDbConnection"/>.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="query">The query to be executed.</param>
/// <param name="arguments">An object that represents the query arguments.</param>
/// <param name="configureCommand">A function used to configure the underlying <see cref="IDbCommand"/>.</param>
/// <returns>The first instance of {T}/> that represents the result of the query or null if not found.</returns>
public static async Task<T> ReadFirstOrDefaultAsync<T>(this IDbConnection dbConnection, CancellationToken cancellationToken, string query, object? arguments = null, Action<IDbCommand>? configureCommand = null)

Check warning on line 283 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 283 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 283 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 283 in src/DbReader/DbConnectionExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
=> (await dbConnection.ReadAsync<T>(cancellationToken, query, arguments, configureCommand)).FirstOrDefault();

private static T ReadScalarValue<T>(IDataReader reader)
{
if (!reader.Read() || reader.IsDBNull(0))
Expand Down
2 changes: 0 additions & 2 deletions src/DbReader/DbReader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<LangVersion>latest</LangVersion>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="LightInject.Source" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/DbReader/Nuget/DbReader.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<owners>Bernhard Richter</owners>
<licenseUrl>http://opensource.org/licenses/MIT</licenseUrl>
<projectUrl>https://github.com/seesharper/DbReader</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A simple and fast database reader for the .Net framework.</description>
<copyright>Bernhard Richter</copyright>
<tags>data-access orm sql micro-orm</tags>
Expand Down
Loading