Call a function

Creating and updating a function requires:

Problem

You need to execute a function within the current database.

Solution

Use the Call function:

try
{
    Value result = await client.Query(
        Call(
            Function("create_post"),
            Arr("First Post Title", "This is my first blog post!")
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "300221738176741888", collection = RefV(id = "posts", collection = RefV(id = "collections"))),ts: LongV(1622572610930000),data: ObjectV(title: StringV(First Post Title),body: StringV(This is my first blog post!)))
result, err := client.Query(
	f.Call(
		f.Function("create_post"),
		f.Arr{"First Post Title", "This is my first blog post!"},
	))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:map[body:This is my first blog post! title:First Post Title] ref:{300221752288477696 0xc00009b8f0 0xc00009b8f0 <nil>} ts:1622572624380000]
System.out.println(
    client.query(
        Call(
            Function("create_post"),
            Arr(
                Value("First Post Title"),
                Value("this is my first blog post!")
            )
        )
    ).get());
{ref: ref(id = "300221779190743552", collection = ref(id = "posts", collection = ref(id = "collections"))), ts: 1622572650040000, data: {title: "First Post Title", body: "this is my first blog post!"}}
client.query(
  q.Call(
    q.Function('create_post'),
    [ 'First Post Title', 'This is my first blog post!' ],
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  ref: Ref(Collection("posts"), "300221794335326720"),
  ts: 1622572664480000,
  data: { title: 'First Post Title', body: 'This is my first blog post!' }
}
result = client.query(
  q.call(
    q.function("create_post"),
    ["First Post Title", "This is my first blog post!"]
  )
)
print(result)
{'ref': Ref(id=300221798539067904, collection=Ref(id=posts, collection=Ref(id=collections))), 'ts': 1622572668490000, 'data': {'title': 'First Post Title', 'body': 'This is my first blog post!'}}
try {
  println(Await.result(
    client.query(
      Call(
        Function("create_post"),
        Arr("First Post Title", "This is my first blog post!")
      )
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{ref: ref(id = "300221947617214976", collection = ref(id = "posts", collection = ref(id = "collections"))), ts: 1622572810670000, data: {title: "First Post Title", body: "This is my first blog post!"}}
Call(
  Function('create_post'),
  [ 'First Post Title', 'This is my first blog post!' ],
)
{
  ref: Ref(Collection("posts"), "302044131605086720"),
  ts: 1624310580730000,
  data: { title: 'First Post Title', body: 'This is my first blog post!' }
}

More information

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!