feat: Client 增加同时操作多种类型数据库示例
This commit is contained in:
parent
5ade081cf2
commit
73ac43e97f
|
@ -1,4 +1,7 @@
|
||||||
using PetaPoco;
|
using Bootstrap.Security.Mvc;
|
||||||
|
using Longbow.Data;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using PetaPoco;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
@ -21,5 +24,30 @@ namespace Bootstrap.Client.DataAccess
|
||||||
db.ExceptionThrown += (sender, args) => args.Exception.Log(new NameValueCollection() { ["LastCmd"] = db.LastCommand });
|
db.ExceptionThrown += (sender, args) => args.Exception.Log(new NameValueCollection() { ["LastCmd"] = db.LastCommand });
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建 Sqlite 类型的 IDatabase 实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectionName">配置文件中配置的数据库连接字符串名称</param>
|
||||||
|
/// <param name="keepAlive">是否保持连接,默认为 false</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IDatabase CreateSqlite(string? connectionName = "client", bool keepAlive = false)
|
||||||
|
{
|
||||||
|
// 此方法为演示同时连接不同的数据库操作
|
||||||
|
|
||||||
|
// 此处注释为获取连接字符串的不同方法
|
||||||
|
//var conn = Bootstrap.Security.Mvc.BootstrapAppContext.Configuration["ConnectionStrings:client"];
|
||||||
|
//var conn = Bootstrap.Security.Mvc.BootstrapAppContext.Configuration.GetSection("ConnectionStrings").GetValue("client", "");
|
||||||
|
|
||||||
|
var conn = BootstrapAppContext.Configuration.GetConnectionString(connectionName);
|
||||||
|
var db = Longbow.Data.DbManager.Create(new DatabaseOption()
|
||||||
|
{
|
||||||
|
ProviderName = DatabaseProviderType.SQLite,
|
||||||
|
ConnectionString = conn,
|
||||||
|
KeepAlive = keepAlive
|
||||||
|
});
|
||||||
|
db.ExceptionThrown += (sender, args) => args.Exception.Log(new NameValueCollection() { ["LastCmd"] = db.LastCommand });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
"MaxFileCount": 1
|
"MaxFileCount": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"AllowOrigins": "http://localhost:50852",
|
||||||
|
"SimulateUserName": "Admin",
|
||||||
|
"BootstrapAdminAuthenticationOptions": {
|
||||||
|
"AuthHost": "http://localhost:50852",
|
||||||
|
"KeyPath": "..\\..\\admin\\keys"
|
||||||
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa",
|
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa",
|
||||||
"client": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
|
"client": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
|
||||||
|
@ -48,11 +54,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"SimulateUserName": "Admin",
|
|
||||||
"BootstrapAdminAuthenticationOptions": {
|
|
||||||
"AuthHost": "http://localhost:50852",
|
|
||||||
"KeyPath": "..\\..\\admin\\keys"
|
|
||||||
},
|
|
||||||
"SmtpClient": {
|
"SmtpClient": {
|
||||||
"Host": "smtp.163.com",
|
"Host": "smtp.163.com",
|
||||||
"Port": 587,
|
"Port": 587,
|
||||||
|
@ -61,7 +62,6 @@
|
||||||
"From": "honeywell_mes@163.com",
|
"From": "honeywell_mes@163.com",
|
||||||
"To": "argo@163.com"
|
"To": "argo@163.com"
|
||||||
},
|
},
|
||||||
"AllowOrigins": "http://localhost:50852",
|
|
||||||
"LongbowCache": {
|
"LongbowCache": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"CacheItems": [
|
"CacheItems": [
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa",
|
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa",
|
||||||
"client": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
|
"client": "Data Source=Client.db;"
|
||||||
},
|
},
|
||||||
"DB": [
|
"DB": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue