Skip to content

Commit

Permalink
Merge pull request #1123 from ngardon/SkipQuery
Browse files Browse the repository at this point in the history
Issue #377 : SkipQuery
  • Loading branch information
mikependon authored Dec 27, 2022
2 parents faacb39 + 2a5c41e commit a36c309
Show file tree
Hide file tree
Showing 26 changed files with 8,426 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public string CreateQueryAll(string tableName, IEnumerable<Field> fields, IEnume
return string.Empty;
}

public string CreateSkipQuery(string tableName, IEnumerable<Field> fields, int skip, int take, IEnumerable<OrderField> orderBy = null, QueryGroup where = null, string hints = null)
{
return string.Empty;
}

public string CreateSum(string tableName, Field field, QueryGroup where = null, string hints = null)
{
return string.Empty;
Expand Down Expand Up @@ -158,6 +163,11 @@ public override string CreateMergeAll(string tableName, IEnumerable<Field> field
{
return string.Empty;
}

public override string CreateSkipQuery(string tableName, IEnumerable<Field> fields, int skip, int take, IEnumerable<OrderField> orderBy = null, QueryGroup where = null, string hints = null)
{
return string.Empty;
}
}

public class CustomNonHintsSupportingBaseStatementBuilder : CustomBaseStatementBuilder
Expand Down
74 changes: 74 additions & 0 deletions RepoDb.Core/RepoDb/Cachers/CommandTextCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,80 @@ private static string GetQueryMultipleTextInternal(QueryMultipleRequest request,

#endregion

#region GetSkipQueryText

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
internal static string GetSkipQueryText(SkipQueryRequest request)
{
if (cache.TryGetValue(request, out var commandText) == false)
{
var fields = GetTargetFields(request.Connection,
request.Name,
request.Fields,
request.Transaction);
ValidateOrderFields(request.Connection,
request.Name,
request.OrderBy,
request.Transaction);
commandText = GetSkipQueryTextInternal(request, fields);
cache.TryAdd(request, commandText);
}
return commandText;
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
internal static async Task<string> GetSkipQueryTextAsync(SkipQueryRequest request,
CancellationToken cancellationToken = default)
{
if (cache.TryGetValue(request, out var commandText) == false)
{
var fields = await GetTargetFieldsAsync(request.Connection,
request.Name,
request.Fields,
request.Transaction,
cancellationToken);
await ValidateOrderFieldsAsync(request.Connection,
request.Name,
request.OrderBy,
request.Transaction,
cancellationToken);
commandText = GetSkipQueryTextInternal(request, fields);
cache.TryAdd(request, commandText);
}
return commandText;
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="fields"></param>
/// <returns></returns>
internal static string GetSkipQueryTextInternal(SkipQueryRequest request,
IEnumerable<Field> fields)
{
var statementBuilder = EnsureStatementBuilder(request.Connection, request.StatementBuilder);
return statementBuilder.CreateSkipQuery(request.Name,
fields,
request.Skip,
request.RowsPerBatch,
request.OrderBy,
request.Where,
request.Hints);
}

#endregion


#region GetSumText

/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions RepoDb.Core/RepoDb/Interfaces/IStatementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ string CreateBatchQuery(string tableName,

#endregion

#region CreateSkipQuery

/// <summary>
/// Creates a SQL Statement for 'BatchQuery' operation.
/// </summary>
/// <param name="tableName">The name of the target table.</param>
/// <param name="fields">The mapping list of <see cref="Field"/> objects to be used.</param>
/// <param name="skip">The number of rows to skip.</param>
/// <param name="take">The number of rows per batch.</param>
/// <param name="orderBy">The list of fields for ordering.</param>
/// <param name="where">The query expression.</param>
/// <param name="hints">The table hints to be used.</param>
/// <returns>A sql statement for batch query operation.</returns>
string CreateSkipQuery(string tableName,
IEnumerable<Field> fields,
int skip,
int take,
IEnumerable<OrderField> orderBy = null,
QueryGroup where = null,
string hints = null);

#endregion

#region CreateCount

/// <summary>
Expand Down
Loading

0 comments on commit a36c309

Please sign in to comment.