Structs
The following structs are available globally.
-
Represents a hash map in FaunaDB where the key is always a
String
and the value can be a primitive value or an expression to be evaluated.You can use the operator
=>
as a syntax sugar while building new objects.For example:
See more// Using a primitive value Obj("name" => "John") // Using a call to `Time` function Obj("created_at" => Time("now"))
Declaration
Swift
public struct Obj: Expr, AsJson, CustomStringConvertible
-
Represents an array in FaunaDB where its elements can be a primitive value or an expression to be evaluated.
For example:
See more// Using a primitive value Arr(1, "Two", 3) // Using a call to the `Time` function Arr(Time("now"))
Declaration
Swift
public struct Arr: Expr, AsJson, CustomStringConvertible
-
Field
represents a field extractor for database entries returned by the server.For example:
let nameField = Field<String>("data", "name") let user = try! client.query( Get( Ref("classes/user/42") ) ).await(timeout: .now() + 5) let userName = user.get(field: nameField)
Every field has a path which is composed by a sequence of segments. A segment can be:
String
: when the desired field is contained in an object in which the segment will be used as the object key;Int
: when the desired field is contained in an array in which the segment will be used as the array index.
Rules for field extraction and data conversion:
- If the field is not present, it returns
nil
; - If the field can’t be converted to the expected type, it throws an
exception. E.g.:
Field<String>("data", "name")
expects thename
field to be aString
. If the end result is not aString
, it will fail; - If the path assumes a type that is not correct, it throws an exception.
E.g.:
Field<String>("data", "name")
expects the target value to contain a nested object at the keydata
in which there should be aString
field at the keyname
. Ifdata
field is not an object, it will fail.
Declaration
Swift
public struct Field<T>
-
Fields
has static constructors for field extractors that can be used when the result value is still undefined. These constructors are useful for complex field compositions.For example:
See moreFields.at("data", "arrayOfArrays").get( asArrayOf: Fields.get(asArrayOf: Field<String>()) ) // Resulting type: Field<[[String]]>
Declaration
Swift
public struct Fields
-
Represents a high precision timestamp starting from UNIX epoch:
See more1970-01-01
.Declaration
Swift
public struct HighPrecisionTime
-
See moreCall
invoke the specified function reference. The function must be created usingCreateFunction
before it can be invoked.Declaration
Swift
public struct Call: Fn
-
Map
applieslambda
expression to each member of the Array or Page collection, and returns the results of each application in a new collection of the same type. If a Page is passed, its cursor is preserved in the result.
See moreMap
applies thelambda
expression concurrently to each element of the collection. Side-effects, such as writes, do not affect evaluation of other lambda applications. The order of possible refs being generated within the lambda are non-deterministic.Declaration
Swift
public struct Map: Fn
-
Foreach
applieslambda
expr to each member of the Array or Page coll. The original collection is returned.
See moreForeach
applies thelambda
expr concurrently to each element of the collection. Side-effects, such as writes, do not affect evaluation of other lambda applications. The order of possible refs being generated within the lambda are non-deterministic.Declaration
Swift
public struct Foreach: Fn
-
Filter
applieslambda
expr to each member of the Array or Page collection, and returns a new collection of the same type containing only those elements for whichlambda
expr returned true. If a Page is passed, its cursor is preserved in the result.Providing a lambda which does not return a Boolean results in an “invalid argument” error.
See moreDeclaration
Swift
public struct Filter: Fn
-
Take
returns a new Collection or Page that contains num elements from the head of the Collection or Page coll. Iftake
value is zero or negative, the resulting collection is empty. When applied to a page, the returned page’s after cursor is adjusted to only cover the taken elements.As special cases:
- If
take
value is negative, after will be set to the same value as the original page’s before. - If all elements from the original page were taken, after does not change.
Declaration
Swift
public struct Take: Fn
- If
-
Drop
returns a new Arr or Page that contains the remaining elements, after num have been removed from the head of the Arr or Page coll. Ifdrop
value is zero or negative, elements of coll are returned unmodified.When applied to a page, the returned page’s before cursor is adjusted to exclude the dropped elements. As special cases:
- If
drop
value is negative, before does not change. - Otherwise if all elements from the original page were dropped (including the case where the page was already empty), before will be set to same value as the original page’s after.
Declaration
Swift
public struct Drop: Fn
- If
-
See moreJoin
derives a set of resources from target by applying each instance insourceSet
towith
target. Target can be either an index reference or a lambda function. The index form is useful when the instances in thesourceSet
match the terms in an index. The join returns instances from index (specified by with) that match the terms fromsourceSet
.Declaration
Swift
public struct Join: Fn
-
Identity
returns the instance reference associated with the current key token.For example, the current key token created using:
See moreCreate(at: Tokens(), Obj("instance" => someRef))
or via:Login(for: someRef, Obj("password" => "sekrit"))
will returnsomeRef
as the result of this function.Declaration
Swift
public struct Identity: Fn
-
See moreTime
constructs a time special type from an ISO 8601 offset date/time string. The special stringnow
may be used to construct a time from the current request’s transaction time. Multiple references tonow
within the same query will be equal.Declaration
Swift
public struct Time: Fn
-
Given the name of a database, this function returns a valid ref that points to it. The database function only looks up child databases so finding a database using this function requires you to provide an admin key from the parent database.
See moreDeclaration
Swift
public struct Database: Fn
-
Declaration
Swift
public struct StringV: ScalarValue, AsJson
-
Declaration
Swift
public struct LongV: ScalarValue, AsJson
-
Declaration
Swift
public struct DoubleV: ScalarValue, AsJson
-
Declaration
Swift
public struct BooleanV: ScalarValue, AsJson
-
Represents a timestamp returned by the server.
Note
You can convert a timestamp to two different types:
HighPrecisionTime
: A timestamp with nanoseconds precision.Date
: A timestamp with seconds precision only.
Declaration
Swift
public struct TimeV: ScalarValue, AsJson
-
Declaration
Swift
public struct DateV: ScalarValue, AsJson
-
Declaration
Swift
public struct RefV: ScalarValue, AsJson
-
Undocumented
See more -
Declaration
Swift
public struct SetRefV: ScalarValue, AsJson
-
Declaration
Swift
public struct BytesV: ScalarValue, AsJson