Delete a function

Creating and updating a function requires:

Problem

You need to delete a function from the current database.

Solution

Use the Delete function:

try
{
    Value result = await client.Query(
        Delete(Function("create_post"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "create_post", collection = RefV(id = "functions")),ts: LongV(1622572615130000),name: StringV(create_post),body: QueryV(System.Collections.Generic.Dictionary`2[System.String,FaunaDB.Query.Expr]))
result, err := client.Query(
	f.Delete(f.Function("create_post")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[body:{[123 34 97 112 105 95 118 101 114 115 105 111 110 34 58 34 52 34 44 34 108 97 109 98 100 97 34 58 91 34 116 105 116 108 101 34 44 34 98 111 100 121 34 44 34 97 117 116 104 111 114 34 93 44 34 101 120 112 114 34 58 123 34 99 114 101 97 116 101 34 58 123 34 99 111 108 108 101 99 116 105 111 110 34 58 34 112 111 115 116 115 34 125 44 34 112 97 114 97 109 115 34 58 123 34 111 98 106 101 99 116 34 58 123 34 100 97 116 97 34 58 123 34 111 98 106 101 99 116 34 58 123 34 97 117 116 104 111 114 34 58 123 34 118 97 114 34 58 34 97 117 116 104 111 114 34 125 44 34 98 111 100 121 34 58 123 34 118 97 114 34 58 34 98 111 100 121 34 125 44 34 116 105 116 108 101 34 58 123 34 118 97 114 34 58 34 116 105 116 108 101 34 125 125 125 125 125 125 125]} name:create_post ref:{create_post 0xc0001097d0 0xc0001097d0 <nil>} ts:1622572625070000]
System.out.println(
    client.query(
        Delete(Function("create_post"))
    ).get());
{ref: ref(id = "create_post", collection = ref(id = "functions")), ts: 1622572655430000, name: "create_post", body: QueryV({api_version=4, lambda=[title, body, author], expr={create={collection=posts}, params={object={data={object={title={var=title}, body={var=body}, author={var=author}}}}}}})}
client.query(
  q.Delete(q.Function('create_post'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  ref: Function("create_post"),
  ts: 1622572664750000,
  name: 'create_post',
  body: Query(Lambda(["title", "body", "author"], Create(Collection("posts"), {"data": {"title": Var("title"), "body": Var("body"), "author": Var("author")}})))
}
result = client.query(
  q.delete(q.function("create_post"))
)
print(result)
{'ref': Ref(id=create_post, collection=Ref(id=functions)), 'ts': 1622572668750000, 'name': 'create_post', 'body': Query({'api_version': '4', 'lambda': ['title', 'body', 'author'], 'expr': {'create': {'collection': 'posts'}, 'params': {'object': {'data': {'object': {'title': {'var': 'title'}, 'body': {'var': 'body'}, 'author': {'var': 'author'}}}}}}})}
try {
  println(Await.result(
    client.query(
      Delete(Function("create_post"))
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{ref: ref(id = "create_post", collection = ref(id = "functions")), ts: 1622572839700000, name: "create_post", body: {api_version: "4", lambda: ["title", "body", "author"], expr: {create: {collection: "posts"}, params: {object: {data: {object: {title: {var: "title"}, body: {var: "body"}, author: {var: "author"}}}}}}}}
Delete(Function('create_post'))
{
  ref: Function("create_post"),
  ts: 1624310581310000,
  name: 'create_post',
  body: Query(Lambda(["title", "body", "author"], Create(Collection("posts"), {data: {title: Var("title"), body: Var("body"), author: Var("author")}})))
}

Discussion

When a function is deleted, queries that call the function fail with an error.

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!