- 增加 ClickHouse LimitBy 查询;

This commit is contained in:
2881099
2022-09-18 21:00:51 +08:00
parent 1a4740ed80
commit 9b264aa163
3 changed files with 42 additions and 20 deletions

View File

@ -1,6 +1,8 @@
using FreeSql;
using FreeSql.ClickHouse.Curd;
using FreeSql.Internal.CommonProvider;
using System;
using System.Linq.Expressions;
public static partial class FreeSqlClickHouseGlobalExtensions
{
@ -14,5 +16,21 @@ public static partial class FreeSqlClickHouseGlobalExtensions
public static string FormatClickHouse(this string that, params object[] args) => _clickHouseAdo.Addslashes(that, args);
static FreeSql.ClickHouse.ClickHouseAdo _clickHouseAdo = new FreeSql.ClickHouse.ClickHouseAdo();
public static ISelect<T> LimitBy<T>(this ISelect<T> that, Expression<Func<T, object>> selector, int limit, int offset = 0)
{
if (limit <= 0 && offset <= 0) return that;
var s0p = that as ClickHouseSelect<T>;
var oldOrderBy = s0p._orderby;
s0p._orderby = "";
try
{
s0p.InternalOrderBy(selector);
s0p._limitBy = $"limit {(offset > 0 ? $"{offset}, " : "")}{limit} by {s0p._orderby}";
}
finally
{
s0p._orderby = oldOrderBy;
}
return that;
}
}