Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
IoTSharp
提交
1686f752
I
IoTSharp
项目概览
jobily
/
IoTSharp
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1686f752
编写于
9月 28, 2022
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix create table error : Sqlite 'table TelemetryData_202209" already exists'. #801
上级
ba2e917e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
153 addition
and
6 deletion
+153
-6
IoTSharp.Data/Shardings/GuessTableEnsureManager.cs
IoTSharp.Data/Shardings/GuessTableEnsureManager.cs
+56
-0
IoTSharp.Data/Shardings/PostgreSqlTableEnsureManager.cs
IoTSharp.Data/Shardings/PostgreSqlTableEnsureManager.cs
+31
-0
IoTSharp.Data/Shardings/SqliteTableEnsureManager.cs
IoTSharp.Data/Shardings/SqliteTableEnsureManager.cs
+34
-0
IoTSharp/Startup.cs
IoTSharp/Startup.cs
+32
-6
未找到文件。
IoTSharp.Data/Shardings/GuessTableEnsureManager.cs
0 → 100644
浏览文件 @
1686f752
using
System
;
using
Microsoft.EntityFrameworkCore
;
using
ShardingCore.Sharding.Abstractions
;
using
ShardingCore.TableExists.Abstractions
;
using
System.Collections.Generic
;
using
System.Data.Common
;
using
ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions
;
using
Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments
;
namespace
ShardingCore.TableExists
{
public
class
GuessTableEnsureManager
:
AbstractTableEnsureManager
{
private
readonly
EmptyTableEnsureManager
_tem_empyt
;
private
readonly
MySqlTableEnsureManager
_tem_mysql
;
private
readonly
SqliteTableEnsureManager
_tem_sqlite
;
private
readonly
PostgreSqlTableEnsureManager
_tem_pgsql
;
private
readonly
SqlServerTableEnsureManager
_tem_mssql
;
public
GuessTableEnsureManager
(
IRouteTailFactory
routeTailFactory
)
:
base
(
routeTailFactory
)
{
_tem_empyt
=
new
EmptyTableEnsureManager
();
_tem_mysql
=
new
MySqlTableEnsureManager
(
routeTailFactory
);
_tem_sqlite
=
new
SqliteTableEnsureManager
(
routeTailFactory
);
_tem_pgsql
=
new
PostgreSqlTableEnsureManager
(
routeTailFactory
);
_tem_mssql
=
new
SqlServerTableEnsureManager
(
routeTailFactory
);
}
public
override
ISet
<
string
>
DoGetExistTables
(
DbConnection
connection
,
string
dataSourceName
)
{
ISet
<
string
>
result
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
);
var
dbctypename
=
connection
.
GetType
().
FullName
;
switch
(
dbctypename
)
{
case
"Npgsql.NpgsqlConnection"
:
result
=
_tem_pgsql
.
DoGetExistTables
(
connection
,
dataSourceName
);
break
;
case
"System.Data.Sqlite.SqliteConnection"
:
case
"Microsoft.Data.Sqlite.SqliteConnection"
:
result
=
_tem_sqlite
.
DoGetExistTables
(
connection
,
dataSourceName
);
break
;
case
"MySqlConnector.MySqlConnection"
:
result
=
_tem_mysql
.
DoGetExistTables
(
connection
,
dataSourceName
);
break
;
case
"Microsoft.Data.SqlClient.SqlConnection"
:
case
"System.Data.SqlClient.SqlConnection"
:
result
=
_tem_mssql
.
DoGetExistTables
(
connection
,
dataSourceName
);
break
;
default
:
break
;
}
return
result
;
}
}
}
IoTSharp.Data/Shardings/PostgreSqlTableEnsureManager.cs
0 → 100644
浏览文件 @
1686f752
using
System
;
using
ShardingCore.TableExists.Abstractions
;
using
System.Collections.Generic
;
using
System.Data.Common
;
using
ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions
;
namespace
ShardingCore.TableExists
{
public
class
PostgreSqlTableEnsureManager
:
AbstractTableEnsureManager
{
public
PostgreSqlTableEnsureManager
(
IRouteTailFactory
routeTailFactory
)
:
base
(
routeTailFactory
)
{
}
private
const
string
Tables
=
"Tables"
;
private
const
string
TABLE_NAME
=
"TABLE_NAME"
;
public
override
ISet
<
string
>
DoGetExistTables
(
DbConnection
connection
,
string
dataSourceName
)
{
ISet
<
string
>
result
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
);
using
(
var
dataTable
=
connection
.
GetSchema
(
Tables
))
{
for
(
int
i
=
0
;
i
<
dataTable
.
Rows
.
Count
;
i
++)
{
result
.
Add
(
dataTable
.
Rows
[
i
][
TABLE_NAME
].
ToString
());
}
}
return
result
;
}
}
}
IoTSharp.Data/Shardings/SqliteTableEnsureManager.cs
0 → 100644
浏览文件 @
1686f752
using
System
;
using
ShardingCore.TableExists.Abstractions
;
using
System.Collections.Generic
;
using
System.Data.Common
;
using
ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions
;
namespace
ShardingCore.TableExists
{
public
class
SqliteTableEnsureManager
:
AbstractTableEnsureManager
{
public
SqliteTableEnsureManager
(
IRouteTailFactory
routeTailFactory
)
:
base
(
routeTailFactory
)
{
}
public
override
ISet
<
string
>
DoGetExistTables
(
DbConnection
connection
,
string
dataSourceName
)
{
ISet
<
string
>
result
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
);
using
(
var
query
=
connection
.
CreateCommand
())
{
query
.
CommandText
=
"SELECT tbl_name FROM sqlite_master;"
;
using
(
var
reader
=
query
.
ExecuteReader
())
{
while
(
reader
.
Read
())
{
var
str
=
(
string
)
reader
[
"tbl_name"
];
result
.
Add
(
str
);
}
}
}
return
result
;
}
}
}
IoTSharp/Startup.cs
浏览文件 @
1686f752
...
...
@@ -40,6 +40,8 @@ using IoTSharp.EventBus.Shashlik;
using
Microsoft.EntityFrameworkCore
;
using
ShardingCore
;
using
Storage.Net
;
using
ShardingCore.TableExists.Abstractions
;
using
ShardingCore.TableExists
;
namespace
IoTSharp
{
...
...
@@ -223,7 +225,8 @@ namespace IoTSharp
case
TelemetryStorage
.
Sharding
:
ShardingByDateMode
settingsShardingByDateMode
=
settings
.
ShardingByDateMode
;
var
sbt
=
DateTime
.
Now
.
Subtract
(
settings
.
ShardingBeginTime
);
services
.
AddShardingDbContext
<
ShardingDbContext
>().
UseRouteConfig
(
o
=>
var
_sharding
=
services
.
AddShardingDbContext
<
ShardingDbContext
>();
_sharding
.
UseRouteConfig
(
o
=>
{
switch
(
settingsShardingByDateMode
)
{
...
...
@@ -237,7 +240,7 @@ namespace IoTSharp
break
;
case
ShardingByDateMode
.
PerDay
:
if
(
sbt
.
TotalDays
<
1
)
throw
new
ArgumentException
(
$"按日分表时间至少大于当前时间一天。"
);
o
.
AddShardingTableRoute
<
TelemetryDataDayRoute
>();
o
.
AddShardingTableRoute
<
TelemetryDataDayRoute
>();
break
;
case
ShardingByDateMode
.
PerMonth
:
if
(
sbt
.
TotalDays
<
DateTime
.
Now
.
Subtract
(
DateTime
.
Now
.
Date
.
AddDays
(-
DateTime
.
Now
.
Day
)).
TotalDays
)
throw
new
ArgumentException
(
$"按月分表时间至少大于当前时间一个月。"
);
...
...
@@ -249,11 +252,12 @@ namespace IoTSharp
break
;
default
:
throw
new
InvalidOperationException
(
$"unknown sharding mode:
{
settingsShardingByDateMode
}
"
);
}
}).
UseConfig
(
o
=>
});
_sharding
.
UseConfig
(
o
=>
{
o
.
ThrowIfQueryRouteNotMatch
=
false
;
o
.
UseShellDbContextConfigure
(
builder
=>
builder
.
UseQueryTrackingBehavior
(
QueryTrackingBehavior
.
NoTracking
));
o
.
AddDefaultDataSource
(
"ds0"
,
Configuration
.
GetConnectionString
(
"TelemetryStorage"
));
o
.
UseShellDbContextConfigure
(
builder
=>
builder
.
UseQueryTrackingBehavior
(
QueryTrackingBehavior
.
NoTracking
));
o
.
AddDefaultDataSource
(
"ds0"
,
Configuration
.
GetConnectionString
(
"TelemetryStorage"
));
switch
(
settings
.
DataBase
)
{
case
DataBaseType
.
MySql
:
...
...
@@ -277,7 +281,29 @@ namespace IoTSharp
break
;
}
}).
AddShardingCore
();
});
_sharding
.
AddShardingCore
();
switch
(
settings
.
DataBase
)
{
case
DataBaseType
.
MySql
:
_sharding
.
ReplaceService
<
ITableEnsureManager
,
MySqlTableEnsureManager
>();
break
;
case
DataBaseType
.
SqlServer
:
_sharding
.
ReplaceService
<
ITableEnsureManager
,
SqlServerTableEnsureManager
>();
break
;
case
DataBaseType
.
Oracle
:
break
;
case
DataBaseType
.
Sqlite
:
_sharding
.
ReplaceService
<
ITableEnsureManager
,
SqliteTableEnsureManager
>();
break
;
case
DataBaseType
.
PostgreSql
:
_sharding
.
ReplaceService
<
ITableEnsureManager
,
GuessTableEnsureManager
>();
break
;
default
:
break
;
}
services
.
AddSingleton
<
IStorage
,
ShardingStorage
>();
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录