CreateFunction

// Not available in this language yet.
CreateFunction( param_object )
CreateFunction( param_object )
// Not available in this language yet.
# Not available in this language yet.
# Not available in this language yet.
// Not available in this language yet.
CreateFunction( param_object )

Description

The CreateFunction operation adds a new user-defined function with the specified parameters.

Parameters

Argument Type Definition and Requirements

param_object

Object

The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements

name

String

The logical name of the function.

body

Object

The Fauna Query Language instructions to be executed.

data

Object

Optional - This is user-defined metadata for the user-defined function. It is provided for the developer to store information at the function level.

Returns

An object containing the metadata of CreateFunction operations.

Field Name Field Type Definition and Requirements

ref

Reference

The reference is an automatically-generated, unique identifier within the database to identify the function that was created.

name

String

The logical name of the function created.

ts

Long

The timestamp associated with the creation of the function.

body

Object

The Fauna Query Language instructions to be executed.

Examples

The query below creates a user-defined function called "double".

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "create_function": {
            "object": {
              "name": "double",
              "body": {
                "query": {
                  "lambda": "x",
                  "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
                }
              }
            }
          }
        }'
// Not available in this language yet.
System.out.println(
   client.query(
      CreateFunction(
         Obj( "name", Value("double"),
            "body" , Query(Lambda(Value("x"), Add(Var("x"), Var("x"))))
         )
      )
   ).get());
result, _ := client.Query(
    f.CreateFunction(f.Obj{
        "name": "double",
        "body": f.Query(f.Lambda("x", f.Add(f.Var("x"), f.Var("x")))),
    }),
)

fmt.Println(result)
client.query(
   CreateFunction(
      Obj( "name", Value("double"),
         "body" , Query(Lambda(Value("x"), Add(Var("x"), Var("x"))))
      )
   )
).get();
# Not available in this language yet.
# Not available in this language yet.
// Not available in this language yet.
client.query(q.CreateFunction({ name: "double", body:
  q.Query(q.Lambda("x", q.Add(q.Var("x"), q.Var("x")))) }))
.then((ret) => console.log(ret))
HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "functions/double" },
    "class": { "@ref": "functions" },
    "ts": 1509244540046619,
    "name": "double",
    "body": {
      "@query": {
        "lambda": "x",
        "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
      }
    }
  }
}
{
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}
{
  ref: ref(id = "double", class = ref(id = "functions")),
  ts: 1527869785204010,
  name: "double",
  body: QueryV({lambda=x, expr={add=[{var=x}, {var=x}]}})
}
map[
  ref:{double 0xc4202310a0 <nil>}
  ts:1509244540046619
  body:{[123 34 108 97 109 98 100 97 34 58 34 120 34 44 34 101 120 112 114 34 58 123 34 97 100 100 34 58 91 123 34 118 97 114 34 58 34 120 34 125 44 123 34 118 97 114 34 58 34 120 34 125 93 125 125]}
]
{
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}
{
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}
{
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}
{
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}
{ ref: Ref(id=double, class=Ref(id=functions)),
  ts: 1527275011179623,
  name: 'double',
  body: Query("[object Object]") }