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 |
A reference to a resource, such as a document, collection, database, etc. |
Examples
The following query creates a single item set from the provided ref:
client.Query(
Singleton(Ref(Collection("posts"), "233286601218720256"))
);
{@set = {singleton: ref(id = "233286601218720256", class = ref(id = "posts", class = ref(id = "classes")))}}
curl https://db.fauna.com/ \
-u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
-d '{ "singleton": { "@ref": "classes/posts/233286601218720256" } }'
HTTP/1.1 200 OK
{
"resource": { "@set": { "singleton": { "@ref": "classes/posts/233286601218720256" } } }
}
result, _ := client.Query(
f.Singleton(f.Ref(f.Collection("posts"), "233286601218720256"))
)
fmt.Println(result)
{map[singleton:{229123172011606530 0xc0002ea460 <nil>}]}
System.out.println(
client.query(
Singleton(Ref(Collection("posts"), "233286601218720256"))
).get()
);
{@set = {singleton: ref(id = "233286601218720256", class = ref(id = "posts", class = ref(id = "classes")))}}
client.query(
q.Singleton(q.Ref(q.Collection('posts'), '233286601218720256'))
)
.then((ret) => console.log(ret))
SetRef({ singleton: Ref(Collection("posts"), "233286601218720256") })
print(client.query(
q.singleton(q.ref(q.collection("posts"), "233286601218720256"))
))
SetRef({'singleton': Ref(id=233286601218720256, class=Ref(id=posts, class=Ref(id=classes)))})
client.query(
Singleton(Ref(Collection("posts", "233286601218720256")))
)
{@set = {singleton: ref(id = "233286601218720256", class = ref(id = "posts", class = ref(id = "classes")))}}
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!