mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] TEngineServer
[+] TEngineServer
This commit is contained in:
45
Assets/GameScripts/DotNet/Core/DataBase/Base/IDateBase.cs
Normal file
45
Assets/GameScripts/DotNet/Core/DataBase/Base/IDateBase.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
#if TENGINE_NET
|
||||
using System.Linq.Expressions;
|
||||
#pragma warning disable CS8625
|
||||
|
||||
namespace TEngine.Core.DataBase;
|
||||
|
||||
public interface IDateBase
|
||||
{
|
||||
IDateBase Initialize(string connectionString, string dbName);
|
||||
FTask<long> Count<T>(string collection = null) where T : Entity;
|
||||
FTask<long> Count<T>(Expression<Func<T, bool>> filter, string collection = null) where T : Entity;
|
||||
FTask<bool> Exist<T>(string collection = null) where T : Entity;
|
||||
FTask<bool> Exist<T>(Expression<Func<T, bool>> filter, string collection = null) where T : Entity;
|
||||
FTask<T> Query<T>(long id, string collection = null) where T : Entity;
|
||||
FTask<(int count, List<T> dates)> QueryCountAndDatesByPage<T>(Expression<Func<T, bool>> filter, int pageIndex, int pageSize, string collection = null) where T : Entity;
|
||||
FTask<(int count, List<T> dates)> QueryCountAndDatesByPage<T>(Expression<Func<T, bool>> filter, int pageIndex, int pageSize, string[] cols, string collection = null) where T : Entity;
|
||||
FTask<List<T>> QueryByPage<T>(Expression<Func<T, bool>> filter, int pageIndex, int pageSize, string collection = null) where T : Entity;
|
||||
FTask<List<T>> QueryByPage<T>(Expression<Func<T, bool>> filter, int pageIndex, int pageSize, string[] cols, string collection = null) where T : Entity;
|
||||
FTask<List<T>> QueryByPageOrderBy<T>(Expression<Func<T, bool>> filter, int pageIndex, int pageSize, Expression<Func<T, object>> orderByExpression, bool isAsc = true, string collection = null) where T : Entity;
|
||||
FTask<T> First<T>(Expression<Func<T, bool>> filter, string collection = null) where T : Entity;
|
||||
FTask<T> First<T>(string json, string[] cols, string collection = null) where T : Entity;
|
||||
FTask<List<T>> QueryOrderBy<T>(Expression<Func<T, bool>> filter, Expression<Func<T, object>> orderByExpression, bool isAsc = true, string collection = null) where T : Entity;
|
||||
FTask<List<T>> Query<T>(Expression<Func<T, bool>> filter, string collection = null) where T : Entity;
|
||||
FTask Query(long id, List<string> collectionNames, List<Entity> result);
|
||||
FTask<List<T>> QueryJson<T>(string json, string collection = null) where T : Entity;
|
||||
FTask<List<T>> QueryJson<T>(string json, string[] cols, string collection = null) where T : Entity;
|
||||
FTask<List<T>> QueryJson<T>(long taskId, string json, string collection = null) where T : Entity;
|
||||
FTask<List<T>> Query<T>(Expression<Func<T, bool>> filter, string[] cols, string collection = null) where T : class;
|
||||
FTask Save<T>(T entity, string collection = null) where T : Entity, new();
|
||||
FTask Save(long id, List<Entity> entities);
|
||||
FTask Save<T>(object transactionSession, T entity, string collection = null) where T : Entity;
|
||||
FTask Insert<T>(T entity, string collection = null) where T : Entity, new();
|
||||
FTask InsertBatch<T>(IEnumerable<T> list, string collection = null) where T : Entity, new();
|
||||
FTask InsertBatch<T>(object transactionSession, IEnumerable<T> list, string collection = null) where T : Entity, new();
|
||||
FTask<long> Remove<T>(object transactionSession, long id, string collection = null) where T : Entity, new();
|
||||
FTask<long> Remove<T>(long id, string collection = null) where T : Entity, new();
|
||||
FTask<long> Remove<T>(long id,object transactionSession, Expression<Func<T, bool>> filter, string collection = null) where T : Entity, new();
|
||||
FTask<long> Remove<T>(long id, Expression<Func<T, bool>> filter, string collection = null) where T : Entity, new();
|
||||
FTask<long> Sum<T>(Expression<Func<T, bool>> filter, Expression<Func<T, object>> sumExpression, string collection = null) where T : Entity;
|
||||
FTask CreateIndex<T>(string collection, params object[] keys) where T : Entity;
|
||||
FTask CreateIndex<T>(params object[] keys) where T : Entity;
|
||||
FTask CreateDB<T>() where T : Entity;
|
||||
FTask CreateDB(Type type);
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 801a4f2fbf5d7944480423ade9d8a998
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
42
Assets/GameScripts/DotNet/Core/DataBase/Base/World.cs
Normal file
42
Assets/GameScripts/DotNet/Core/DataBase/Base/World.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#if TENGINE_NET
|
||||
namespace TEngine.Core.DataBase;
|
||||
|
||||
public sealed class World
|
||||
{
|
||||
public uint Id { get; private init; }
|
||||
public IDateBase DateBase { get; private init; }
|
||||
public WorldConfigInfo Config => ConfigTableManage.WorldConfigInfo(Id);
|
||||
private static readonly Dictionary<uint, World> Worlds = new();
|
||||
|
||||
public World(WorldConfigInfo worldConfigInfo)
|
||||
{
|
||||
Id = worldConfigInfo.Id;
|
||||
var dbType = worldConfigInfo.DbType.ToLower();
|
||||
|
||||
switch (dbType)
|
||||
{
|
||||
case "mongodb":
|
||||
{
|
||||
DateBase = new MongoDataBase();
|
||||
DateBase.Initialize(worldConfigInfo.DbConnection, worldConfigInfo.DbName);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Exception("No supported database");
|
||||
}
|
||||
}
|
||||
|
||||
public static World Create(uint id)
|
||||
{
|
||||
if (Worlds.TryGetValue(id, out var world))
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
var worldConfigInfo = ConfigTableManage.WorldConfigInfo(id);
|
||||
world = new World(worldConfigInfo);
|
||||
Worlds.Add(id, world);
|
||||
return world;
|
||||
}
|
||||
}
|
||||
#endif
|
11
Assets/GameScripts/DotNet/Core/DataBase/Base/World.cs.meta
Normal file
11
Assets/GameScripts/DotNet/Core/DataBase/Base/World.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e207b62400a4d2742945b50eb84f8233
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,12 @@
|
||||
#if TENGINE_NET
|
||||
namespace TEngine.Core.DataBase;
|
||||
|
||||
public class WorldConfigInfo
|
||||
{
|
||||
public uint Id;
|
||||
public string WorldName;
|
||||
public string DbConnection;
|
||||
public string DbName;
|
||||
public string DbType;
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c1d63a41ee591348a2aeab0a1ff5b2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user