Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into main
  • Loading branch information
2881099 committed Dec 6, 2024
2 parents 09341c5 + b2c8dab commit cd48a52
Show file tree
Hide file tree
Showing 19 changed files with 480 additions and 26 deletions.
Binary file added docs/.vuepress/public/aliyun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.vuepress/public/rhino-design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/.vuepress/sidebar/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const zhSidebarConfig = sidebar({
"freesql-provider-questdb",
"freesql-provider-firebird",
"freesql-provider-duckdb",
"freesql-provider-tdengine",
],
},
"expression-function",
Expand Down
71 changes: 68 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ features:
- title: 超前理念
details: MIT 开源,零依赖包
- title: 数据库
details: 支持常见 17 种数据库
details: 支持常见 26 种数据库
link: /guide/
- title: 查询
details: 多表/嵌套/联合/递归等
Expand Down Expand Up @@ -53,15 +53,30 @@ footer: MIT Licensed | Copyright © 2018-present nicye

> 扫码捐助请作者喝一杯咖啡
<img src="/barcode_2x1.png" style="width:400px;height:255px;" />
<div class="vp-donation">
<div class="vp-donation-item">
<img src="/barcode_2x1.png" style="width:400px;height:255px;" />
</div>
<div class="vp-donation-item">
<a style="margin-left:20px;cursor:pointer" target="_blank" href="https://curl.qcloud.com/lj8Rbc9Y">
<img src="/rhino-design.png" style="width:400px;" />
<h4>【腾讯云】2核2G云服务器新老同享 99元/年,续费同价</h4>
</a>
</div>
<div class="vp-donation-item">
<a style="margin-left:20px;cursor:pointer" target="_blank" href="https://t.aliyun.com/U/rs0mOj">
<img src="/aliyun.png" style="width:400px;" />
<h4>【阿里云】云服务器经济型e实例/2核2G/3M/40g,新人专享渠道特惠价只要99元!</h4>
</a>
</div>
</div>

## 👯 Contributors (贡献者)

<a href="https://contributors-img.web.app/image?repo=dotnetcore/FreeSql">
<img src="https://contributors-img.web.app/image?repo=dotnetcore/FreeSql" />
</a>


## 🗄 License (许可证)

[MIT](https://github.com/dotnetcore/FreeSql/blob/master/LICENSE)
Expand All @@ -72,3 +87,53 @@ footer: MIT Licensed | Copyright © 2018-present nicye
data-ad-slot="3532742594"
data-ad-format="auto"
data-full-width-responsive="true"></ins>

<style>
.vp-donation {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
align-items: center; /* 确保项目在交叉轴上居中对齐 */
padding: 20px;
}

.vp-donation-item {
flex-basis: calc(33.333% - 20px); /* 基础大小为三分之一减去间距 */
max-width: calc(33.333% - 20px); /* 最大宽度也是三分之一减去间距 */
margin: 10px;
text-align: center;
}

.vp-donation-item img {
width: 100%; /* 图片宽度充满容器 */
height: auto; /* 高度自动调整 */
}

.vp-donation-item a {
text-decoration: none;
color: inherit;
display: inline-block;
margin-top: 10px;
}

.vp-donation-item h4 {
margin: 5px 0;
font-size: 16px;
}

/* 媒体查询,针对中等屏幕设备 */
@media (max-width: 1024px) {
.vp-donation-item {
flex-basis: calc(50% - 20px); /* 中等屏幕宽度下,一行显示两个 */
max-width: calc(50% - 20px);
}
}

/* 媒体查询,针对小屏幕设备 */
@media (max-width: 600px) {
.vp-donation-item {
flex-basis: 100%; /* 小屏幕宽度下,一行显示一个 */
max-width: 100%;
}
}
</style>
23 changes: 23 additions & 0 deletions docs/en/guide/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ repo.Update(item); // Compare changes from snapshot
Dictionary<string, object[]> CompareState(TEntity newdata);
```

It should be noted that when using Repository updates, `ServerTime` should not be specified in ColumnAttribute.

~~~csharp
var repo = fsql.GetRepository<Dictionaries>();
var item = await repo.Where(a => a.DictId == "1").FirstAsync();

//If the ServerTime property exists in the Column attribute, it may result in the inability to modify it
item.UpdateTime = DateTime.Now;
await repo.UpdateAsync(item);

public class Dictionaries
{
[Column(Name = "id", IsPrimary = true)]
public string Id { get; set; }

[Column(Name = "name")]
public string Name { get; set; }

[Column(Name = "update_time", ServerTime = DateTimeKind.Local)]
public DateTime? UpdateTime { get; set; }
}
~~~

## Login Information (Dependency Injection)

`repo.DbContextOptions.AuditValue` is suitable for integration with AddScoped (Dependency Injection) to uniformly set login information.
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Install-Package FreeSql.Provider.Sqlite
| [FreeSql.Provider.SqliteCore](freesql-provider-sqlitecore.md) | 基于 Microsoft.Data.Sqlite.Core,需安装 bundle_xxx |
| [FreeSql.Provider.Duckdb](freesql-provider-duckdb.md) | 基于 DuckDB.NET.Data.Full |
| FreeSql.Provider.ClickHouse | 基于 ClickHouse.Client |
| [FreeSql.Provider.TDengine](freesql-provider-tdengine.md) | 基于 TDengine.Connector(TaoS 官方驱动) |
| [FreeSql.Provider.QuestDb](freesql-provider-questdb.md) | 基于 Npgsql 和 RestApi |
| FreeSql.Provider.Oracle | |
| [FreeSql.Provider.OracleOledb](freesql-provider-oracle.md) | 基于 Oledb 解决 US7ASCII 中文乱码问题 |
Expand Down Expand Up @@ -175,6 +176,7 @@ fsql.GlobalFilter //全局过滤器对象
| DataType.DuckDB | [https://duckdb.net/docs/connection-string.html](https://duckdb.net/docs/connection-string.html) |
| DataType.ClickHouse | DataCompress=False;BufferSize=32768;SocketTimeout=10000;CheckCompressedHash=False;Encrypt=False;Compressor=lz4;Host=192.168.0.121;Port=8125;Database=PersonnelLocation;Username=root;Password=123 |
| DataType.Firebird | database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456 |
| DataType.TDengine | host=localhost;port=6030;username=root;password=taosdata;protocol=Native;db=test; |
| DataType.QuestDb | host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading; |
| DataType.MsAccess | Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:/accdb/2003.mdb |
| DataType.MsAccess(accdb) | Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:/accdb/2003.accdb; |
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/entity-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ class JsonPocoTypeHandler : TypeHandler<JsonPoco>
{
public override object Serialize(JsonPoco value) => JsonConvert.SerializeObject(value);
public override JsonPoco Deserialize(object value) => JsonConvert.DeserializeObject<JsonPoco>((string)value);
public override void FluentApi(FluentColumn col) => col.MapType(typeof(string)).StringLength(-1);
public override void FluentApi(ColumnFluent col) => col.MapType(typeof(string)).StringLength(-1);
}
class DateOnlyTypeHandler : TypeHandler<DateOnly>
{
public override object Serialize(DateOnly value) => value.ToString("yyyy-MM-dd");
public override DateOnly Deserialize(object value) => DateOnly.TryParse(string.Concat(value), out var trydo) ? trydo : DateOnly.MinValue;
public override void FluentApi(FluentColumn col) => col.MapType(typeof(string)).StringLength(12);
public override void FluentApi(ColumnFluent col) => col.MapType(typeof(string)).StringLength(12);
}
class DateTimeOffsetTypeHandler : TypeHandler<DateTimeOffset>
{
public override object Serialize(DateTimeOffset value) => value.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss");
public override DateTimeOffset Deserialize(object value) => DateTimeOffset.TryParse((string)value, out var dts) ? dts : DateTimeOffset.MinValue;
public override void FluentApi(FluentColumn col) => col.MapType(typeof(string)).DbType("datetime");
public override void FluentApi(ColumnFluent col) => col.MapType(typeof(string)).DbType("datetime");
}
```

Expand Down Expand Up @@ -278,7 +278,7 @@ fsql.Select<Table>().Where(a => a.Options.Value1 == 100 && a.Options.Value2 == "

适用场景:当实体类继承时,CodeFirst 创建表的字段顺序可能不是想要的,通过该特性可以设置顺序。

创建表时指定字段位置,如:[Column(Position = 1],可为负数即反方向位置;
创建表时指定字段位置,如:[Column(Position = 1)],可为负数即反方向位置;

## 可插入(CanInsert)、可更新(CanUpdate)

Expand Down
5 changes: 5 additions & 0 deletions docs/guide/expression-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ fsql.Select<T>()
.Where(a => a.CreateTime.Between(DateTime.Today, DateTime.Today.AddDays(1)))
.ToList();
//正常用法应该是这样
fsql.Select<T>()
.Where(a => a.CreateTime.Subtract(DateTime.Today).TotalDays == 0)
.ToList();
//WHERE datediff(day, date1, date2) = 0
```

> SqlServer nvarchar/varchar 已兼容表达式解析,分别解析为:N'' 和 '',优化索引执行计划;
Expand Down
80 changes: 78 additions & 2 deletions docs/guide/freeredis.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
- 🎣 支持主从分离(Master-Slave)
- 📡 支持发布订阅(Pub-Sub)
- 📃 支持 Redis Lua 脚本
- 💻 支持管道(Pipeline)
- 📰 支持事务
- 💻 支持管道(Pipeline)、支持事务、延迟队列、RediSearch
- 🌴 支持 GEO 命令(服务端要求 3.2 及以上版本)
- 🌲 支持 STREAM 类型命令(服务端要求 5.0 及以上版本)
- ⚡ 支持本地缓存(Client-side-cahing,服务端要求 6.0 及以上版本)
Expand Down Expand Up @@ -177,3 +176,80 @@ foreach (var keys in cli.Scan("*", 10, null))
Console.WriteLine(string.Join(", ", keys));
}
```

## 🍡DelayQueue (延时队列)

```c#
var delayQueue = cli.DelayQueue("TestDelayQueue");

//添加队列
delayQueue.Enqueue($"Execute in 5 seconds.", TimeSpan.FromSeconds(5));
delayQueue.Enqueue($"Execute in 10 seconds.", DateTime.Now.AddSeconds(10));
delayQueue.Enqueue($"Execute in 15 seconds.", DateTime.Now.AddSeconds(15));
delayQueue.Enqueue($"Execute in 20 seconds.", TimeSpan.FromSeconds(20));
delayQueue.Enqueue($"Execute in 25 seconds.", DateTime.Now.AddSeconds(25));
delayQueue.Enqueue($"Execute in 2024-07-02 14:30:15", DateTime.Parse("2024-07-02 14:30:15"));

//消费延时队列
await delayQueue.DequeueAsync(s =>
{
output.WriteLine($"{DateTime.Now}:{s}");

return Task.CompletedTask;
});
```

## 🐆 RediSearch

```csharp
cli.FtCreate(...).Execute();
cli.FtSearch(...).Execute();
cli.FtAggregate(...).Execute();
//... or ...
[FtDocument("index_post", Prefix = "blog:post:")]
class TestDoc
{
[FtKey]
public int Id { get; set; }

[FtTextField("title", Weight = 5.0)]
public string Title { get; set; }

[FtTextField("category")]
public string Category { get; set; }

[FtTextField("content", Weight = 1.0, NoIndex = true)]
public string Content { get; set; }

[FtTagField("tags")]
public string Tags { get; set; }

[FtNumericField("views")]
public int Views { get; set; }
}

var repo = cli.FtDocumentRepository<TestDoc>();
repo.CreateIndex();

repo.Save(new TestDoc { Id = 1, Title = "test title1 word", Category = "class 1", Content = "test content 1 suffix", Tags = "user1,user2", Views = 101 });
repo.Save(new TestDoc { Id = 2, Title = "prefix test title2", Category = "class 2", Content = "test infix content 2", Tags = "user2,user3", Views = 201 });
repo.Save(new TestDoc { Id = 3, Title = "test title3 word", Category = "class 1", Content = "test word content 3", Tags = "user2,user5", Views = 301 });

repo.Delete(1, 2, 3);

repo.Save(new[]
{
new TestDoc { Id = 1, Title = "test title1 word", Category = "class 1", Content = "test content 1 suffix", Tags = "user1,user2", Views = 101 },
new TestDoc { Id = 2, Title = "prefix test title2", Category = "class 2", Content = "test infix content 2", Tags = "user2,user3", Views = 201 },
new TestDoc { Id = 3, Title = "test title3 word", Category = "class 1", Content = "test word content 3", Tags = "user2,user5", Views = 301 }
});

var list = repo.Search("*").InFields(a => new { a.Title }).ToList();
list = repo.Search("*").Return(a => new { a.Title, a.Tags }).ToList();
list = repo.Search("*").Return(a => new { tit1 = a.Title, tgs1 = a.Tags, a.Title, a.Tags }).ToList();

list = repo.Search(a => a.Title == "word").Filter(a => a.Views, 1, 1000).ToList();
list = repo.Search("word").ToList();
list = repo.Search("@title:word").ToList();
```
1 change: 1 addition & 0 deletions docs/guide/freescheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FreeScheduler 是利用 IdleBus 实现的轻量化定时任务调度,支持集
```csharp
static Scheduler scheduler = new FreeSchedulerBuilder()
.UseTimeZone(TimeSpan.FromHours(8)) //默认为UTC时间,国内可指定时区+8,任务将按本地时间执行
.OnExecuting(task =>
{
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] {task.Topic} 被执行");
Expand Down
Loading

0 comments on commit cd48a52

Please sign in to comment.