Skip to content

Server Value #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Firebase/ServerValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;

namespace Firebase.Database
{
/// <summary>
/// Values that can be used to instruct the Firebase Database to take action based on server value
/// </summary>
public static class ServerValue
{
private const string SERVER_VALUE_KEY = ".sv";
private const string TIME_STAMP_KEY = "timestamp";

/// <summary>
/// Increments or decreases a number in server side
/// e.g.: valueInFirebaseDatabase = 3
/// Sending { "valueInFirebaseDatabase", ServerValue.Increment(-1) }
/// results in valueInFirebaseDatabase = 2
/// </summary>
/// <param name="value">the amount you want to increment or decrease(negative values)</param>
/// <returns></returns>
public static Dictionary<string, object> Increment(double value)
=> new Dictionary<string, object> { { SERVER_VALUE_KEY, new { increment = value } } };

/// <summary>
/// Saves the server time as unix timestamp at the moment of the request
/// </summary>
public static Dictionary<string, object> TimeStamp
=> new Dictionary<string, object> { { SERVER_VALUE_KEY, TIME_STAMP_KEY } };
}
}