Update mongodb

This commit is contained in:
sunkaixuan
2025-05-02 17:00:36 +08:00
parent e47c66aa58
commit e999988ec3
5 changed files with 5 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace MongoDb.Ado.data
{
public class DbDataReaderFactoryAsync
{
public readonly static Dictionary<string, IQueryHandlerAsync> Items = new Dictionary<string, IQueryHandlerAsync>(StringComparer.OrdinalIgnoreCase)
{
{ "find", new QueryFindHandlerAsync() },
{ "aggregate", new QueryFindHandlerAsync() },
};
public async Task<DbDataReader> HandleAsync(string operation, IMongoCollection<BsonDocument> collection, string json)
{
MongoDbMethodUtils.ValidateOperation(operation);
var doc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonValue>(json);
DbDataReaderFactoryAsync.Items.TryGetValue(operation, out var handler);
if (handler == null)
{
await ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection);
return new DataTable().CreateDataReader();
}
return await handler.HandlerAsync(collection, doc);
}
}
}