Merge pull request #1433 from d4ilys/master

修复及优化QuestDb RestAPI一些问题
This commit is contained in:
2881099 2023-02-22 13:33:30 +08:00 committed by GitHub
commit 6843beeabe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 10 deletions

View File

@ -46,7 +46,7 @@ namespace FreeSql.QuestDb.Curd
{ {
if (execAsync.Contains("401")) if (execAsync.Contains("401"))
{ {
throw new Exception("请确认QuestDb设置的RestAPI账号是否正确."); throw new Exception("请确认new FreeSqlBuilder().UseQuestDbRestAPI()中设置的用户名密码是否正确.");
} }
} }
var ddl = resultHash["ddl"]?.ToString(); var ddl = resultHash["ddl"]?.ToString();

View File

@ -33,7 +33,6 @@ namespace FreeSql.QuestDb.Curd
private int InternelExecuteAffrows() private int InternelExecuteAffrows()
{ {
//如果设置了RestAPI的Url则走HTTP
var sql = ToSql(); var sql = ToSql();
var execAsync = RestAPIExtension.ExecAsync(sql).GetAwaiter().GetResult(); var execAsync = RestAPIExtension.ExecAsync(sql).GetAwaiter().GetResult();
var resultHash = new Hashtable(); var resultHash = new Hashtable();
@ -45,7 +44,7 @@ namespace FreeSql.QuestDb.Curd
{ {
if (execAsync.Contains("401")) if (execAsync.Contains("401"))
{ {
throw new Exception("请确认QuestDb设置的RestAPI账号是否正确."); throw new Exception("请确认new FreeSqlBuilder().UseQuestDbRestAPI()中设置的用户名密码是否正确.");
} }
} }
var ddl = resultHash["ddl"]?.ToString(); var ddl = resultHash["ddl"]?.ToString();
@ -55,6 +54,7 @@ namespace FreeSql.QuestDb.Curd
public override int ExecuteAffrows() public override int ExecuteAffrows()
{ {
//如果设置了RestAPI中Url则走HTTP
if (string.IsNullOrWhiteSpace(RestAPIExtension.BaseUrl)) if (string.IsNullOrWhiteSpace(RestAPIExtension.BaseUrl))
{ {
return base.SplitExecuteAffrows(_batchRowsLimit > 0 ? _batchRowsLimit : 500, return base.SplitExecuteAffrows(_batchRowsLimit > 0 ? _batchRowsLimit : 500,

View File

@ -7,8 +7,9 @@ namespace FreeSql.Provider.QuestDb
{ {
internal class QuestDbContainer internal class QuestDbContainer
{ {
//作用于HttpClientFatory
private static IServiceCollection Services; private static IServiceCollection Services;
public static IServiceProvider ServiceProvider { get; private set; } internal static IServiceProvider ServiceProvider { get; private set; }
internal static void Initialize(Action<IServiceCollection> service) internal static void Initialize(Action<IServiceCollection> service)
{ {

View File

@ -55,8 +55,6 @@ public static partial class QuestDbGlobalExtensions
lines.Add(line); lines.Add(line);
line = sr.ReadLine(); line = sr.ReadLine();
} }
;
} }
} }
@ -71,6 +69,10 @@ public static partial class QuestDbGlobalExtensions
/// <returns></returns> /// <returns></returns>
public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) where T : class public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) where T : class
{ {
if (string.IsNullOrWhiteSpace(RestAPIExtension.BaseUrl))
{
throw new Exception("BulkCopy功能需要启用RestAPI启用方式new FreeSqlBuilder().UseQuestDbRestAPI(\"localhost:9000\", \"username\", \"password\")");
}
var result = 0; var result = 0;
var fileName = $"{Guid.NewGuid()}.csv"; var fileName = $"{Guid.NewGuid()}.csv";
var filePath = Path.Combine(AppContext.BaseDirectory, fileName); var filePath = Path.Combine(AppContext.BaseDirectory, fileName);
@ -89,7 +91,7 @@ public static partial class QuestDbGlobalExtensions
{ {
{ "name", d.Name }, { "name", d.Name },
{ "type", d.DbTypeText }, { "type", d.DbTypeText },
{ "pattern", "yyyy/M/dd HH:mm:ss" } { "pattern", "yyyy/M/d H:mm:ss" }
}); });
} }
else else
@ -136,14 +138,13 @@ public static partial class QuestDbGlobalExtensions
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); throw e;
throw;
} }
finally finally
{ {
try try
{ {
File.Delete(filePath); // File.Delete(filePath);
} }
catch catch
{ {