Singleton

Singleton( ref )
Singleton( ref )
Singleton( ref )
Singleton( ref )
singleton( ref )
singleton( ref )
Singleton( ref )
Singleton( ref )

Description

The Singleton function produces a set containing the ref that you provide.

In most cases, functions cast refs into sets when necessary. The only case where Singleton is required is to return a set’s events rather than a ref’s events.

Parameters

Argument Type Definition and Requirements

ref

Ref

A reference to a resource, such as a document, collection, database, etc.

Returns

A SetRef for the single ref.

Examples

The following query creates a single item set from the provided ref:

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "singleton": { "@ref": "classes/posts/233286601218720256" } }'
client.Query(
  Singleton(Ref(Collection("posts"), "233286601218720256"))
);
System.out.println(
    client.query(
        Singleton(Ref(Collection("posts"), "233286601218720256"))
    ).get()
);
result, _ := client.Query(
    f.Singleton(f.Ref(f.Collection("posts"), "233286601218720256"))
)

fmt.Println(result)
client.query(
  Singleton(Ref(Collection("posts", "233286601218720256")))
)
print(client.query(
  q.singleton(q.ref(q.collection("posts"),  "233286601218720256"))
))
puts $client.query {
  singleton ref collection("posts"), "233286601218720256"
}
client.query(
    Singleton(Ref(Collection("posts"), "233286601218720256"))
)
client.query(
  q.Singleton(q.Ref(q.Collection("posts"), "233286601218720256"))
)
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": { "@set": { "singleton": { "@ref": "classes/posts/233286601218720256" } } }
}
{@set = {singleton: ref(id = "233286601218720256", class = ref(id = "posts", class = ref(id = "classes")))}}
{@set = {singleton: ref(id = "233286601218720256", class = ref(id = "posts", class = ref(id = "classes")))}}
{map[singleton:{229123172011606530 0xc0002ea460 <nil>}]}
{@set = {singleton: ref(id = "233286601218720256", class = ref(id = "posts", class = ref(id = "classes")))}}
SetRef({'singleton': Ref(id=233286601218720256, class=Ref(id=posts, class=Ref(id=classes)))})
#<Fauna::SetRef:0x00007fb5a5029b28>
{@set = {singleton: ref(id = "233286601218720256", class = ref(id = "posts", class = ref(id = "classes")))}}
SetRef({ singleton: Ref(Collection("posts"), "233286601218720256") })

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!