Structs

The following structs are available globally.

  • Represents an error found by FaunaDB while executing a query.

    See more

    Declaration

    Swift

    public struct QueryError
  • Represents a validation failure while executing a FaunaDB query.

    See more

    Declaration

    Swift

    public struct ValidationFailure
  • Obj

    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.

    Reference

    For example:

    // Using a primitive value
    Obj("name" => "John")
    
    // Using a call to `Time` function
    Obj("created_at" => Time("now"))
    
    See more

    Declaration

    Swift

    public struct Obj: Expr, AsJson, CustomStringConvertible
  • Arr

    Represents an array in FaunaDB where its elements can be a primitive value or an expression to be evaluated.

    Reference

    For example:

    // Using a primitive value
    Arr(1, "Two", 3)
    
    // Using a call to the `Time` function
    Arr(Time("now"))
    
    See more

    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 the name field to be a String. If the end result is not a String, 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 key data in which there should be a String field at the key name. If data field is not an object, it will fail.
    See more

    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:

    Fields.at("data", "arrayOfArrays").get(
        asArrayOf: Fields.get(asArrayOf: Field<String>())
    )
    
    // Resulting type: Field<[[String]]>
    
    See more

    Declaration

    Swift

    public struct Fields
  • Represents a high precision timestamp starting from UNIX epoch: 1970-01-01.

    See more

    Declaration

    Swift

    public struct HighPrecisionTime
  • Ref

    Ref creates a new RefV value with the ID provided.

    Reference.

    See more

    Declaration

    Swift

    public struct Ref: Fn
  • Aborts the current query execution.

    Reference.

    See more

    Declaration

    Swift

    public struct Abort: Fn
  • Returns a native reference to classes. This allows for example, paginate over all classes in a database.

    Reference.

    See more

    Declaration

    Swift

    public struct Classes: Fn
  • Returns a native reference to indexes. This allows for example, paginate over all indexes in a database.

    Reference.

    See more

    Declaration

    Swift

    public struct Indexes: Fn
  • Returns a native reference to databases. This allows for example, paginate over all databases in a database.

    Reference.

    See more

    Declaration

    Swift

    public struct Databases: Fn
  • Returns a native reference to functions. This allows for example, paginate over all functions in a database.

    Reference.

    See more

    Declaration

    Swift

    public struct Functions: Fn
  • Returns a native reference to keys. This allows for example, paginate over all keys in a database.

    Reference.

    See more

    Declaration

    Swift

    public struct Keys: Fn
  • Returns a native reference to tokens. This allows for example, paginate over all tokens in a database.

    Reference.

    See more

    Declaration

    Swift

    public struct Tokens: Fn
  • Returns a native reference to credentials. This allows for example, paginate over all credentials in a database.

    Reference.

    See more

    Declaration

    Swift

    public struct Credentials: Fn
  • Var

    A Var expression refers to the value of a variable varname in the current lexical scope. Referring to a variable that is not in scope results in an “unbound variable” error.

    Reference.

    See more

    Declaration

    Swift

    public struct Var: Fn
  • At

    At evaluates the expr at a given timestamp.

    Reference.

    See more

    Declaration

    Swift

    public struct At: Fn
  • Let

    Let binds values to one or more variables. Variable values cannot refer to other variables defined in the same let expression. Variables are lexically scoped to the expression passed via in.

    Reference.

    See more

    Declaration

    Swift

    public struct Let: Fn
  • If

    If evaluates and returns then expr or else expr depending on the value of pred. If pred evaluates to anything other than a boolean, if returns an “invalid argument” error.

    Reference.

    See more

    Declaration

    Swift

    public struct If: Fn
  • Do

    Do sequentially evaluates its arguments, and returns the evaluation of the last expression. If no expressions are provided, do returns an error.

    Reference.

    See more

    Declaration

    Swift

    public struct Do: Fn
  • Lambda creates an anonymous function that binds one or more variables in the expression at expr. The lambda form is only permitted as a direct argument to a form which applies it. It cannot be bound to a variable.

    Reference.

    See more

    Declaration

    Swift

    public struct Lambda: Fn
  • Call invoke the specified function reference. The function must be created using CreateFunction before it can be invoked.

    Reference.

    See more

    Declaration

    Swift

    public struct Call: Fn
  • Query constructs an instance of @query type with the specified lambda.

    Reference.

    See more

    Declaration

    Swift

    public struct Query: Fn
  • Map

    Map applies lambda 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.

    Map applies the lambda 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.

    Reference.

    See more

    Declaration

    Swift

    public struct Map: Fn
  • Foreach applies lambda expr to each member of the Array or Page coll. The original collection is returned.

    Foreach applies the lambda 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.

    Reference.

    See more

    Declaration

    Swift

    public struct Foreach: Fn
  • Filter applies lambda expr to each member of the Array or Page collection, and returns a new collection of the same type containing only those elements for which lambda 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.

    Reference.

    See more

    Declaration

    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. If take 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.

    Reference.

    See more

    Declaration

    Swift

    public struct Take: Fn
  • 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. If drop 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.

    Reference.

    See more

    Declaration

    Swift

    public struct Drop: Fn
  • Prepend returns a new Array that is the result of prepending elements onto the Array toCollection.

    Reference.

    See more

    Declaration

    Swift

    public struct Prepend: Fn
  • Append returns a new Array that is the result of appending elements onto the collection array.

    Reference.

    See more

    Declaration

    Swift

    public struct Append: Fn
  • Get

    Retrieves the instance identified by ref. If the instance does not exist, an “instance not found” error will be returned. Use the exists predicate to avoid “instance not found” errors. Reference.

    See more

    Declaration

    Swift

    public struct Get: Fn
  • KeyFromSecret retrieves a key object associated to the given secret.

    Reference.

    See more

    Declaration

    Swift

    public struct KeyFromSecret: Fn
  • Paginate retrieves a page from the set identified by resource. A valid set is any set identifier or instance ref. Instance refs represent singleton sets of themselves.

    Reference.

    See more

    Declaration

    Swift

    public struct Paginate: Fn
  • Exists returns boolean true if the provided ref exists (in the case of an instance), or is non-empty (in the case of a set), and false otherwise.

    Reference.

    See more

    Declaration

    Swift

    public struct Exists: Fn
  • Creates an instance of the class referred to by classRef, using params.

    Reference.

    See more

    Declaration

    Swift

    public struct Create: Fn
  • Updates a resource ref. Updates are partial, and only modify values that are specified. Scalar values and arrays are replaced by newer versions, objects are merged, and null removes a value.

    Reference.

    See more

    Declaration

    Swift

    public struct Update: Fn
  • Replaces the resource ref using the provided params. Values not specified are removed.

    Reference.

    See more

    Declaration

    Swift

    public struct Replace: Fn
  • Removes a resource.

    Reference.

    See more

    Declaration

    Swift

    public struct Delete: Fn
  • Adds an event to an instance’s history. The ref must refer to an instance of a user-defined class or a key - all other refs result in an “invalid argument” error.

    Reference.

    See more

    Declaration

    Swift

    public struct Insert: Fn
  • Deletes an event from an instance’s history. The ref must refer to an instance of an user-defined class - all other refs result in an “invalid argument” error.

    Reference.

    See more

    Declaration

    Swift

    public struct Remove: Fn
  • CreateClass creates a class object using params. It is a shortcut function that has the same effect as Create(Ref("classes"), params).

    Reference.

    See more

    Declaration

    Swift

    public struct CreateClass: Fn
  • CreateDatabase creates a new database using data from params. Since this function creates a database, it requires an admin key to be passed

    Reference.

    See more

    Declaration

    Swift

    public struct CreateDatabase: Fn
  • This function creates a new index where the name and source class are specified in params.

    Reference.

    See more

    Declaration

    Swift

    public struct CreateIndex: Fn
  • This function creates a new key where the database and role are specified in params. It needs the admin key for authentication.

    Reference.

    See more

    Declaration

    Swift

    public struct CreateKey: Fn
  • This function creates a new stored function where the name and body lambda are specified in params.

    Reference.

    See more

    Declaration

    Swift

    public struct CreateFunction: Fn
  • Singleton returns the history of the instance’s presence of the provided ref.

    Reference.

    See more

    Declaration

    Swift

    public struct Singleton: Fn
  • Events returns the history of instance’s data of the provided ref.

    Reference.

    See more

    Declaration

    Swift

    public struct Events: Fn
  • Match returns the set of instances that match the terms, based on the configuration of the specified index. terms can be either a single value, or an array.

    Reference.

    See more

    Declaration

    Swift

    public struct Match: Fn
  • Union represents the set of resources that are present in at least one of the specified sets.

    Reference.

    See more

    Declaration

    Swift

    public struct Union: Fn
  • Intersection represents the set of resources that are present in all of the specified sets.

    Reference.

    See more

    Declaration

    Swift

    public struct Intersection: Fn
  • Difference represents the set of resources present in the source set and not in any of the other specified sets.

    Reference.

    See more

    Declaration

    Swift

    public struct Difference: Fn
  • Distinct function returns the set after removing duplicates.

    Reference.

    See more

    Declaration

    Swift

    public struct Distinct: Fn
  • Join derives a set of resources from target by applying each instance in sourceSet to with target. Target can be either an index reference or a lambda function. The index form is useful when the instances in the sourceSet match the terms in an index. The join returns instances from index (specified by with) that match the terms from sourceSet.

    Reference.

    See more

    Declaration

    Swift

    public struct Join: Fn
  • Login creates a token for the provided ref.

    Reference.

    See more

    Declaration

    Swift

    public struct Login: Fn
  • Logout deletes all tokens associated with the current session if its parameter is true, or just the token used in this request otherwise.

    Reference..

    See more

    Declaration

    Swift

    public struct Logout: Fn
  • Identify checks the given password against the ref’s credentials, returning true if the credentials are valid, or false otherwise..

    Reference..

    See more

    Declaration

    Swift

    public struct Identify: Fn
  • Identity returns the instance reference associated with the current key token.

    For example, the current key token created using: Create(at: Tokens(), Obj("instance" => someRef)) or via: Login(for: someRef, Obj("password" => "sekrit")) will return someRef as the result of this function.

    Reference.

    See more

    Declaration

    Swift

    public struct Identity: Fn
  • HasIdentity checks if the current key token has an identity associated to it.

    Reference.

    See more

    Declaration

    Swift

    public struct HasIdentity: Fn
  • Concat joins a list of strings into a single string value.

    Reference.

    See more

    Declaration

    Swift

    public struct Concat: Fn
  • Casefold normalizes strings according to the Unicode Standard section 5.18 Case Mappings.

    To compare two strings for case-insensitive matching, transform each string and use a binary comparison, such as equals.

    Reference.

    See more

    Declaration

    Swift

    public struct Casefold: Fn
  • Time constructs a time special type from an ISO 8601 offset date/time string. The special string now may be used to construct a time from the current request’s transaction time. Multiple references to now within the same query will be equal.

    Reference.

    See more

    Declaration

    Swift

    public struct Time: Fn
  • Epoch constructs a time special type relative to the epoch (1970-01-01T00:00:00Z). offset must be an integer type. unit may be a valid time unit.

    Reference.

    See more

    Declaration

    Swift

    public struct Epoch: Fn
  • DateFn constructs a date special type from an ISO 8601 date string.

    Reference.

    See more

    Declaration

    Swift

    public struct DateFn: Fn
  • NextId produces a new identifier suitable for use when constructing refs.

    Reference

    See more

    Declaration

    Swift

    public struct NextId: Fn
  • NewId produces a new identifier suitable for use when constructing refs.

    Reference

    See more

    Declaration

    Swift

    public struct NewId: 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.

    Reference

    See more

    Declaration

    Swift

    public struct Database: Fn
  • The index function returns a valid ref for the given index name

    Reference

    See more

    Declaration

    Swift

    public struct Index: Fn
  • The class function returns a valid ref for the given class name

    Reference

    See more

    Declaration

    Swift

    public struct Class: Fn
  • The function function returns a valid ref for the given function name

    Reference

    See more

    Declaration

    Swift

    public struct Function: Fn
  • Equals tests equivalence between a list of values.

    Reference.

    See more

    Declaration

    Swift

    public struct Equals: Fn
  • Contains returns true if the argument passed to in contains a value at the specified path, and false otherwise.

    Reference.

    See more

    Declaration

    Swift

    public struct Contains: Fn
  • Select traverses into the argument passed to from and returns the resulting value. If the path does not exist, it results in an error.

    Reference.

    See more

    Declaration

    Swift

    public struct Select: Fn
  • SelectAll traverses into the argument passed to from flattening all values into an array.

    Reference.

    See more

    Declaration

    Swift

    public struct SelectAll: Fn
  • Add

    Add computes the sum of a list of numbers. Attempting to add fewer that two numbers will result in an “invalid argument” error.

    Reference.

    See more

    Declaration

    Swift

    public struct Add: Fn
  • Multiply computes the product of a list of numbers. Attempting to multiply fewer than two numbers will result in an “invalid argument” error.

    Reference.

    See more

    Declaration

    Swift

    public struct Multiply: Fn
  • Subtract computes the difference of a list of numbers. Attempting to subtract fewer than two numbers will result in an “invalid argument” error.

    Reference.

    See more

    Declaration

    Swift

    public struct Subtract: Fn
  • Divide computes the quotient of a list of numbers.

    Reference.

    See more

    Declaration

    Swift

    public struct Divide: Fn
  • Modulo computes the remainder after division of a list of numbers.

    Reference.

    See more

    Declaration

    Swift

    public struct Modulo: Fn
  • LT

    LT returns true if each specified value compares as less than the ones following it, and false otherwise. The function takes one or more arguments; it always returns true if it has a single argument.

    Reference.

    See more

    Declaration

    Swift

    public struct LT: Fn
  • LTE

    LTE returns true if each specified value compares as less than or equal to the ones following it, and false otherwise. The function takes one or more arguments; it always returns true if it has a single argument.

    Reference.

    See more

    Declaration

    Swift

    public struct LTE: Fn
  • GT

    GT returns true if each specified value compares as greater than the ones following it, and false otherwise. The function takes one or more arguments; it always returns true if it has a single argument.

    Reference.

    See more

    Declaration

    Swift

    public struct GT: Fn
  • GTE

    GTE returns true if each specified value compares as greater than or equal to the ones following it, and false otherwise. The function takes one or more arguments; it always returns true if it has a single argument.

    Reference.

    See more

    Declaration

    Swift

    public struct GTE: Fn
  • And

    And computes the conjunction of a list of boolean values, returning true if all elements are true, and false otherwise.

    Reference.

    See more

    Declaration

    Swift

    public struct And: Fn
  • Or

    Or computes the disjunction of a list of boolean values, returning true if any elements are true, and false otherwise.

    Reference.

    See more

    Declaration

    Swift

    public struct Or: Fn
  • Not

    Not computes the negation of a boolean expression. Computes the negation of a boolean value, returning true if its argument is false, or false if its argument is true..

    Reference.

    See more

    Declaration

    Swift

    public struct Not: Fn