Skip to content

Commit

Permalink
Add overloads without sql param
Browse files Browse the repository at this point in the history
Give Fetch(), Query(), Page(), and SkipTake() overloads that omit the
string sql parameter, so that PetaPoco will do SELECT *
  • Loading branch information
asherber authored and pleb committed Nov 1, 2018
1 parent 226a41d commit c86d31c
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
59 changes: 59 additions & 0 deletions PetaPoco/Database.cs
Expand Up @@ -733,6 +733,13 @@ public T ExecuteScalar<T>(Sql sql)


#region operation: Fetch #region operation: Fetch


/// <summary>
/// Runs a SELECT * query and returns the result set as a typed list
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <returns>A List holding the results of the query</returns>
public List<T> Fetch<T>() => Fetch<T>(String.Empty);

/// <summary> /// <summary>
/// Runs a query and returns the result set as a typed list /// Runs a query and returns the result set as a typed list
/// </summary> /// </summary>
Expand Down Expand Up @@ -828,6 +835,20 @@ public Page<T> Page<T>(long page, long itemsPerPage, string sqlCount, object[] c
return result; return result;
} }


/// <summary>
/// Retrieves a page of records and the total number of available records
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <param name="page">The 1 based page number to retrieve</param>
/// <param name="itemsPerPage">The number of records per page</param>
/// <returns>A Page of results</returns>
/// <remarks>
/// PetaPoco will automatically modify a default SELECT * statement to only retrieve the
/// records for the specified page. It will also execute a second query to retrieve the
/// total number of records in the result set.
/// </remarks>
public Page<T> Page<T>(long page, long itemsPerPage) => Page<T>(page, itemsPerPage, String.Empty);

/// <summary> /// <summary>
/// Retrieves a page of records and the total number of available records /// Retrieves a page of records and the total number of available records
/// </summary> /// </summary>
Expand Down Expand Up @@ -890,6 +911,19 @@ public Page<T> Page<T>(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage)


#region operation: Fetch (page) #region operation: Fetch (page)


/// <summary>
/// Retrieves a page of records (without the total count)
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <param name="page">The 1 based page number to retrieve</param>
/// <param name="itemsPerPage">The number of records per page</param>
/// <returns>A List of results</returns>
/// <remarks>
/// PetaPoco will automatically modify a default SELECT * statement to only retrieve the
/// records for the specified page.
/// </remarks>
public List<T> Fetch<T>(long page, long itemsPerPage) => Fetch<T>(page, itemsPerPage, String.Empty);

/// <summary> /// <summary>
/// Retrieves a page of records (without the total count) /// Retrieves a page of records (without the total count)
/// </summary> /// </summary>
Expand Down Expand Up @@ -929,6 +963,19 @@ public List<T> Fetch<T>(long page, long itemsPerPage, Sql sql)


#region operation: SkipTake #region operation: SkipTake


/// <summary>
/// Retrieves a range of records from result set
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <param name="skip">The number of rows at the start of the result set to skip over</param>
/// <param name="take">The number of rows to retrieve</param>
/// <returns>A List of results</returns>
/// <remarks>
/// PetaPoco will automatically modify a default SELECT * statement to only retrieve the
/// records for the specified range.
/// </remarks>
public List<T> SkipTake<T>(long skip, long take) => SkipTake<T>(skip, take, String.Empty);

/// <summary> /// <summary>
/// Retrieves a range of records from result set /// Retrieves a range of records from result set
/// </summary> /// </summary>
Expand Down Expand Up @@ -970,6 +1017,18 @@ public List<T> SkipTake<T>(long skip, long take, Sql sql)


#region operation: Query #region operation: Query


/// <summary>
/// Runs a SELECT * query, returning the results as an IEnumerable collection
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <returns>An enumerable collection of result records</returns>
/// <remarks>
/// For some DB providers, care should be taken to not start a new Query before finishing with
/// and disposing the previous one. In cases where this is an issue, consider using Fetch which
/// returns the results as a List rather than an IEnumerable.
/// </remarks>
public IEnumerable<T> Query<T>() => Query<T>(String.Empty);

/// <summary> /// <summary>
/// Runs an SQL query, returning the results as an IEnumerable collection /// Runs an SQL query, returning the results as an IEnumerable collection
/// </summary> /// </summary>
Expand Down
60 changes: 60 additions & 0 deletions PetaPoco/IQuery.cs
Expand Up @@ -11,6 +11,18 @@ namespace PetaPoco
{ {
public interface IQuery public interface IQuery
{ {
/// <summary>
/// Runs a SELECT * query, returning the results as an IEnumerable collection
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <returns>An enumerable collection of result records</returns>
/// <remarks>
/// For some DB providers, care should be taken to not start a new Query before finishing with
/// and disposing the previous one. In cases where this is an issue, consider using Fetch which
/// returns the results as a List rather than an IEnumerable.
/// </remarks>
IEnumerable<T> Query<T>();

/// <summary> /// <summary>
/// Runs an SQL query, returning the results as an IEnumerable collection /// Runs an SQL query, returning the results as an IEnumerable collection
/// </summary> /// </summary>
Expand Down Expand Up @@ -241,6 +253,13 @@ public interface IQuery
/// <returns>A collection of POCO's as an IEnumerable</returns> /// <returns>A collection of POCO's as an IEnumerable</returns>
IEnumerable<TRet> Query<TRet>(Type[] types, object cb, string sql, params object[] args); IEnumerable<TRet> Query<TRet>(Type[] types, object cb, string sql, params object[] args);


/// <summary>
/// Runs a SELECT * query and returns the result set as a typed list
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <returns>A List holding the results of the query</returns>
List<T> Fetch<T>();

/// <summary> /// <summary>
/// Runs a query and returns the result set as a typed list /// Runs a query and returns the result set as a typed list
/// </summary> /// </summary>
Expand Down Expand Up @@ -276,6 +295,20 @@ public interface IQuery
/// </remarks> /// </remarks>
Page<T> Page<T>(long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs); Page<T> Page<T>(long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs);


/// <summary>
/// Retrieves a page of records and the total number of available records
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <param name="page">The 1 based page number to retrieve</param>
/// <param name="itemsPerPage">The number of records per page</param>
/// <returns>A Page of results</returns>
/// <remarks>
/// PetaPoco will automatically modify a default SELECT * statement to only retrieve the
/// records for the specified page. It will also execute a second query to retrieve the
/// total number of records in the result set.
/// </remarks>
Page<T> Page<T>(long page, long itemsPerPage);

/// <summary> /// <summary>
/// Retrieves a page of records and the total number of available records /// Retrieves a page of records and the total number of available records
/// </summary> /// </summary>
Expand Down Expand Up @@ -323,6 +356,19 @@ public interface IQuery
/// </remarks> /// </remarks>
Page<T> Page<T>(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage); Page<T> Page<T>(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage);


/// <summary>
/// Retrieves a page of records (without the total count)
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <param name="page">The 1 based page number to retrieve</param>
/// <param name="itemsPerPage">The number of records per page</param>
/// <returns>A List of results</returns>
/// <remarks>
/// PetaPoco will automatically modify a default SELECT * statement to only retrieve the
/// records for the specified page.
/// </remarks>
List<T> Fetch<T>(long page, long itemsPerPage);

/// <summary> /// <summary>
/// Retrieves a page of records (without the total count) /// Retrieves a page of records (without the total count)
/// </summary> /// </summary>
Expand Down Expand Up @@ -352,6 +398,20 @@ public interface IQuery
/// </remarks> /// </remarks>
List<T> Fetch<T>(long page, long itemsPerPage, Sql sql); List<T> Fetch<T>(long page, long itemsPerPage, Sql sql);



/// <summary>
/// Retrieves a range of records from result set
/// </summary>
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
/// <param name="skip">The number of rows at the start of the result set to skip over</param>
/// <param name="take">The number of rows to retrieve</param>
/// <returns>A List of results</returns>
/// <remarks>
/// PetaPoco will automatically modify a default SELECT * statement to only retrieve the
/// records for the specified range.
/// </remarks>
List<T> SkipTake<T>(long skip, long take);

/// <summary> /// <summary>
/// Retrieves a range of records from result set /// Retrieves a range of records from result set
/// </summary> /// </summary>
Expand Down

0 comments on commit c86d31c

Please sign in to comment.