SqlSugar/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/ExecuteHandlerFactory.cs
2025-05-02 16:55:48 +08:00

37 lines
1.3 KiB
C#

using MongoDb.Ado.data;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace MongoDb.Ado.data
{
public class ExecuteHandlerFactoryAsync
{
public readonly static Dictionary<string, IMongoOperationHandlerAsync> Items = new Dictionary<string, IMongoOperationHandlerAsync>(StringComparer.OrdinalIgnoreCase)
{
{ "insert", new InsertHandlerAsync() },
{ "insertmany", new InsertManyHandlerAsync() },
{ "update", new UpdateHandlerAsync() },
{ "updatemany", new UpdateManyHandlerAsync() },
{ "delete", new DeleteHandlerAsync() },
{ "deletemany", new DeleteManyHandlerAsync() },
{ "find", new NonFindHandlerAsync() }
};
public static Task<int> HandlerAsync(string operation, string json, IMongoCollection<BsonDocument> collection)
{
var handlers = ExecuteHandlerFactoryAsync.Items;
if (!handlers.TryGetValue(operation, out var handler))
throw new NotSupportedException($"不支持的操作类型: {operation}");
handler.operation = operation;
return handler.HandleAsync(collection, json);
}
}
}