public static T GetOne <T>(DBREQUESTTYPE type, Expression <Func <T, bool> > expression) where T : IQueryResult, new() { var serializer = new ExpressionSerializer(new BinarySerializer()); byte[] query = serializer.SerializeBinary(expression); ByteRef payload = new ByteRef(2 + query.Length); payload.Set <byte>(0, (byte)type); payload.Set <byte>(1, (byte)DBRESULTTYPE.GETONE); payload.Set <byte[]>(2, query); ByteRef queryResult = new ByteRef(SendQuery(payload.Get())); if (queryResult.Length == 1 || (DBRESPONSETYPE)queryResult.GetByte(0) == DBRESPONSETYPE.FAILURE || (queryResult.Length == 2 && queryResult.GetByte(1) == 0) || (queryResult.Length >= 5 && queryResult.GetUInt32(1) == 0)) { return(default(T)); } T result = Deserialize <T>(queryResult.Get().Skip(5).ToArray()); return(result); }
public static long UpdateMany <T>(DBREQUESTTYPE type, Expression <Func <T, bool> > expression, Dictionary <string, object> update) { long updated = 0; var serializer = new ExpressionSerializer(new BinarySerializer()); byte[] serializedFilter = serializer.SerializeBinary(expression); byte[] serializedUpdate = Serialize(update); ByteRef payload = new ByteRef(2 + 4 + serializedFilter.Length + 4 + serializedUpdate.Length); payload.Set <byte>(0, type); payload.Set <byte>(1, (byte)DBRESULTTYPE.UPDATEMANY); payload.Set <int>(2, serializedFilter.Length); payload.Set <byte[]>(6, serializedFilter); payload.Set <int>(6 + serializedFilter.Length, serializedUpdate.Length); payload.Set <byte[]>(6 + serializedFilter.Length + 4, serializedUpdate); ByteRef queryResult = new ByteRef(SendQuery(payload.Get())); if (queryResult.Length >= 5 || (DBRESPONSETYPE)queryResult.GetByte(0) != DBRESPONSETYPE.FAILURE) { updated = queryResult.GetUInt32(1); } return(updated); }
public static (Type, string) GetType(DBREQUESTTYPE requestType) { switch (requestType) { case DBREQUESTTYPE.ACCOUNT: return(typeof(Account), "accounts"); case DBREQUESTTYPE.PLAYER: return(typeof(Player), "players"); case DBREQUESTTYPE.ACTIVESESSION: return(typeof(ActiveSession), "activesessions"); } return(null, ""); }
public static uint GetMaxID(DBREQUESTTYPE type) { uint maxID = 0; ByteRef payload = new ByteRef(2); payload.Set <byte>(0, (byte)type); payload.Set <byte>(1, (byte)DBRESULTTYPE.GETMAXID); ByteRef queryResult = new ByteRef(SendQuery(payload.Get())); if (queryResult.Length >= 5 && (DBRESPONSETYPE)queryResult.GetByte(0) != DBRESPONSETYPE.FAILURE) { maxID = queryResult.GetUInt32(1); } return(maxID); }
public static bool InsertMany <T>(DBREQUESTTYPE type, List <T> obj) { byte[] serializedObj = Serialize(obj); ByteRef payload = new ByteRef(2 + serializedObj.Length); payload.Set <byte>(0, type); payload.Set <byte>(1, (byte)DBRESULTTYPE.INSERTMANY); payload.Set <byte[]>(2, serializedObj); byte[] queryResult = SendQuery(payload.Get()); if (queryResult.Length == 1 || (DBRESPONSETYPE)queryResult[0] == DBRESPONSETYPE.FAILURE) { return(false); } return(true); }
public static long DeleteMany <T>(DBREQUESTTYPE type, Expression <Func <T, bool> > expression) { long deleted = 0; var serializer = new ExpressionSerializer(new BinarySerializer()); byte[] query = serializer.SerializeBinary(expression); ByteRef payload = new ByteRef(2 + query.Length); payload.Set <byte>(0, (byte)type); payload.Set <byte>(1, (byte)DBRESULTTYPE.DELETEMANY); payload.Set <byte[]>(2, query); ByteRef queryResult = new ByteRef(SendQuery(payload.Get())); if (queryResult.Length >= 5 || (DBRESPONSETYPE)queryResult.GetByte(0) != DBRESPONSETYPE.FAILURE) { deleted = queryResult.GetUInt32(1); } return(deleted); }