Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dotnetcore/FreeSql
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Apr 18, 2021
2 parents 7a33511 + 7206d39 commit db701f0
Show file tree
Hide file tree
Showing 23 changed files with 584 additions and 4 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/docfx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: .NET Core Deploy Docfx

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.202
- name: Exclude example projects
run: dotnet sln FreeSql.sln remove Examples/**/*.csproj FreeSql.Tests/**/*.csproj
- name: Install dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration Release --no-restore

generate-docs:
runs-on: windows-latest
needs: build

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.202
- name: Remove Examples
run: dotnet sln FreeSql.sln remove (ls -r Examples/**/*.csproj)
- name: Remove FreeSql.Tests
run: dotnet sln FreeSql.sln remove (ls -r FreeSql.Tests/**/*.csproj)
- name: Install dependencies
run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config && dotnet restore
- name: Setup DocFX
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install docfx --version 2.56.7
- name: DocFX Build
working-directory: docs
run: docfx docfx.json
continue-on-error: false
- name: Publish
if: github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_site
force_orphan: true
11 changes: 11 additions & 0 deletions Examples/repository_01/Controllers/SongController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public Task<List<Song>> GetItems([FromQuery] string key, [FromQuery] int page =
return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
}

/// <summary>
/// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
/// </summary>
/// <param name="pagingInfo"></param>
/// <returns></returns>
[HttpGet("GetPagingItems")]
public Task<List<Song>> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
{
return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
}

[HttpGet("{id}")]
public Task<Song> GetItem([FromRoute] int id)
{
Expand Down
57 changes: 57 additions & 0 deletions Examples/repository_01/PagingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using FreeSql.Internal.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace repository_01
{
public class PagingInfo : BasePagingInfo
{
/// <summary>
/// 无参构造函数
/// </summary>
public PagingInfo()
{
}
/// <summary>
/// 当前为第1页,每页大小的构造函数
/// </summary>
/// <param name="pageSize"></param>
public PagingInfo(int pageSize)
{
PageNumber = 1;
PageSize = pageSize;
}
/// <summary>
/// 带当前页和每页大小的构造函数
/// </summary>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
public PagingInfo(int pageNumber, int pageSize)
{
PageNumber = pageNumber;
PageSize = pageSize;
}
/// <summary>
/// 当前有多少页【只读】
/// </summary>
public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
/// <summary>
/// 是否有上一页【只读】
/// </summary>
public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
/// <summary>
/// 是否有下一页【只读】
/// </summary>
public bool HasNext => PageNumber < PageCount;
/// <summary>
/// 是否在第一页【只读】
/// </summary>
public bool IsFrist => PageNumber == 1;
/// <summary>
/// 是否在最后一页【只读】
/// </summary>
public bool IsLast => PageNumber == PageCount;
}
}
12 changes: 12 additions & 0 deletions Examples/restful/Controllers/SongController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ public Task<List<Song>> GetItems([FromQuery] string key, [FromQuery] int page =
return _fsql.Select<Song>().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
}

/// <summary>
/// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
/// </summary>
/// <param name="key"></param>
/// <param name="pagingInfo"></param>
/// <returns></returns>
[HttpGet("GetPagingItems")]
public Task<List<Song>> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
{
return _fsql.Select<Song>().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
}

[HttpGet("{id}")]
public Task<Song> GetItem([FromRoute] int id)
{
Expand Down
57 changes: 57 additions & 0 deletions Examples/restful/PagingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using FreeSql.Internal.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace restful
{
public class PagingInfo : BasePagingInfo
{
/// <summary>
/// 无参构造函数
/// </summary>
public PagingInfo()
{
}
/// <summary>
/// 当前为第1页,每页大小的构造函数
/// </summary>
/// <param name="pageSize"></param>
public PagingInfo(int pageSize)
{
PageNumber = 1;
PageSize = pageSize;
}
/// <summary>
/// 带当前页和每页大小的构造函数
/// </summary>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
public PagingInfo(int pageNumber, int pageSize)
{
PageNumber = pageNumber;
PageSize = pageSize;
}
/// <summary>
/// 当前有多少页【只读】
/// </summary>
public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
/// <summary>
/// 是否有上一页【只读】
/// </summary>
public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
/// <summary>
/// 是否有下一页【只读】
/// </summary>
public bool HasNext => PageNumber < PageCount;
/// <summary>
/// 是否在第一页【只读】
/// </summary>
public bool IsFrist => PageNumber == 1;
/// <summary>
/// 是否在最后一页【只读】
/// </summary>
public bool IsLast => PageNumber == PageCount;
}
}
34 changes: 34 additions & 0 deletions FreeSql/FreeSql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions FreeSql/Interface/Curd/ISelect/ISelect0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ public partial interface ISelect0<TSelect, T1> : ISelect0
/// <returns></returns>
TSelect Page(int pageNumber, int pageSize);

/// <summary>
/// 分页
/// </summary>
/// <param name="pagingInfo">分页信息</param>
/// <returns></returns>
TSelect Page(BasePagingInfo pagingInfo);

/// <summary>
/// 查询数据前,去重
/// <para>
Expand Down
10 changes: 9 additions & 1 deletion FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using FreeSql.Internal.Model;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
Expand Down Expand Up @@ -101,6 +102,13 @@ public interface ISelectGrouping<TKey, TValue>
/// <returns></returns>
ISelectGrouping<TKey, TValue> Page(int pageNumber, int pageSize);

/// <summary>
/// 分页
/// </summary>
/// <param name="pagingInfo">分页信息</param>
/// <returns></returns>
ISelectGrouping<TKey, TValue> Page(BasePagingInfo pagingInfo);

/// <summary>
/// 查询的记录数量
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/Internal/CommonProvider/InsertProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInf
}
if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false)
col.SetValue(data, val = "");
if (val == null && col.Attribute.MapType == typeof(byte[]) && col.Attribute.IsVersion)
if (col.Attribute.MapType == typeof(byte[]) && (val == null || (val is byte[] bytes && bytes.Length == 0)) && col.Attribute.IsVersion)
col.SetValue(data, val = Utils.GuidToBytes(Guid.NewGuid()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ public TSelect Page(int pageNumber, int pageSize)
return this.Limit(pageSize) as TSelect;
}

public TSelect Page(BasePagingInfo pagingInfo)
{
pagingInfo.Count = this.Count();
this.Skip(Math.Max(0, pagingInfo.PageNumber - 1) * pagingInfo.PageSize);
return this.Limit(pagingInfo.PageSize) as TSelect;
}

public TSelect Skip(int offset)
{
_skip = offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ public ISelectGrouping<TKey, TValue> Page(int pageNumber, int pageSize)
return this;
}

public ISelectGrouping<TKey, TValue> Page(BasePagingInfo pagingInfo)
{
pagingInfo.Count = this.Count();
_groupBySkip = Math.Max(0, pagingInfo.PageNumber - 1) * pagingInfo.PageSize;
_groupByLimit = pagingInfo.PageSize;
return this;
}

public long Count() => _select._cancel?.Invoke() == true ? 0 : long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_select._connection, _select._transaction, CommandType.Text, $"select count(1) from ({this.ToSql($"1{_comonExp._common.FieldAsAlias("as1")}")}) fta", _select._commandTimeout, _select._params.ToArray())), out var trylng) ? trylng : default(long);
public ISelectGrouping<TKey, TValue> Count(out long count)
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql/Internal/Model/BasePagingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace FreeSql.Internal.Model
{
/// <summary>
/// 分页信息
/// </summary>
public class BasePagingInfo
{
/// <summary>
/// 第几页,从1开始
/// </summary>
public int PageNumber { get; set; }
/// <summary>
/// 每页多少
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// 查询的记录数量
/// </summary>
public long Count { get; set; }
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ constantine,

L*y 58元、花花 88元、麦兜很乖 50元、网络来者 2000元、John 99.99元、alex 666元、bacongao 36元、无名 100元、Eternity 188元、无名 10元、⌒.Helper~..oO 66元、习惯与被习惯 100元、无名 100元、蔡易喋 88.88元、中讯科技 1000元、Good Good Work 24元、炽焰 6.6元、Nothing 100元、兰州天擎赵 500元、哈利路亚 300元、
无名 100元、蛰伏 99.99元、TCYM 66.66元、MOTA 5元、LDZXG 30元、Near 30元、建爽 66元、无名 200元、LambertWu 100元、无名 18.88元、乌龙 50元、无名 100元、陳怼怼 66.66元、陳怼怼 66.66元、丁淮 100元、李伟坚-Excel催化剂 100元、白狐 6.66元、她微笑的脸y 30元、Eternity²º²¹ 588元、夜归柴门 88元、蔡易喋 666.66元、
*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k\*t 66元、蓝 100元
*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k\*t 66元、蓝 100元*菜 10元、生命如歌 1000元

> Thank you for your donation
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ constantine,

L*y 58元、花花 88元、麦兜很乖 50元、网络来者 2000元、John 99.99元、alex 666元、bacongao 36元、无名 100元、Eternity 188元、无名 10元、⌒.Helper~..oO 66元、习惯与被习惯 100元、无名 100元、蔡易喋 88.88元、中讯科技 1000元、Good Good Work 24元、炽焰 6.6元、Nothing 100元、兰州天擎赵 500元、哈利路亚 300元、
无名 100元、蛰伏 99.99元、TCYM 66.66元、MOTA 5元、LDZXG 30元、Near 30元、建爽 66元、无名 200元、LambertWu 100元、无名 18.88元、乌龙 50元、无名 100元、陳怼怼 66.66元、陳怼怼 66.66元、丁淮 100元、李伟坚-Excel催化剂 100元、白狐 6.66元、她微笑的脸y 30元、Eternity²º²¹ 588元、夜归柴门 88元、蔡易喋 666.66元、
*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k*t 66元、蓝 100元
*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k*t 66元、蓝 100元*菜 10元、生命如歌 1000元

> 超级感谢你的打赏。
Expand Down
Loading

0 comments on commit db701f0

Please sign in to comment.