Skip to content

Commit

Permalink
Fix nullability suggestions and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
schotime committed Dec 27, 2023
1 parent 89b87bf commit 7c8d0a9
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 79 deletions.
21 changes: 11 additions & 10 deletions src/NPoco.Abstractions/IAsyncDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Data;
Expand Down Expand Up @@ -46,12 +47,12 @@ public interface IAsyncDatabase : IAsyncQueryDatabase
/// <summary>
/// Insert POCO's into database using SqlBulkCopy for SqlServer (other DB's currently fall back to looping each row)
/// </summary>
Task InsertBulkAsync<T>(IEnumerable<T> pocos, InsertBulkOptions options = null, CancellationToken cancellationToken = default);
Task InsertBulkAsync<T>(IEnumerable<T> pocos, InsertBulkOptions? options = null, CancellationToken cancellationToken = default);

/// <summary>
/// Insert POCO's into database by concatenating sql using the provided batch options
/// </summary>
Task<int> InsertBatchAsync<T>(IEnumerable<T> pocos, BatchOptions options = null, CancellationToken cancellationToken = default);
Task<int> InsertBatchAsync<T>(IEnumerable<T> pocos, BatchOptions? options = null, CancellationToken cancellationToken = default);

/// <summary>
/// Update POCO in the table by convention or configuration
Expand All @@ -71,7 +72,7 @@ public interface IAsyncDatabase : IAsyncQueryDatabase
/// <summary>
/// Update POCO's into database by concatenating sql using the provided batch options
/// </summary>
Task<int> UpdateBatchAsync<T>(IEnumerable<UpdateBatch<T>> pocos, BatchOptions options = null, CancellationToken cancellationToken = default);
Task<int> UpdateBatchAsync<T>(IEnumerable<UpdateBatch<T>> pocos, BatchOptions? options = null, CancellationToken cancellationToken = default);

/// <summary>
/// Delete POCO from table by convention or configuration
Expand Down Expand Up @@ -116,13 +117,13 @@ public interface IAsyncQueryDatabase : IAsyncBaseDatabase
/// <summary>
/// Fetch the only row of type T using the sql and parameters specified
/// </summary>
Task<T> SingleOrDefaultAsync<T>(string sql, CancellationToken cancellationToken = default);
Task<T> SingleOrDefaultAsync<T>(string sql, object[] args, CancellationToken cancellationToken = default);
Task<T?> SingleOrDefaultAsync<T>(string sql, CancellationToken cancellationToken = default);
Task<T?> SingleOrDefaultAsync<T>(string sql, object[] args, CancellationToken cancellationToken = default);

/// <summary>
/// Fetch the only row of type T using the sql and parameters specified
/// </summary>
Task<T> SingleOrDefaultAsync<T>(Sql sql, CancellationToken cancellationToken = default);
Task<T?> SingleOrDefaultAsync<T>(Sql sql, CancellationToken cancellationToken = default);

/// <summary>
/// Get an object of type T by primary key value
Expand All @@ -132,7 +133,7 @@ public interface IAsyncQueryDatabase : IAsyncBaseDatabase
/// <summary>
/// Get an object of type T by primary key value
/// </summary>
Task<T> SingleOrDefaultByIdAsync<T>(object primaryKey, CancellationToken cancellationToken = default);
Task<T?> SingleOrDefaultByIdAsync<T>(object primaryKey, CancellationToken cancellationToken = default);

/// <summary>
/// Fetch the first row of type T using the sql and parameters specified
Expand All @@ -148,13 +149,13 @@ public interface IAsyncQueryDatabase : IAsyncBaseDatabase
/// <summary>
/// Fetch the first row of type T using the sql and parameters specified
/// </summary>
Task<T> FirstOrDefaultAsync<T>(string sql, CancellationToken cancellationToken = default);
Task<T> FirstOrDefaultAsync<T>(string sql, object[] args, CancellationToken cancellationToken = default);
Task<T?> FirstOrDefaultAsync<T>(string sql, CancellationToken cancellationToken = default);
Task<T?> FirstOrDefaultAsync<T>(string sql, object[] args, CancellationToken cancellationToken = default);

/// <summary>
/// Fetch the first row of type T using the sql and parameters specified
/// </summary>
Task<T> FirstOrDefaultAsync<T>(Sql sql, CancellationToken cancellationToken = default);
Task<T?> FirstOrDefaultAsync<T>(Sql sql, CancellationToken cancellationToken = default);

/// <summary>
/// Fetch objects of type T from the database using the sql and parameters specified.
Expand Down
23 changes: 12 additions & 11 deletions src/NPoco.Abstractions/IDatabaseQuery.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -186,17 +187,17 @@ public interface IDatabaseQuery : IAsyncQueryDatabase
/// <summary>
/// Get an object of type T by primary key value where the row may not be there
/// </summary>
T SingleOrDefaultById<T>(object primaryKey);
T? SingleOrDefaultById<T>(object primaryKey);

/// <summary>
/// Fetch the only row of type T using the sql and parameters specified
/// </summary>
T SingleOrDefault<T>(string sql, params object[] args);
T? SingleOrDefault<T>(string sql, params object[] args);

/// <summary>
/// Fetch the only row of type T using the sql and parameters specified into the T instance provided
/// </summary>
T SingleOrDefaultInto<T>(T instance, string sql, params object[] args);
T? SingleOrDefaultInto<T>(T instance, string sql, params object[] args);

/// <summary>
/// Fetch the first row of type T using the sql and parameters specified
Expand All @@ -211,12 +212,12 @@ public interface IDatabaseQuery : IAsyncQueryDatabase
/// <summary>
/// Fetch the first row of type T using the sql and parameters specified
/// </summary>
T FirstOrDefault<T>(string sql, params object[] args);
T? FirstOrDefault<T>(string sql, params object[] args);

/// <summary>
/// Fetch the first row of type T using the sql and parameters specified into the T instance provided
/// </summary>
T FirstOrDefaultInto<T>(T instance, string sql, params object[] args);
T? FirstOrDefaultInto<T>(T instance, string sql, params object[] args);

/// <summary>
/// Fetch the only row of type T using the Sql specified
Expand All @@ -231,12 +232,12 @@ public interface IDatabaseQuery : IAsyncQueryDatabase
/// <summary>
/// Fetch the only row of type T using the Sql specified
/// </summary>
T SingleOrDefault<T>(Sql sql);
T? SingleOrDefault<T>(Sql sql);

/// <summary>
/// Fetch the only row of type T using the Sql specified
/// </summary>
T SingleOrDefaultInto<T>(T instance, Sql sql);
T? SingleOrDefaultInto<T>(T instance, Sql sql);

/// <summary>
/// Fetch the first row of type T using the Sql specified
Expand All @@ -251,22 +252,22 @@ public interface IDatabaseQuery : IAsyncQueryDatabase
/// <summary>
/// Fetch the first row of type T using the Sql specified
/// </summary>
T FirstOrDefault<T>(Sql sql);
T? FirstOrDefault<T>(Sql sql);

/// <summary>
/// Fetch the first row of type T using the Sql specified
/// </summary>
T FirstOrDefaultInto<T>(T instance, Sql sql);
T? FirstOrDefaultInto<T>(T instance, Sql sql);

/// <summary>
/// Fetches the first two columns into a dictionary using the first value as the key and the second as the value
/// </summary>
Dictionary<TKey, TValue> Dictionary<TKey, TValue>(Sql Sql);
Dictionary<TKey, TValue> Dictionary<TKey, TValue>(Sql sql) where TKey : notnull;

/// <summary>
/// Fetches the first two columns into a dictionary using the first value as the key and the second as the value
/// </summary>
Dictionary<TKey, TValue> Dictionary<TKey, TValue>(string sql, params object[] args);
Dictionary<TKey, TValue> Dictionary<TKey, TValue>(string sql, params object[] args) where TKey : notnull;

/// <summary>
/// Checks if the POCO of type T exists by using the primary key value
Expand Down
27 changes: 14 additions & 13 deletions src/NPoco.Abstractions/Linq/IAsyncQueryProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -14,12 +15,12 @@ public interface IAsyncQueryResultProvider<T>
Task<List<T>> ToList(CancellationToken cancellationToken = default);
Task<T[]> ToArray(CancellationToken cancellationToken = default);
IAsyncEnumerable<T> ToEnumerable(CancellationToken cancellationToken = default);
Task<T> FirstOrDefault(CancellationToken cancellationToken = default);
Task<T> FirstOrDefault(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T?> FirstOrDefault(CancellationToken cancellationToken = default);
Task<T?> FirstOrDefault(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T> First(CancellationToken cancellationToken = default);
Task<T> First(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T> SingleOrDefault(CancellationToken cancellationToken = default);
Task<T> SingleOrDefault(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T?> SingleOrDefault(CancellationToken cancellationToken = default);
Task<T?> SingleOrDefault(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T> Single(CancellationToken cancellationToken = default);
Task<T> Single(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<int> Count(CancellationToken cancellationToken = default);
Expand All @@ -34,12 +35,12 @@ public interface IAsyncQueryResultProvider<T>

public interface IQueryResultProvider<T>
{
T FirstOrDefault();
T FirstOrDefault(Expression<Func<T, bool>> whereExpression);
T? FirstOrDefault();
T? FirstOrDefault(Expression<Func<T, bool>> whereExpression);
T First();
T First(Expression<Func<T, bool>> whereExpression);
T SingleOrDefault();
T SingleOrDefault(Expression<Func<T, bool>> whereExpression);
T? SingleOrDefault();
T? SingleOrDefault(Expression<Func<T, bool>> whereExpression);
T Single();
T Single(Expression<Func<T, bool>> whereExpression);
int Count();
Expand All @@ -58,12 +59,12 @@ public interface IQueryResultProvider<T>
Task<List<T>> ToListAsync(CancellationToken cancellationToken = default);
Task<T[]> ToArrayAsync(CancellationToken cancellationToken = default);
IAsyncEnumerable<T> ToEnumerableAsync(CancellationToken cancellationToken = default);
Task<T> FirstOrDefaultAsync(CancellationToken cancellationToken = default);
Task<T> FirstOrDefaultAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T?> FirstOrDefaultAsync(CancellationToken cancellationToken = default);
Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T> FirstAsync(CancellationToken cancellationToken = default);
Task<T> FirstAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T> SingleOrDefaultAsync(CancellationToken cancellationToken = default);
Task<T> SingleOrDefaultAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T?> SingleOrDefaultAsync(CancellationToken cancellationToken = default);
Task<T?> SingleOrDefaultAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<T> SingleAsync(CancellationToken cancellationToken = default);
Task<T> SingleAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);
Task<int> CountAsync(CancellationToken cancellationToken = default);
Expand Down
2 changes: 1 addition & 1 deletion src/NPoco.Abstractions/NPoco.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Nullable>disable</Nullable>
<LangVersion>latest</LangVersion>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_").Replace(".Abstractions", ""))</RootNamespace>
Expand Down
4 changes: 2 additions & 2 deletions src/NPoco.JsonNet/NPoco.JsonNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Provides an implementation to use Json.NET as the serializer for serialized columns</Description>
<VersionPrefix>5.7.0</VersionPrefix>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<AssemblyName>NPoco.JsonNet</AssemblyName>
<PackageId>NPoco.JsonNet</PackageId>
<PackageTags>orm;sql;micro-orm;database;mvc</PackageTags>
Expand All @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>An extremely easy to use Micro-ORM supporting Sql Server.</Description>
<VersionPrefix>5.7.0</VersionPrefix>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<AssemblyName>NPoco.SqlServer.SystemData</AssemblyName>
<PackageId>NPoco.SqlServer.SystemData</PackageId>
<Authors>Adam Schröder</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/NPoco.SqlServer/NPoco.SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>An extremely easy to use Micro-ORM supporting Sql Server.</Description>
<VersionPrefix>5.7.0</VersionPrefix>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<AssemblyName>NPoco.SqlServer</AssemblyName>
<PackageId>NPoco.SqlServer</PackageId>
<Authors>Adam Schröder</Authors>
Expand Down
Loading

0 comments on commit 7c8d0a9

Please sign in to comment.