修改代码生成数据库字符串连接
This commit is contained in:
parent
67e1343e24
commit
1375a1f61a
@ -30,7 +30,7 @@
|
||||
"SECRET": "XX"
|
||||
},
|
||||
"gen": {
|
||||
"conn": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;user=zr;pwd=abc;database={database};Trusted_Connection=SSPI",
|
||||
"conn": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;user=zr;pwd=abc;database=ZrAdmin;Trusted_Connection=SSPI",
|
||||
"dbType": 1, //MySql = 0, SqlServer = 1
|
||||
"autoPre": true, //自动去除表前缀
|
||||
"author": "zr",
|
||||
|
||||
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
@ -24,11 +25,14 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConfig(GenConstants.Gen_conn);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(GenConstants.Gen_conn_dbType, 0);
|
||||
connStr = connStr.Replace("{database}", dbName);
|
||||
if (string.IsNullOrEmpty(dbName))
|
||||
|
||||
if (!string.IsNullOrEmpty(dbName))
|
||||
{
|
||||
connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
|
||||
string replaceStr = GetValue(connStr, "database=", ";");
|
||||
|
||||
connStr = connStr.Replace(replaceStr, dbName);
|
||||
//connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
//dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
|
||||
}
|
||||
var db = new SqlSugarScope(new List<ConnectionConfig>()
|
||||
{
|
||||
@ -43,5 +47,18 @@ namespace ZR.CodeGenerator
|
||||
CodeDb = db;
|
||||
return db;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得字符串中开始和结束字符串中间得值
|
||||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <param name="s">开始</param>
|
||||
/// <param name="e">结束</param>
|
||||
/// <returns></returns>
|
||||
public static string GetValue(string str, string s, string e)
|
||||
{
|
||||
Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
|
||||
return rg.Match(str).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user