From c957d157c233d74f378d4838dc3904ec067c2455 Mon Sep 17 00:00:00 2001
From: dailyccc <963922242@qq.com>
Date: Wed, 22 Feb 2023 13:34:50 +0800
Subject: [PATCH 1/2] =?UTF-8?q?-=20QuestDb=20RestAPI=20CSV=E5=AF=BC?=
=?UTF-8?q?=E5=85=A5=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs b/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs
index 617963c9..82afdb18 100644
--- a/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs
+++ b/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs
@@ -144,7 +144,7 @@ public static partial class QuestDbGlobalExtensions
{
try
{
- // File.Delete(filePath);
+ File.Delete(filePath);
}
catch
{
From eadb5a47477a2f58062e5b6a1a457ed2297cea13 Mon Sep 17 00:00:00 2001
From: dailyccc <963922242@qq.com>
Date: Wed, 22 Feb 2023 13:44:02 +0800
Subject: [PATCH 2/2] =?UTF-8?q?-=20=E8=A7=A3=E5=86=B3QuestDb=20BulkCopy?=
=?UTF-8?q?=E5=90=8ECSV=E6=96=87=E4=BB=B6=E6=9C=AA=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../QuestDbGlobalExtensions.cs | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs b/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs
index 82afdb18..74fd73a7 100644
--- a/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs
+++ b/Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs
@@ -69,6 +69,7 @@ public static partial class QuestDbGlobalExtensions
///
public static async Task ExecuteBulkCopyAsync(this IInsert that) where T : class
{
+ //思路:通过提供的RestAPI imp,实现快速复制
if (string.IsNullOrWhiteSpace(RestAPIExtension.BaseUrl))
{
throw new Exception("BulkCopy功能需要启用RestAPI,启用方式:new FreeSqlBuilder().UseQuestDbRestAPI(\"localhost:9000\", \"username\", \"password\")");
@@ -104,6 +105,7 @@ public static partial class QuestDbGlobalExtensions
}
});
var schema = JsonConvert.SerializeObject(list);
+ //写入CSV文件
using (var writer = new StreamWriter(filePath))
using (var csv = new CsvWriter(writer, CultureInfo.CurrentCulture))
{
@@ -146,9 +148,7 @@ public static partial class QuestDbGlobalExtensions
{
File.Delete(filePath);
}
- catch
- {
- }
+ catch { }
}
return result;
@@ -197,7 +197,7 @@ public static class SampleByExtension
{
var _unit = Enum.GetName(typeof(SampleUnits), unit);
IsExistence.Value = true;
- var samoleByTemple = $"{Environment.NewLine}SAMPLE BY {{0}}{{1}}{Environment.NewLine}";
+ var samoleByTemple = $"{Environment.NewLine}SAMPLE BY {{0}}{{1}} ";
SamoleByString.Value = string.Format(samoleByTemple, time.ToString(), _unit);
return select;
}
@@ -234,11 +234,11 @@ public static class LatestOnExtension
public static ISelect LatestOn(this ISelect select, Expression> timestamp,
Expression> partition)
{
- Provider(timestamp, partition);
+ InternelImpl(timestamp, partition);
return select;
}
- private static void Provider(Expression> timestamp,
+ private static void InternelImpl(Expression> timestamp,
Expression> partition)
{
IsExistence.Value = true;
@@ -264,7 +264,7 @@ public static class LatestOnExtension
Expression> timestamp,
Expression> partition) where T2 : class
{
- Provider(timestamp, partition);
+ InternelImpl(timestamp, partition);
return select;
}
@@ -281,7 +281,7 @@ public static class LatestOnExtension
Expression> timestamp,
Expression> partition) where T2 : class where T3 : class
{
- Provider(timestamp, partition);
+ InternelImpl(timestamp, partition);
return select;
}
@@ -298,7 +298,7 @@ public static class LatestOnExtension
Expression> timestamp,
Expression> partition) where T2 : class where T3 : class where T4 : class
{
- Provider(timestamp, partition);
+ InternelImpl(timestamp, partition);
return select;
}
}
@@ -310,6 +310,7 @@ public static class RestAPIExtension
internal static async Task ExecAsync(string sql)
{
+ //HTTP GET 执行SQL
var result = string.Empty;
var client = QuestDbContainer.GetService().CreateClient();
var url = $"{BaseUrl}/exec?query={HttpUtility.UrlEncode(sql)}";
@@ -317,7 +318,6 @@ public static class RestAPIExtension
client.DefaultRequestHeaders.Add("Authorization", authorization);
var httpResponseMessage = await client.GetAsync(url);
result = await httpResponseMessage.Content.ReadAsStringAsync();
-
return result;
}
@@ -330,11 +330,13 @@ public static class RestAPIExtension
if (!BaseUrl.ToLower().StartsWith("http"))
BaseUrl = $"http://{BaseUrl}";
+ //生成TOKEN
if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
{
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"));
authorization = $"Basic {base64}";
}
+ //RESTAPI需要无参数
buider.UseNoneCommandParameter(true);
return buider;
}