mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update QuestDb
This commit is contained in:
parent
e7be0ce07e
commit
4e2057546c
27
Src/Asp.NetCore2/QuestDbTest/Demo/DemoL_BulkCopy.cs
Normal file
27
Src/Asp.NetCore2/QuestDbTest/Demo/DemoL_BulkCopy.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
internal class DemoL_BulkCopy
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.QuestDB,
|
||||||
|
ConnectionString = Config.ConnectionString3,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true
|
||||||
|
});
|
||||||
|
|
||||||
|
var list=db.Queryable<Order>().Take(2).ToList();
|
||||||
|
var i=db.RestApi().BulkCopy(list);
|
||||||
|
var i2 = db.RestApi().ExecuteCommand("select 1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
//Demo
|
//Demo
|
||||||
Demo0_SqlSugarClient.Init();
|
Demo0_SqlSugarClient.Init();
|
||||||
|
DemoL_BulkCopy.Init();
|
||||||
Demo1_Queryable.Init();
|
Demo1_Queryable.Init();
|
||||||
Demo2_Updateable.Init();
|
Demo2_Updateable.Init();
|
||||||
Demo3_Insertable.Init();
|
Demo3_Insertable.Init();
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SqlSugar.QuestDb.RestApi\SqlSugar.QuestDb.RestAPI.csproj" />
|
||||||
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" />
|
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -9,11 +9,35 @@ using System.Threading.Tasks;
|
|||||||
using System.Web;
|
using System.Web;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
internal class QuestDbRestAPHelper
|
internal class QuestDbRestAPHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 绑定RestAPI需要的信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder"></param>
|
||||||
|
/// <param name="host"></param>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
public static void SetRestApiInfo(DbConnectionStringBuilder builder, ref string host, ref string username, ref string password)
|
||||||
|
{
|
||||||
|
if (builder.TryGetValue("Host", out object hostValue))
|
||||||
|
{
|
||||||
|
host = Convert.ToString(hostValue);
|
||||||
|
}
|
||||||
|
if (builder.TryGetValue("Username", out object usernameValue))
|
||||||
|
{
|
||||||
|
username = Convert.ToString(usernameValue);
|
||||||
|
}
|
||||||
|
if (builder.TryGetValue("Password", out object passwordValue))
|
||||||
|
{
|
||||||
|
password = Convert.ToString(passwordValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 逐行读取,包含空行
|
/// 逐行读取,包含空行
|
||||||
@ -35,11 +59,8 @@ namespace SqlSugar
|
|||||||
line = sr.ReadLine();
|
line = sr.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,20 @@ using Newtonsoft.Json;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// QuestDb RestAPI
|
||||||
|
/// </summary>
|
||||||
public class QuestDbRestAPI
|
public class QuestDbRestAPI
|
||||||
{
|
{
|
||||||
internal string url = string.Empty;
|
internal string url = string.Empty;
|
||||||
@ -20,26 +24,21 @@ namespace SqlSugar
|
|||||||
ISqlSugarClient db;
|
ISqlSugarClient db;
|
||||||
public QuestDbRestAPI(ISqlSugarClient db)
|
public QuestDbRestAPI(ISqlSugarClient db)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var builder = new DbConnectionStringBuilder();
|
||||||
|
builder.ConnectionString = db.CurrentConnectionConfig.ConnectionString;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
string host = "";
|
string host = String.Empty;
|
||||||
string username = "";
|
string username = String.Empty;
|
||||||
string password = "";
|
string password = String.Empty;
|
||||||
|
QuestDbRestAPHelper.SetRestApiInfo(builder, ref host, ref username, ref password);
|
||||||
url = host;
|
BindHost(host, username, password);
|
||||||
if (url.EndsWith("/"))
|
|
||||||
url = url.Remove(url.Length - 1);
|
|
||||||
|
|
||||||
if (!url.ToLower().StartsWith("http"))
|
|
||||||
url = $"http://{url}";
|
|
||||||
//生成TOKEN
|
|
||||||
if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
|
|
||||||
{
|
|
||||||
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"));
|
|
||||||
authorization = $"Basic {base64}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL异步
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<string> ExecuteCommandAsync(string sql)
|
public async Task<string> ExecuteCommandAsync(string sql)
|
||||||
{
|
{
|
||||||
//HTTP GET 执行SQL
|
//HTTP GET 执行SQL
|
||||||
@ -52,13 +51,17 @@ namespace SqlSugar
|
|||||||
result = await httpResponseMessage.Content.ReadAsStringAsync();
|
result = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public string ExecuteCommand(string sql)
|
public string ExecuteCommand(string sql)
|
||||||
{
|
{
|
||||||
return ExecuteCommandAsync(sql).GetAwaiter().GetResult();
|
return ExecuteCommandAsync(sql).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 批量快速插入
|
/// 批量快速插入异步
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="that"></param>
|
/// <param name="that"></param>
|
||||||
@ -161,6 +164,21 @@ namespace SqlSugar
|
|||||||
public int BulkCopy<T>(List<T> insertList, string dateFormat = "yyyy/M/d H:mm:ss") where T : class
|
public int BulkCopy<T>(List<T> insertList, string dateFormat = "yyyy/M/d H:mm:ss") where T : class
|
||||||
{
|
{
|
||||||
return BulkCopyAsync(insertList, dateFormat).GetAwaiter().GetResult();
|
return BulkCopyAsync(insertList, dateFormat).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
private void BindHost(string host, string username, string password)
|
||||||
|
{
|
||||||
|
url = host + ":9000";
|
||||||
|
if (url.EndsWith("/"))
|
||||||
|
url = url.Remove(url.Length - 1);
|
||||||
|
|
||||||
|
if (!url.ToLower().StartsWith("http"))
|
||||||
|
url = $"http://{url}";
|
||||||
|
//生成TOKEN
|
||||||
|
if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
|
||||||
|
{
|
||||||
|
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"));
|
||||||
|
authorization = $"Basic {base64}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public static class ISqlSugarClientExtensions
|
public static class QuestDbSqlSugarClientExtensions
|
||||||
{
|
{
|
||||||
public static QuestDbRestAPI RestApi(this ISqlSugarClient db)
|
public static QuestDbRestAPI RestApi(this ISqlSugarClient db)
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user