Skip to content

Commit

Permalink
add region scopes to IAlterPoco/Async, IQuery/Async
Browse files Browse the repository at this point in the history
  • Loading branch information
Ste1io committed Jun 25, 2023
1 parent 8b0b331 commit ac80468
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 9 deletions.
32 changes: 26 additions & 6 deletions PetaPoco/IAlterPoco.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace PetaPoco
{
public interface IAlterPoco
{
#region Insert

/// <summary>
/// Performs an SQL Insert.
/// </summary>
Expand Down Expand Up @@ -44,6 +46,10 @@ public interface IAlterPoco
/// <returns>The auto allocated primary key of the new record, or <see langword="null"/> for non-auto-increment tables.</returns>
object Insert(object poco);

#endregion

#region Update

/// <summary>
/// Performs an SQL update.
/// </summary>
Expand Down Expand Up @@ -133,6 +139,10 @@ public interface IAlterPoco
/// <returns>The number of affected rows.</returns>
int Update<T>(Sql sql);

#endregion

#region Delete

/// <summary>
/// Performs an SQL Delete.
/// </summary>
Expand Down Expand Up @@ -184,8 +194,12 @@ public interface IAlterPoco
/// <returns>The number of affected rows.</returns>
int Delete<T>(Sql sql);

#endregion

#region IsNew

/// <summary>
/// Check if a poco represents a new row.
/// Checks if a poco represents a new row.
/// </summary>
/// <remarks>
/// This method simply tests if the POCO's primary key column property has a non-default value.
Expand All @@ -196,7 +210,7 @@ public interface IAlterPoco
bool IsNew(string primaryKeyName, object poco);

/// <summary>
/// Check if a poco represents a new row.
/// Checks if a poco represents a new row.
/// </summary>
/// <remarks>
/// This method simply tests if the POCO's primary key column property has a non-default value.
Expand All @@ -205,18 +219,24 @@ public interface IAlterPoco
/// <returns><see langword="true"/> if the POCO represents a record already in the database.</returns>
bool IsNew(object poco);

#endregion

#region Save

/// <summary>
/// Saves a POCO by either performing either an SQL Insert or SQL Update.
/// Saves a POCO by performing either an INSERT or UPDATE operation.
/// </summary>
/// <param name="tableName">The name of the table to be updated.</param>
/// <param name="primaryKeyName">The name of the primary key column.</param>
/// <param name="poco">A POCO object to be saved.</param>
/// <param name="poco">The POCO object to be saved.</param>
void Save(string tableName, string primaryKeyName, object poco);

/// <summary>
/// Saves a POCO by either performing either an SQL Insert or SQL Update.
/// Saves a POCO by performing either an INSERT or UPDATE operation.
/// </summary>
/// <param name="poco">A POCO object to be saved.</param>
/// <param name="poco">The POCO object to be saved.</param>
void Save(object poco);

#endregion
}
}
19 changes: 17 additions & 2 deletions PetaPoco/IAlterPocoAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace PetaPoco
{
public interface IAlterPocoAsync
{
#region Insert

/// <summary>
/// Async version of <see cref="IAlterPoco.Insert(string, object)" />.
/// </summary>
Expand Down Expand Up @@ -46,6 +48,10 @@ public interface IAlterPocoAsync
/// </summary>
Task<object> InsertAsync(CancellationToken cancellationToken, object poco);

#endregion

#region Update

/// <summary>
/// Async version of <see cref="IAlterPoco.Update(string, string, object, object)" />.
/// </summary>
Expand All @@ -64,8 +70,7 @@ public interface IAlterPocoAsync
/// <summary>
/// Async version of <see cref="IAlterPoco.Update(string, string, object, object, IEnumerable{string})" />.
/// </summary>
Task<int> UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue,
IEnumerable<string> columns);
Task<int> UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable<string> columns);

/// <summary>
/// Async version of <see cref="IAlterPoco.Update(string, string, object)" />.
Expand Down Expand Up @@ -147,6 +152,10 @@ Task<int> UpdateAsync(CancellationToken cancellationToken, string tableName, str
/// </summary>
Task<int> UpdateAsync<T>(CancellationToken cancellationToken, Sql sql);

#endregion

#region Delete

/// <summary>
/// Async version of <see cref="IAlterPoco.Delete(string, string, object)" />.
/// </summary>
Expand Down Expand Up @@ -207,6 +216,10 @@ Task<int> UpdateAsync(CancellationToken cancellationToken, string tableName, str
/// </summary>
Task<int> DeleteAsync<T>(CancellationToken cancellationToken, Sql sql);

#endregion

#region Save

/// <summary>
/// Async version of <see cref="IAlterPoco.Save(string, string, object)" />.
/// </summary>
Expand All @@ -226,5 +239,7 @@ Task<int> UpdateAsync(CancellationToken cancellationToken, string tableName, str
/// Async version of <see cref="IAlterPoco.Save(object)" />.
/// </summary>
Task SaveAsync(CancellationToken cancellationToken, object poco);

#endregion
}
}
40 changes: 40 additions & 0 deletions PetaPoco/IQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace PetaPoco
{
public interface IQuery
{
#region Query

/// <summary>
/// Streams the result of a select all query (SELECT *).
/// </summary>
Expand Down Expand Up @@ -241,6 +243,10 @@ public interface IQuery
/// <returns>A collection of POCOs as an IEnumerable.</returns>
IEnumerable<TRet> Query<TRet>(Type[] types, object cb, string sql, params object[] args);

#endregion

#region Fetch

/// <summary>
/// Runs a SELECT * query and returns the result set as a typed list.
/// </summary>
Expand Down Expand Up @@ -496,6 +502,10 @@ public interface IQuery
/// <returns>A collection of POCOs as a List.</returns>
List<T1> Fetch<T1, T2, T3, T4, T5>(Sql sql);

#endregion

#region Page

/// <summary>
/// Retrieves a page of records and the total number of available records.
/// </summary>
Expand Down Expand Up @@ -565,6 +575,10 @@ public interface IQuery
/// <returns>A Page of results.</returns>
Page<T> Page<T>(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage);

#endregion

#region SkipTake

/// <summary>
/// Retrieves a range of records from result set.
/// </summary>
Expand Down Expand Up @@ -604,6 +618,10 @@ public interface IQuery
/// <returns>A List of results.</returns>
List<T> SkipTake<T>(long skip, long take, Sql sql);

#endregion

#region Exists

/// <summary>
/// Checks for the existence of a row with the specified primary key value.
/// </summary>
Expand All @@ -621,6 +639,10 @@ public interface IQuery
/// <returns><see langword="true"/> if a record matching the condition is found, otherwise <see langword="false"/>.</returns>
bool Exists<T>(string sqlCondition, params object[] args);

#endregion

#region Single

/// <summary>
/// Returns the record with the specified primary key value.
/// </summary>
Expand Down Expand Up @@ -655,6 +677,10 @@ public interface IQuery
/// <returns>The single record matching the specified SQL query.</returns>
T Single<T>(Sql sql);

#endregion

#region SingleOrDefault

/// <summary>
/// Runs a query that should always return either a single row, or no rows.
/// </summary>
Expand Down Expand Up @@ -683,6 +709,10 @@ public interface IQuery
/// <returns>The single record matching the specified primary key value, or default(T) if no matching rows.</returns>
T SingleOrDefault<T>(string sql, params object[] args);

#endregion

#region First

/// <summary>
/// Runs a query that should always return at least one record.
/// </summary>
Expand All @@ -700,6 +730,10 @@ public interface IQuery
/// <returns>The first record in the result set.</returns>
T First<T>(Sql sql);

#endregion

#region FirstOrDefault

/// <summary>
/// Runs a query and returns the first record, or the default value if no matching records.
/// </summary>
Expand All @@ -717,6 +751,10 @@ public interface IQuery
/// <returns>The first record in the result set, or default(T) if no matching rows.</returns>
T FirstOrDefault<T>(Sql sql);

#endregion

#region QueryMultiple

/// <summary>
/// Perform a multi-results set query.
/// </summary>
Expand All @@ -731,5 +769,7 @@ public interface IQuery
/// <param name="args">Arguments to any embedded parameters in the SQL.</param>
/// <returns>A GridReader to be queried.</returns>
IGridReader QueryMultiple(string sql, params object[] args);

#endregion
}
}
42 changes: 41 additions & 1 deletion PetaPoco/IQueryAsync.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
Expand All @@ -9,6 +9,8 @@ namespace PetaPoco
#if ASYNC
public interface IQueryAsync
{
#region Query

/// <summary>
/// Async version of <see cref="IQuery.Query{T}()" />.
/// </summary>
Expand Down Expand Up @@ -129,6 +131,10 @@ public interface IQueryAsync
/// </summary>
Task<IAsyncReader<T>> QueryAsync<T>(CancellationToken cancellationToken, CommandType commandType, Sql sql);

#endregion

#region Fetch

/// <summary>
/// Async version of <see cref="IQuery.Fetch{T}()" />.
/// </summary>
Expand Down Expand Up @@ -219,6 +225,10 @@ public interface IQueryAsync
/// </summary>
Task<List<T>> FetchAsync<T>(CancellationToken cancellationToken, long page, long itemsPerPage, Sql sql);

#endregion

#region Page

/// <summary>
/// Async version of <see cref="IQuery.Page{T}(long,long,string,object[],string,object[])" />.
/// </summary>
Expand Down Expand Up @@ -269,6 +279,10 @@ public interface IQueryAsync
/// </summary>
Task<Page<T>> PageAsync<T>(CancellationToken cancellationToken, long page, long itemsPerPage, Sql sqlCount, Sql sqlPage);

#endregion

#region SkipTake

/// <summary>
/// Async version of <see cref="IQuery.SkipTake{T}(long,long)" />.
/// </summary>
Expand Down Expand Up @@ -299,6 +313,10 @@ public interface IQueryAsync
/// </summary>
Task<List<T>> SkipTakeAsync<T>(CancellationToken cancellationToken, long skip, long take, Sql sql);

#endregion

#region Exists

/// <summary>
/// Async version of <see cref="IQuery.Exists{T}(object)" />.
/// </summary>
Expand All @@ -319,6 +337,10 @@ public interface IQueryAsync
/// </summary>
Task<bool> ExistsAsync<T>(CancellationToken cancellationToken, string sqlCondition, params object[] args);

#endregion

#region Single

/// <summary>
/// Async version of <see cref="IQuery.Single{T}(object)" />.
/// </summary>
Expand Down Expand Up @@ -349,6 +371,10 @@ public interface IQueryAsync
/// </summary>
Task<T> SingleAsync<T>(CancellationToken cancellationToken, Sql sql);

#endregion

#region SingleOrDefault

/// <summary>
/// Async version of <see cref="IQuery.SingleOrDefault{T}(Sql)" />.
/// </summary>
Expand Down Expand Up @@ -379,6 +405,10 @@ public interface IQueryAsync
/// </summary>
Task<T> SingleOrDefaultAsync<T>(CancellationToken cancellationToken, string sql, params object[] args);

#endregion

#region First

/// <summary>
/// Async version of <see cref="IQuery.First{T}(string,object[])" />.
/// </summary>
Expand All @@ -399,6 +429,10 @@ public interface IQueryAsync
/// </summary>
Task<T> FirstAsync<T>(CancellationToken cancellationToken, Sql sql);

#endregion

#region FirstOrDefault

/// <summary>
/// Async version of <see cref="IQuery.FirstOrDefault{T}(string,object[])" />.
/// </summary>
Expand All @@ -418,6 +452,12 @@ public interface IQueryAsync
/// Async version of <see cref="IQuery.FirstOrDefault{T}(Sql)" />.
/// </summary>
Task<T> FirstOrDefaultAsync<T>(CancellationToken cancellationToken, Sql sql);

#endregion

#region QueryMultiple

#endregion
}
#endif
}

0 comments on commit ac80468

Please sign in to comment.