Singleton

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:

client.Query(
    Singleton(Ref(Collection("posts"), "233286601218720256"))
);
SetRefV(System.Collections.Generic.Dictionary`2[System.String,FaunaDB.Types.Value])
result, err := client.Query(
	f.Singleton(f.Ref(f.Collection("posts"), "233555580689580553")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
{map[singleton:{233555580689580553 0xc00009b410 0xc00009b410 <nil>}]}
System.out.println(
    client.query(
        Singleton(Ref(Collection("posts"), "233286601218720256"))
    ).get()
);
{@set = {singleton: ref(id = "233286601218720256", collection = ref(id = "posts", collection = ref(id = "collections")))}}
client.query(
  q.Singleton(q.Ref(q.Collection('posts'), '233286601218720256'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Singleton(Ref(Collection("posts"), "233286601218720256"))
result = client.query(
  q.singleton(q.ref(q.collection("posts"), "233286601218720256"))
)
print(result)
SetRef({'singleton': Ref(id=233286601218720256, collection=Ref(id=posts, collection=Ref(id=collections)))})
client.query(
  Singleton(Ref(Collection("posts"), "233286601218720256"))
)
{@set = {singleton: ref(id = "233286601218720256", collection = ref(id = "posts", collection = ref(id = "collections")))}}

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!