#if FANTASY_NET using System; using System.Collections.Generic; using System.Linq.Expressions; using Fantasy.Async; using Fantasy.Entitas; using MongoDB.Driver; // ReSharper disable InconsistentNaming #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. #pragma warning disable CS8625 namespace Fantasy.DataBase { /// /// 数据库设置助手 /// public static class DataBaseSetting { /// /// 初始化自定义委托,当设置了这个委托后,就不会自动创建MongoClient,需要自己在委托里创建MongoClient。 /// public static Func? MongoDBCustomInitialize; } /// /// MongoDB自定义连接参数 /// public sealed class DataBaseCustomConfig { /// /// 当前Scene /// public Scene Scene; /// /// 连接字符串 /// public string ConnectionString; /// /// 数据库名字 /// public string DBName; } /// /// 表示用于执行各种数据库操作的数据库接口。 /// public interface IDataBase : IDisposable { /// /// 获得当前数据的类型 /// public DataBaseType GetDataBaseType { get;} /// /// 获得对应数据的操作实例 /// /// 如MongoDB就是IMongoDatabase public object GetDataBaseInstance { get;} /// /// 初始化数据库连接。 /// IDataBase Initialize(Scene scene, string connectionString, string dbName); /// /// 在指定的集合中检索类型 的实体数量。 /// FTask Count(string collection = null) where T : Entity; /// /// 在指定的集合中检索满足给定筛选条件的类型 的实体数量。 /// FTask Count(Expression> filter, string collection = null) where T : Entity; /// /// 检查指定集合中是否存在类型 的实体。 /// FTask Exist(string collection = null) where T : Entity; /// /// 检查指定集合中是否存在满足给定筛选条件的类型 的实体。 /// FTask Exist(Expression> filter, string collection = null) where T : Entity; /// /// 从指定集合中检索指定 ID 的类型 的实体,不锁定。 /// FTask QueryNotLock(long id, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 从指定集合中检索指定 ID 的类型 的实体。 /// FTask Query(long id, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 按页查询满足给定筛选条件的类型 的实体数量和日期。 /// FTask<(int count, List dates)> QueryCountAndDatesByPage(Expression> filter, int pageIndex, int pageSize, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 按页查询满足给定筛选条件的类型 的实体数量和日期。 /// FTask<(int count, List dates)> QueryCountAndDatesByPage(Expression> filter, int pageIndex, int pageSize, string[] cols, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 分页查询指定集合中满足给定筛选条件的类型 的实体列表。 /// FTask> QueryByPage(Expression> filter, int pageIndex, int pageSize, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 分页查询指定集合中满足给定筛选条件的类型 的实体列表,仅返回指定列的数据。 /// FTask> QueryByPage(Expression> filter, int pageIndex, int pageSize, string[] cols, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 从指定集合中按页查询满足给定筛选条件的类型 的实体列表,按指定字段排序。 /// FTask> QueryByPageOrderBy(Expression> filter, int pageIndex, int pageSize, Expression> orderByExpression, bool isAsc = true, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 检索满足给定筛选条件的类型 的第一个实体,从指定集合中。 /// FTask First(Expression> filter, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 查询指定集合中满足给定 JSON 查询字符串的类型 的第一个实体,仅返回指定列的数据。 /// FTask First(string json, string[] cols, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 从指定集合中按页查询满足给定筛选条件的类型 的实体列表,按指定字段排序。 /// FTask> QueryOrderBy(Expression> filter, Expression> orderByExpression, bool isAsc = true, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 从指定集合中按页查询满足给定筛选条件的类型 的实体列表。 /// FTask> Query(Expression> filter, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 查询指定集合中满足给定筛选条件的类型 实体列表,仅返回指定字段的数据。 /// FTask> Query(Expression> filter, Expression>[] cols, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 查询指定 ID 的多个集合,将结果存储在给定的实体列表中。 /// FTask Query(long id, List collectionNames, List result, bool isDeserialize = false); /// /// 根据给定的 JSON 查询字符串查询指定集合中的类型 实体列表。 /// FTask> QueryJson(string json, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 根据给定的 JSON 查询字符串查询指定集合中的类型 实体列表,仅返回指定列的数据。 /// FTask> QueryJson(string json, string[] cols, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 根据给定的 JSON 查询字符串查询指定集合中的类型 实体列表,通过指定的任务 ID 进行标识。 /// FTask> QueryJson(long taskId, string json, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 查询指定集合中满足给定筛选条件的类型 实体列表,仅返回指定列的数据。 /// FTask> Query(Expression> filter, string[] cols, bool isDeserialize = false, string collection = null) where T : Entity; /// /// 保存类型 实体到指定集合中,如果集合不存在将自动创建。 /// FTask Save(T entity, string collection = null) where T : Entity, new(); /// /// 保存一组实体到数据库中,根据实体列表的 ID 进行区分和存储。 /// FTask Save(long id, List entities); /// /// 通过事务会话将类型 实体保存到指定集合中,如果集合不存在将自动创建。 /// FTask Save(object transactionSession, T entity, string collection = null) where T : Entity; /// /// 向指定集合中插入一个类型 实体,如果集合不存在将自动创建。 /// FTask Insert(T entity, string collection = null) where T : Entity, new(); /// /// 批量插入一组类型 实体到指定集合中,如果集合不存在将自动创建。 /// FTask InsertBatch(IEnumerable list, string collection = null) where T : Entity, new(); /// /// 通过事务会话,批量插入一组类型 实体到指定集合中,如果集合不存在将自动创建。 /// FTask InsertBatch(object transactionSession, IEnumerable list, string collection = null) where T : Entity, new(); /// /// 通过事务会话,根据指定的 ID 从数据库中删除指定类型 实体。 /// FTask Remove(object transactionSession, long id, string collection = null) where T : Entity, new(); /// /// 根据指定的 ID 从数据库中删除指定类型 实体。 /// FTask Remove(long id, string collection = null) where T : Entity, new(); /// /// 通过事务会话,根据给定的筛选条件从数据库中删除指定类型 实体。 /// FTask Remove(long coroutineLockQueueKey, object transactionSession, Expression> filter, string collection = null) where T : Entity, new(); /// /// 根据给定的筛选条件从数据库中删除指定类型 实体。 /// FTask Remove(long coroutineLockQueueKey, Expression> filter, string collection = null) where T : Entity, new(); /// /// 根据给定的筛选条件计算指定集合中类型 实体某个属性的总和。 /// FTask Sum(Expression> filter, Expression> sumExpression, string collection = null) where T : Entity; /// /// 在指定的集合中创建索引,以提高类型 实体的查询性能。 /// FTask CreateIndex(string collection, params object[] keys) where T : Entity; /// /// 在默认集合中创建索引,以提高类型 实体的查询性能。 /// FTask CreateIndex(params object[] keys) where T : Entity; /// /// 创建指定类型 的数据库,用于存储实体。 /// FTask CreateDB() where T : Entity; /// /// 根据指定类型创建数据库,用于存储实体。 /// FTask CreateDB(Type type); } } #endif