From de1405a8ada3105b56be077ba02c436ab1cf1660 Mon Sep 17 00:00:00 2001 From: Guilherme Muniz Santos Date: Tue, 25 Feb 2025 17:16:06 +0100 Subject: [PATCH] Server Value --- src/Firebase/ServerValue.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Firebase/ServerValue.cs diff --git a/src/Firebase/ServerValue.cs b/src/Firebase/ServerValue.cs new file mode 100644 index 0000000..e92e2dd --- /dev/null +++ b/src/Firebase/ServerValue.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; + +namespace Firebase.Database +{ + /// + /// Values that can be used to instruct the Firebase Database to take action based on server value + /// + public static class ServerValue + { + private const string SERVER_VALUE_KEY = ".sv"; + private const string TIME_STAMP_KEY = "timestamp"; + + /// + /// Increments or decreases a number in server side + /// e.g.: valueInFirebaseDatabase = 3 + /// Sending { "valueInFirebaseDatabase", ServerValue.Increment(-1) } + /// results in valueInFirebaseDatabase = 2 + /// + /// the amount you want to increment or decrease(negative values) + /// + public static Dictionary Increment(double value) + => new Dictionary { { SERVER_VALUE_KEY, new { increment = value } } }; + + /// + /// Saves the server time as unix timestamp at the moment of the request + /// + public static Dictionary TimeStamp + => new Dictionary { { SERVER_VALUE_KEY, TIME_STAMP_KEY } }; + } +}