The examples in this section demonstrate calling a Realm Function named sum
that takes two arguments, adds them, and returns the result:
exports = function(a, b) { return a + b;};
Note Authenticate First
You call Functions on a User object, so before calling any function, you must authenticate a user.
ImportantMake sure to sanitize client data to protect against code injection when using Functions.
To execute a function from the .NET SDK, use the Functions.CallAsync() method on the User
object, passing in the name of the function as the first parameter and the arguments as the remaining parameters:
var bsonValue = await user.Functions.CallAsync("sum", 2, 40);var sum = bsonValue.ToInt32();sum = await user.Functions.CallAsync<int>("sum", 2, 40);
Note
The CallAsync()
method returns a single BsonValue
object, which you can deserialize after calling the function or by using the the generic overload. Both of these approaches to deserialization are shown in the code above.
A BsonValue
object can hold a single primitive value (as shown in the example above), or hold a complete BSON document. If you have a class that maps to the returned object, you can deserialize to that class by using the generic overload. For example, the following code calls a function that returns an object from a collection of "RealmTasks". Since we know the shape of the returned object, we we can deserialize the BsonValue
to a class that we have created, and then we have access to the properties and methods on that object:
var item = await user.Functions.CallAsync<MyClass> ("getItem", "5f7f7638024a99f41a3c8de4");var name = item.Name;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4