faunadb

package
v4.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: MPL-2.0 Imports: 23 Imported by: 22

Documentation

Overview

Package faunadb implements the FaunaDB query language for Golang applications.

FaunaClient is the main client structure, containing methods to communicate with a FaunaDB Cluster. This structure is designed to be reused, so avoid making copies of it.

FaunaDB's query language is composed of expressions that implement the Expr interface. Expressions are created using the query language functions found in query.go.

Responses returned by FaunaDB are wrapped into types that implement the Value interface. This interface provides methods for transversing and decoding FaunaDB values into native Go types.

The driver allows for the user to encode custom data structures. You can create your own struct and encode it as a valid FaunaDB object.

type User struct {
	Name string
	Age  int
}

user := User{"John", 24} // Encodes as: {"Name": "John", "Age": 24}

If you wish to control the property names, you can tag them with the "fauna" tag:

type User struct {
	Name string `fauna:"displayName"`
	Age  int    `fauna:"age"`
}

user := User{"John", 24} // Encodes as: {"displayName": "John", "age": 24}

For more information about FaunaDB, check https://fauna.com/.

Example
package main

import f "github.com/fauna/faunadb-go/v4/faunadb"

var (
	data = f.ObjKey("data")
	ref  = f.ObjKey("ref")
)

type Profile struct {
	Name     string `fauna:"name"`
	Verified bool   `fauna:"verified"`
}

func main() {
	var profileId f.RefV

	// Crate a new client
	client := f.NewFaunaClient("your-secret-here")

	// Create a collection to store profiles
	_, _ = client.Query(f.CreateCollection(f.Obj{"name": "profiles"}))

	// Create a new profile entry
	profile := Profile{
		Name:     "Jhon",
		Verified: false,
	}

	// Save profile at FaunaDB
	newProfile, _ := client.Query(
		f.Create(
			f.Collection("profiles"),
			f.Obj{"data": profile},
		),
	)

	// Get generated profile ID
	_ = newProfile.At(ref).Get(&profileId)

	// Update existing profile entry
	_, _ = client.Query(
		f.Update(
			profileId,
			f.Obj{"data": f.Obj{
				"verified": true,
			}},
		),
	)

	// Retrieve profile by its ID
	value, _ := client.Query(f.Get(profileId))
	_ = value.At(data).Get(&profile)

	// Delete profile using its ID
	_, _ = client.Query(f.Delete(profileId))
}
Output:

Index

Examples

Constants

View Source
const (
	ActionCreate = "create"
	ActionUpdate = "update"
	ActionDelete = "delete"
	ActionAdd    = "add"
	ActionRemove = "remove"
)

Event's action types. Usually used as a parameter for Insert or Remove functions.

See: https://app.fauna.com/documentation/reference/queryapi#simple-type-events

View Source
const (
	TimeUnitDay         = "day"
	TimeUnitHalfDay     = "half day"
	TimeUnitHour        = "hour"
	TimeUnitMinute      = "minute"
	TimeUnitSecond      = "second"
	TimeUnitMillisecond = "millisecond"
	TimeUnitMicrosecond = "microsecond"
	TimeUnitNanosecond  = "nanosecond"
)

Time unit. Usually used as a parameter for Time functions.

See: https://app.fauna.com/documentation/reference/queryapi#epochnum-unit

View Source
const (
	NormalizerNFKCCaseFold = "NFKCCaseFold"
	NormalizerNFC          = "NFC"
	NormalizerNFD          = "NFD"
	NormalizerNFKC         = "NFKC"
	NormalizerNFKD         = "NFKD"
)

Normalizers for Casefold

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

Variables

This section is empty.

Functions

func MarshalJSON

func MarshalJSON(value Value) ([]byte, error)

Marshal a FaunaDB value into a json string.

func UnmarshalJSON

func UnmarshalJSON(buffer []byte, outValue *Value) error

Unmarshal json string into a FaunaDB value.

Types

type Arr

type Arr []interface{}

Arr is a expression shortcut to represent any valid JSON array

func (Arr) MarshalJSON

func (arr Arr) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Arr expression

type ArrayV

type ArrayV []Value

ArrayV represents a FaunaDB array type.

func (ArrayV) At

func (arr ArrayV) At(field Field) FieldValue

At implements the Value interface by traversing the array and extracting the provided field.

func (ArrayV) Get

func (arr ArrayV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either an ArrayV or a native slice type.

type BadRequest

type BadRequest struct{ FaunaError }

A BadRequest wraps an HTTP 400 error response.

type BooleanV

type BooleanV bool

BooleanV represents a valid JSON boolean.

func (BooleanV) At

func (boolean BooleanV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since BooleanV is not traversable.

func (BooleanV) Get

func (boolean BooleanV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a BooleanV or a boolean type.

type BytesV

type BytesV []byte

BytesV represents a FaunaDB binary blob type.

func (BytesV) At

func (bytes BytesV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since BytesV is not traversable.

func (BytesV) Get

func (bytes BytesV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a ByteV or a []byte type.

func (BytesV) MarshalJSON

func (bytes BytesV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB bytes representation.

type ClientConfig

type ClientConfig func(*FaunaClient)

ClientConfig is the base type for the configuration parameters of a FaunaClient.

func DisableTxnTimePassthrough

func DisableTxnTimePassthrough() ClientConfig

DisableTxnTimePassthrough configures the FaunaClient to not keep track of the last seen transaction time. The last seen transaction time is used to avoid reading stale data from outdated replicas when reading and writing from different nodes at the same time.

Disabling this option might lead to data inconsistencies and is not recommended. If don't know what you're doing leave this alone. Use at your own risk.

func EnableTxnTimePassthrough deprecated

func EnableTxnTimePassthrough() ClientConfig

EnableTxnTimePassthrough configures the FaunaClient to keep track of the last seen transaction time. The last seen transaction time is used to avoid reading stale data from outdated replicas when reading and writing from different nodes at the same time.

Deprecated: This function is deprecated since this feature is enabled by default.

func Endpoint

func Endpoint(url string) ClientConfig

Endpoint configures the FaunaDB URL for a FaunaClient.

func HTTP

func HTTP(http *http.Client) ClientConfig

HTTP allows the user to override the http.Client used by a FaunaClient.

func Headers added in v4.1.0

func Headers(headers map[string]string) ClientConfig

Headers configures the http headers for a FaunaClient.

func Observer

func Observer(observer ObserverCallback) ClientConfig

Observer configures a callback function called for every query executed.

func QueryTimeoutMS

func QueryTimeoutMS(millis uint64) ClientConfig

QueryTimeoutMS sets the server timeout for ALL queries issued with this client. This is not the http request timeout.

type DateV

type DateV time.Time

DateV represents a FaunaDB date type.

func (DateV) At

func (date DateV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since DateV is not traversable.

func (DateV) Get

func (date DateV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a DateV or a time.Time type.

func (DateV) MarshalJSON

func (date DateV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB date representation.

type DecodeError

type DecodeError struct {
	// contains filtered or unexported fields
}

A DecodeError describes an error when decoding a Fauna Value to a native Golang type

func (DecodeError) Error

func (d DecodeError) Error() string

type DoubleV

type DoubleV float64

DoubleV represents a valid JSON double.

func (DoubleV) At

func (num DoubleV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since DoubleV is not traversable.

func (DoubleV) Get

func (num DoubleV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a DoubleV or a float type.

type ErrorEvent

type ErrorEvent struct {
	StreamEvent
	// contains filtered or unexported fields
}

ErrorEvent represents an error event fired both for client and server errors that may occur as a result of a subscription.

func (ErrorEvent) Error

func (event ErrorEvent) Error() error

Error returns the event error

func (ErrorEvent) String

func (event ErrorEvent) String() string

func (ErrorEvent) Txn

func (event ErrorEvent) Txn() int64

Txn returns the stream event timestamp

func (ErrorEvent) Type

func (event ErrorEvent) Type() StreamEventType

Type returns the stream event type

type Expr

type Expr interface {
	// contains filtered or unexported methods
}

Expr is the base type for FaunaDB query language expressions.

Expressions are created by using the query language functions in query.go. Query functions are designed to compose with each other, as well as with custom data structures. For example:

type User struct {
	Name string
}

_, _ := client.Query(
	Create(
		Collection("users"),
		Obj{"data": User{"John"}},
	),
)

func Abort

func Abort(msg interface{}) Expr

Abort aborts the execution of the query

Parameters:

msg string - An error message.

Returns:

Error

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func Abs

func Abs(value interface{}) Expr

Abs computes the absolute value of a number.

Parameters:

value number - The number to take the absolute value of

Returns:

number - The abosulte value of a number

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func AccessProvider

func AccessProvider(name interface{}) Expr

AccessProvider create a new access provider ref.

Parameters:

name string - The name of the access provider.

Returns:

Ref - The access provider reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func AccessProviders

func AccessProviders() Expr

AccessProviders creates a native ref for access providers.

Returns:

Ref - The reference of the access providers set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Acos

func Acos(value interface{}) Expr

Acos computes the arccosine of a number.

Parameters:

value number - The number to take the arccosine of

Returns:

number - The arccosine of a number

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Add

func Add(args ...interface{}) Expr

Add computes the sum of a list of numbers.

Parameters:

args []number - A collection of numbers to sum together.

Returns:

number - The sum of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func All

func All(collection interface{}) Expr

All evaluates to true if all elements of the collection are true.

Parameters: collection - the collection

Returns: Expr

See: https://docs.fauna.com/fauna/current/api/fql/functions/all

func And

func And(args ...interface{}) Expr

And returns the conjunction of a list of boolean values.

Parameters:

args []bool - A collection to compute the conjunction of.

Returns:

bool - true if all elements are true, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Any

func Any(collection interface{}) Expr

Any evaluates to true if any element of the collection is true.

Parameters: collection - the collection

Returns: Expr

See: https://docs.fauna.com/fauna/current/api/fql/functions/any

func Append

func Append(elems, coll interface{}) Expr

Append returns a new collection that is the result of appending elems to coll.

Parameters:

elems []Value - Elements to add to the end of the other collection.
coll []Value - The collection of elements.

Returns:

[]Value - A new collection.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func Asin

func Asin(value interface{}) Expr

Asin computes the arcsine of a number.

Parameters:

value number - The number to take the arcsine of

Returns:

number - The arcsine of a number

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func At

func At(timestamp, expr interface{}) Expr

At execute an expression at a given timestamp.

Parameters:

timestamp time - The timestamp in which the expression will be evaluated.
expr Expr - An expression to be evaluated.

Returns:

Value - The result of the given expression.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func Atan

func Atan(value interface{}) Expr

Atan computes the arctan of a number.

Parameters:

value number - The number to take the arctan of

Returns:

number - The arctan of a number

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func BitAnd

func BitAnd(args ...interface{}) Expr

BitAnd computes the and of a list of numbers.

Parameters:

args []number - A collection of numbers to and together.

Returns:

number - The and of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func BitNot

func BitNot(value interface{}) Expr

BitNot computes the 2's complement of a number

Parameters:

value number - A numbers to not

Returns:

number - The not of an element

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func BitOr

func BitOr(args ...interface{}) Expr

BitOr computes the OR of a list of numbers.

Parameters:

args []number - A collection of numbers to OR together.

Returns:

number - The OR of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func BitXor

func BitXor(args ...interface{}) Expr

BitXor computes the XOR of a list of numbers.

Parameters:

args []number - A collection of numbers to XOR together.

Returns:

number - The XOR of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Call

func Call(ref interface{}, args ...interface{}) Expr

Call invokes the specified function passing in a variable number of arguments

Parameters:

ref Ref - The reference to the user defined functions to call.
args []Value - A series of values to pass as arguments to the user defined function.

Returns:

Value - The return value of the user defined function.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func Casefold

func Casefold(str interface{}, options ...OptionalParameter) Expr

Casefold normalizes strings according to the Unicode Standard section 5.18 "Case Mappings".

Parameters:

str string - The string to casefold.

Optional parameters:

normalizer string - The algorithm to use. One of: NormalizerNFKCCaseFold, NormalizerNFC, NormalizerNFD, NormalizerNFKC, NormalizerNFKD.

Returns:

string - The normalized string.

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Ceil

func Ceil(value interface{}) Expr

Ceil computes the largest integer greater than or equal to

Parameters:

value number - A numbers to compute the ceil of

Returns:

number - The ceil of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Class deprecated

func Class(name interface{}) Expr

Class creates a new class ref.

Parameters:

name string - The name of the class.

Deprecated: Use Collection instead, Class is kept for backwards compatibility

Returns:

Ref - The class reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Classes deprecated

func Classes() Expr

Classes creates a native ref for classes.

Deprecated: Use Collections instead, Classes is kept for backwards compatibility

Returns:

Ref - The reference of the class set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Collection

func Collection(name interface{}) Expr

Collection creates a new collection ref.

Parameters:

name string - The name of the collection.

Returns:

Ref - The collection reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Collections

func Collections() Expr

Collections creates a native ref for collections.

Returns:

Ref - The reference of the collections set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Concat

func Concat(terms interface{}, options ...OptionalParameter) Expr

Concat concatenates a list of strings into a single string.

Parameters:

terms []string - A list of strings to concatenate.

Optional parameters:

separator string - The separator to use between each string. See Separator() function.

Returns:

string - A string with all terms concatenated.

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Contains deprecated

func Contains(path, value interface{}) Expr

Contains checks if the provided value contains the path specified.

Parameters:

path Path - An array representing a path to check for the existence of. Path can be either strings or ints.
value Object - An object to search against.

Returns:

bool - true if the path contains any value, false otherwise.

Deprecated: Use ContainsPath instead. Contains will be removed in API v4.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ContainsField

func ContainsField(field, value interface{}) Expr

ContainsField checks if the provided value contains the field specified.

Parameters:

field Expr - The field to check for the existence of. Field can only be a string.
value Expr - Value to search against.

Returns:

bool - true if the field exists, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ContainsPath

func ContainsPath(path, value interface{}) Expr

ContainsPath checks if the provided value contains the path specified.

Parameters:

path Path - An array representing a path to check for the existence of. Path can be either strings or ints.
value Object - Value to search against.

Returns:

bool - true if the path contains any value, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ContainsStr

func ContainsStr(value interface{}, search interface{}) Expr

ContainsStr returns true if the string contains the given substring, or false if otherwise

Parameters:

value string - the string to evaluate search string - the substring to search for

Returns: boolean - was the search result found

See https://docs.fauna.com/fauna/current/api/fql/functions/containsstr

func ContainsStrRegex

func ContainsStrRegex(value interface{}, pattern interface{}) Expr

ContainsStrRegex returns true if the string contains the given pattern, or false if otherwise

Parameters:

value string - the string to evaluate pattern string - the pattern to search for

Returns: boolean - was the search result found

See https://docs.fauna.com/fauna/current/api/fql/functions/containsstrregex

func ContainsValue

func ContainsValue(value, in interface{}) Expr

ContainsValue checks if the provided value contains the value specified.

Parameters:

value Expr - Value to check for the existence of.
in Expr - An object/array/page/ref to search against.

Returns:

bool - true if the value is found, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Cos

func Cos(value interface{}) Expr

Cos computes the Cosine of a number

Parameters:

value number - A number to compute the cosine of

Returns:

number - The cosine of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Cosh

func Cosh(value interface{}) Expr

Cosh computes the Hyperbolic Cosine of a number

Parameters:

value number - A number to compute the Hyperbolic cosine of

Returns:

number - The Hyperbolic cosine of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Count

func Count(collection interface{}) Expr

Count returns the number of elements in the collection.

Parameters: collection Expr - the collection

Returns: a new Expr instance

See: https://docs.fauna.com/fauna/current/api/fql/functions/count

func Create

func Create(ref, params interface{}) Expr

Create creates an document of the specified collection.

Parameters:

ref Ref - A collection reference.
params Object - An object with attributes of the document created.

Returns:

Object - A new document of the collection referenced.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func CreateAccessProvider

func CreateAccessProvider(params interface{}) Expr

CreateAccessProvider creates a new AccessProvider

Parameters: params Object - An object of parameters used to create a new access provider.

  • name: A valid schema name
  • issuer: A unique string
  • jwks_uri: A valid HTTPS URL
  • roles: An optional list of Role refs
  • data: An optional user-defined metadata for the AccessProvider

Returns: Object - The new created access provider.

See: the [docs](https://app.fauna.com/documentation/reference/queryapi#write-functions).

func CreateClass deprecated

func CreateClass(params interface{}) Expr

CreateClass creates a new class.

Parameters:

params Object - An object with attributes of the class.

Deprecated: Use CreateCollection instead, CreateClass is kept for backwards compatibility

Returns:

Object - The new created class object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func CreateCollection

func CreateCollection(params interface{}) Expr

CreateCollection creates a new collection.

Parameters:

params Object - An object with attributes of the collection.

Returns:

Object - The new created collection object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func CreateDatabase

func CreateDatabase(params interface{}) Expr

CreateDatabase creates an new database.

Parameters:

params Object - An object with attributes of the database.

Returns:

Object - The new created database object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func CreateFunction

func CreateFunction(params interface{}) Expr

CreateFunction creates a new function.

Parameters:

params Object - An object with attributes of the function.

Returns:

Object - The new created function object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func CreateIndex

func CreateIndex(params interface{}) Expr

CreateIndex creates a new index.

Parameters:

params Object - An object with attributes of the index.

Returns:

Object - The new created index object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func CreateKey

func CreateKey(params interface{}) Expr

CreateKey creates a new key.

Parameters:

params Object - An object with attributes of the key.

Returns:

Object - The new created key object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func CreateRole

func CreateRole(params interface{}) Expr

CreateRole creates a new role.

Parameters:

params Object - An object with attributes of the role.

Returns:

Object - The new created role object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func Credentials

func Credentials() Expr

Credentials creates a native ref for credentials.

Returns:

Ref - The reference of the credential set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func CurrentIdentity

func CurrentIdentity() Expr

func CurrentToken

func CurrentToken() Expr

func Database

func Database(name interface{}) Expr

Database creates a new database ref.

Parameters:

name string - The name of the database.

Returns:

Ref - The database reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Databases

func Databases() Expr

Databases creates a native ref for databases.

Returns:

Ref - The reference of the datbase set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Date

func Date(str interface{}) Expr

Date constructs a date from a ISO 8601 offset date/time string.

Parameters:

str string - A string to convert to a date object.

Returns:

date - A date object.

See: https://app.fauna.com/documentation/reference/queryapi#time-and-date

func DayOfMonth

func DayOfMonth(value interface{}) Expr

DayOfMonth returns a time expression's day of the month, from 1 to 31.

Parameters:

value Object - The expression to convert.

Returns:

time - day of month.

func DayOfWeek

func DayOfWeek(value interface{}) Expr

DayOfWeek returns a time expression's day of the week following ISO-8601 convention, from 1 (Monday) to 7 (Sunday).

Parameters:

value Object - The expression to convert.

Returns:

time - day of week.

func DayOfYear

func DayOfYear(value interface{}) Expr

DayOfYear eturns a time expression's day of the year, from 1 to 365, or 366 in a leap year.

Parameters:

value Object - The expression to convert.

Returns:

time - Day of the year.

func Degrees

func Degrees(value interface{}) Expr

Degrees computes the degress of a number

Parameters:

value number - A number to compute the degress of

Returns:

number - The degrees of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Delete

func Delete(ref interface{}) Expr

Delete deletes the provided document.

Parameters:

ref Ref - The reference to delete.

Returns:

Object - The deleted object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func Difference

func Difference(sets ...interface{}) Expr

Difference returns the set of documents that are present in the first set but not in any of the other specified sets.

Parameters:

sets []SetRef - A list of SetRef to diff.

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func Distinct

func Distinct(set interface{}) Expr

Distinct returns the set of documents with duplicates removed.

Parameters:

set []SetRef - A list of SetRef to remove duplicates from.

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func Divide

func Divide(args ...interface{}) Expr

Divide computes the quotient of a list of numbers.

Parameters:

args []number - A collection of numbers to compute the quotient of.

Returns:

number - The quotient of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Do

func Do(exprs ...interface{}) Expr

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

Parameters:

exprs []Expr - A variable number of expressions to be evaluated.

Returns:

Value - The result of the last expression in the list.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func Documents

func Documents(collection interface{}) Expr

Documents returns a set of all documents in the given collection. A set must be paginated in order to retrieve its values.

Parameters: collection ref - a reference to the collection

Returns: Expr - A new Expr instance

See: https://docs.fauna.com/fauna/current/api/fql/functions/Documents

func Drop

func Drop(num, coll interface{}) Expr

Drop returns a new collection containing the remaining elements from the original collection after num elements have been removed.

Parameters:

num int64 - The number of elements to drop from the collection.
coll []Value - The collection of elements.

Returns:

[]Value - A new collection.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func EndsWith

func EndsWith(value interface{}, search interface{}) Expr

EndsWith returns true if the string ends with the given suffix value, or false if otherwise

Parameters:

value string - the string to evaluate search string - the suffix to search for

Returns: boolean - does `value` end with `search`

See https://docs.fauna.com/fauna/current/api/fql/functions/endswith

func Epoch

func Epoch(num, unit interface{}) Expr

Epoch constructs a time relative to the epoch "1970-01-01T00:00:00Z".

Parameters:

num int64 - The number of units from Epoch.
unit string - The unit of number. One of TimeUnitSecond, TimeUnitMillisecond, TimeUnitMicrosecond, TimeUnitNanosecond.

Returns:

time - A time object.

See: https://app.fauna.com/documentation/reference/queryapi#time-and-date

func Equals

func Equals(args ...interface{}) Expr

Equals checks if all args are equivalents.

Parameters:

args []Value - A collection of expressions to check for equivalence.

Returns:

bool - true if all elements are equals, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Events

func Events(refSet interface{}) Expr

Events returns the history of document's data of the provided ref.

Parameters:

refSet Ref|SetRef - A reference or set reference to retrieve an event set from.

Returns:

SetRef - The events SetRef.

See: https://app.fauna.com/documentation/reference/queryapi#sets

func Exists

func Exists(ref interface{}, options ...OptionalParameter) Expr

Exists returns boolean true if the provided ref exists (in the case of an document), or is non-empty (in the case of a set), and false otherwise. Optional parameters: TS.

Parameters:

ref Ref - The reference to the object. It could be a document reference of a object reference like a collection.

Optional parameters:

ts time - The snapshot time at which to check for the document's existence. See TS() function.

Returns:

bool - true if the reference exists, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#read-functions

func Exp

func Exp(value interface{}) Expr

Exp computes the Exp of a number

Parameters:

value number - A number to compute the exp of

Returns:

number - The exp of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Filter

func Filter(coll, lambda interface{}) Expr

Filter applies the lambda expression on each element of a collection or Page. It returns a new collection of the same type containing only the elements in which the function application returned true.

Parameters:

coll []Value - The collection of elements to iterate.
lambda Lambda - A lambda function to be applied to each element of the collection. The lambda function must return a boolean value. See Lambda() function.

Returns:

[]Value - A new collection.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func FindStr

func FindStr(str, find interface{}, options ...OptionalParameter) Expr

FindStr locates a substring in a source string. Optional parameters: Start

Parameters:

str string  - The source string
find string - The string to locate

Optional parameters:

start int - a position to start the search. See Start() function.

Returns:

string - The offset of where the substring starts or -1 if not found

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func FindStrRegex

func FindStrRegex(str, pattern interface{}, options ...OptionalParameter) Expr

FindStrRegex locates a java regex pattern in a source string. Optional parameters: Start

Parameters:

str string      - The sourcestring
pattern string  - The pattern to locate.

Optional parameters:

start long - a position to start the search.  See Start() function.

Returns:

string - The offset of where the substring starts or -1 if not found

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Floor

func Floor(value interface{}) Expr

Floor computes the Floor of a number

Parameters:

value number - A number to compute the Floor of

Returns:

number - The Floor of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Foreach

func Foreach(coll, lambda interface{}) Expr

Foreach applies the lambda expression on each element of a collection or Page. The original collection is returned.

Parameters:

coll []Value - The collection of elements to iterate.
lambda Lambda - A lambda function to be applied to each element of the collection. See Lambda() function.

Returns:

[]Value - The original collection.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func Format

func Format(format interface{}, values ...interface{}) Expr

Format formats values into a string.

Parameters:

format string - format a string with format specifiers.

Optional parameters:

values []string - list of values to format into string.

Returns:

string - A string.

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Function

func Function(name interface{}) Expr

Function create a new function ref.

Parameters:

name string - The name of the functions.

Returns:

Ref - The function reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Functions

func Functions() Expr

Functions creates a native ref for functions.

Returns:

Ref - The reference of the function set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func GT

func GT(args ...interface{}) Expr

GT returns true if each specified value is greater than all subsequent values. Otherwise GT returns false. and false otherwise.

Parameters:

args []number - A collection of terms to compare.

Returns:

bool - true if all elements are greather than to each other from left to right.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func GTE

func GTE(args ...interface{}) Expr

GTE returns true if each specified value is greater than or equal to all subsequent values. Otherwise GTE returns false.

Parameters:

args []number - A collection of terms to compare.

Returns:

bool - true if all elements are greather than or equals to each other from left to right.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Get

func Get(ref interface{}, options ...OptionalParameter) Expr

Get retrieves the document identified by the provided ref. Optional parameters: TS.

Parameters:

ref Ref|SetRef - The reference to the object or a set reference.

Optional parameters:

ts time - The snapshot time at which to get the document. See TS() function.

Returns:

Object - The object requested.

See: https://app.fauna.com/documentation/reference/queryapi#read-functions

func HasCurrentIdentity

func HasCurrentIdentity() Expr

func HasCurrentToken

func HasCurrentToken() Expr

func HasIdentity

func HasIdentity() Expr

HasIdentity checks if the current key has an identity associated to it.

Returns:

bool - true if the current key has an identity, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#authentication

func Hour

func Hour(value interface{}) Expr

Hour returns a time expression's hour of the day, from 0 to 23.

Parameters:

value Object - The expression to convert.

Returns:

time - year.

func Hypot

func Hypot(a, b interface{}) Expr

Hypot computes the Hypotenuse of two numbers

Parameters:

a number - A side of a right triangle
b number - A side of a right triangle

Returns:

number - The hypotenuse of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Identify

func Identify(ref, password interface{}) Expr

Identify checks the given password against the provided ref's credentials.

Parameters:

ref Ref - The reference to check the password against.
password string - The credentials password to check.

Returns:

bool - true if the password is correct, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#authentication

func Identity

func Identity() Expr

Identity returns the document reference associated with the current key.

For example, the current key token created using:

Create(Tokens(), Obj{"document": someRef})

or via:

Login(someRef, Obj{"password":"sekrit"})

will return "someRef" as the result of this function.

Returns:

Ref - The reference associated with the current key.

See: https://app.fauna.com/documentation/reference/queryapi#authentication

func If

func If(cond, then, elze interface{}) Expr

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

Parameters:

cond bool - A boolean expression.
then Expr - The expression to run if condition is true.
elze Expr - The expression to run if condition is false.

Returns:

Value - The result of either then or elze expression.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func Index

func Index(name interface{}) Expr

Index creates a new index ref.

Parameters:

name string - The name of the index.

Returns:

Ref - The index reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Indexes

func Indexes() Expr

Indexes creates a native ref for indexes.

Returns:

Ref - The reference of the index set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Insert

func Insert(ref, ts, action, params interface{}) Expr

Insert adds an event to the provided document's history.

Parameters:

ref Ref - The reference to insert against.
ts time - The valid time of the inserted event.
action string - Whether the event shoulde be a ActionCreate, ActionUpdate or ActionDelete.

Returns:

Object - The deleted object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func Intersection

func Intersection(sets ...interface{}) Expr

Intersection returns the set of documents that are present in all of the specified sets.

Parameters:

sets []SetRef - A list of SetRef to intersect.

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func IsArray

func IsArray(expr interface{}) Expr

IsArray checks if the expression is an array

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is an array

func IsBoolean

func IsBoolean(expr interface{}) Expr

IsBoolean checks if the expression is a boolean

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a boolean

func IsBytes

func IsBytes(expr interface{}) Expr

IsBytes checks if the expression are bytes

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression are bytes

func IsCollection

func IsCollection(expr interface{}) Expr

IsCollection checks if the expression is a collection

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a collection

func IsCredentials

func IsCredentials(expr interface{}) Expr

IsCredentials checks if the expression is a credentials

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a credential

func IsDatabase

func IsDatabase(expr interface{}) Expr

IsDatabase checks if the expression is a database

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a database

func IsDate

func IsDate(expr interface{}) Expr

IsDate checks if the expression is a date

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a date

func IsDoc

func IsDoc(expr interface{}) Expr

IsDoc checks if the expression is a document

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a document

func IsDouble

func IsDouble(expr interface{}) Expr

IsDouble checks if the expression is a double

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a double

func IsEmpty

func IsEmpty(coll interface{}) Expr

IsEmpty returns true if the collection is the empty set, else false.

Parameters:

coll []Value - The collection of elements.

Returns:

bool - True if the collection is empty, else false.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func IsFunction

func IsFunction(expr interface{}) Expr

IsFunction checks if the expression is a function

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a function

func IsIndex

func IsIndex(expr interface{}) Expr

IsIndex checks if the expression is an index

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is an index

func IsInteger

func IsInteger(expr interface{}) Expr

IsInteger checks if the expression is an integer

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is an integer

func IsKey

func IsKey(expr interface{}) Expr

IsKey checks if the expression is a key

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a key

func IsLambda

func IsLambda(expr interface{}) Expr

IsLambda checks if the expression is a Lambda

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a Lambda

func IsNonEmpty

func IsNonEmpty(coll interface{}) Expr

IsNonEmpty returns false if the collection is the empty set, else true

Parameters:

coll []Value - The collection of elements.

Returns:

bool - True if the collection is not empty, else false.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func IsNull

func IsNull(expr interface{}) Expr

IsNull checks if the expression is null

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is null

func IsNumber

func IsNumber(expr interface{}) Expr

IsNumber checks if the expression is a number

Parameters:

expr Expr - The expression to check.

Returns:

bool      -  returns true if the expression is a number

func IsObject

func IsObject(expr interface{}) Expr

IsObject checks if the expression is an object

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is an object

func IsRef

func IsRef(expr interface{}) Expr

IsRef checks if the expression is a ref

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a ref

func IsRole

func IsRole(expr interface{}) Expr

IsRole checks if the expression is a role

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a role

func IsSet

func IsSet(expr interface{}) Expr

IsSet checks if the expression is a set

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a set

func IsString

func IsString(expr interface{}) Expr

IsString checks if the expression is a string

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a string

func IsTimestamp

func IsTimestamp(expr interface{}) Expr

IsTimestamp checks if the expression is a timestamp

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a timestamp

func IsToken

func IsToken(expr interface{}) Expr

IsToken checks if the expression is a token

Parameters:

expr Expr - The expression to check.

Returns:

bool         -  returns true if the expression is a token

func Join

func Join(source, target interface{}) Expr

Join derives a set of resources by applying each document in the source set to the target set.

Parameters:

source SetRef - A SetRef of the source set.
target Lambda - A Lambda that will accept each element of the source Set and return a Set.

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func KeyFromSecret

func KeyFromSecret(secret interface{}) Expr

KeyFromSecret retrieves the key object from the given secret.

Parameters:

secret string - The token secret.

Returns:

Key - The key object related to the token secret.

See: https://app.fauna.com/documentation/reference/queryapi#read-functions

func Keys

func Keys() Expr

Keys creates a native ref for keys.

Returns:

Ref - The reference of the key set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func LT

func LT(args ...interface{}) Expr

LT returns true if each specified value is less than all the subsequent values. Otherwise LT returns false.

Parameters:

args []number - A collection of terms to compare.

Returns:

bool - true if all elements are less than each other from left to right.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func LTE

func LTE(args ...interface{}) Expr

LTE returns true if each specified value is less than or equal to all subsequent values. Otherwise LTE returns false.

Parameters:

args []number - A collection of terms to compare.

Returns:

bool - true if all elements are less than of equals each other from left to right.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func LTrim

func LTrim(str interface{}) Expr

LTrim returns a string wtih leading white space removed.

Parameters:

str string - A string to remove leading white space

Returns:

string - A string with all leading white space removed

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Lambda

func Lambda(varName, expr interface{}) Expr

Lambda creates an anonymous function. Mostly used with Collection functions.

Parameters:

varName string|[]string - A string or an array of strings of arguments name to be bound in the body of the lambda.
expr Expr - An expression used as the body of the lambda.

Returns:

Value - The result of the body expression.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func Length

func Length(str interface{}) Expr

Length finds the length of a string in codepoints

Parameters:

str string - A string to find the length in codepoints

Returns:

int - A length of a string.

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Ln

func Ln(value interface{}) Expr

Ln computes the natural log of a number

Parameters:

value number - A number to compute the natural log of

Returns:

number - The ln of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Log

func Log(value interface{}) Expr

Log computes the Log of a number

Parameters:

value number - A number to compute the Log of

Returns:

number - The Log of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Login

func Login(ref, params interface{}) Expr

Login creates a token for the provided ref.

Parameters:

ref Ref - A reference with credentials to authenticate against.
params Object - An object of parameters to pass to the login function
  - password: The password used to login

Returns:

Key - a key with the secret to login.

See: https://app.fauna.com/documentation/reference/queryapi#authentication

func Logout

func Logout(invalidateAll interface{}) Expr

Logout deletes the current session token. If invalidateAll is true, logout will delete all tokens associated with the current session.

Parameters:

invalidateAll bool - If true, log out all tokens associated with the current session.

See: https://app.fauna.com/documentation/reference/queryapi#authentication

func LowerCase

func LowerCase(str interface{}) Expr

LowerCase changes all characters in the string to lowercase

Parameters:

str string - A string to convert to lowercase

Returns:

string - A string in lowercase.

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Map

func Map(coll, lambda interface{}) Expr

Map applies the lambda expression on each element of a collection or Page. It returns the result of each application on a collection of the same type.

Parameters:

coll []Value - The collection of elements to iterate.
lambda Lambda - A lambda function to be applied to each element of the collection. See Lambda() function.

Returns:

[]Value - A new collection with elements transformed by the lambda function.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func Match

func Match(ref interface{}) Expr

Match returns the set of documents for the specified index.

Parameters:

ref Ref - The reference of the index to match against.

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func MatchTerm

func MatchTerm(ref, terms interface{}) Expr

MatchTerm returns th set of documents that match the terms in an index.

Parameters:

ref Ref - The reference of the index to match against.
terms []Value - A list of terms used in the match.

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func Max

func Max(args ...interface{}) Expr

Max computes the max of a list of numbers.

Parameters:

args []number - A collection of numbers to find the max of.

Returns:

number - The max of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Mean

func Mean(collection interface{}) Expr

Mean returns the mean of all elements in the collection.

Parameters:

collection Expr - the collection

Returns: a new Expr instance

See: https://docs.fauna.com/fauna/current/api/fql/functions/mean

func Merge

func Merge(merge interface{}, with interface{}, lambda ...OptionalParameter) Expr

Merge two or more objects..

Parameters:

merge merge the first object.
with the second object or a list of objects
lambda a lambda to resolve possible conflicts

Returns: merged object

func Min

func Min(args ...interface{}) Expr

Min computes the Min of a list of numbers.

Parameters:

args []number - A collection of numbers to find the min of.

Returns:

number - The min of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Minute

func Minute(value interface{}) Expr

Minute returns a time expression's minute of the hour, from 0 to 59.

Parameters:

value Object - The expression to convert.

Returns:

time - year.

func Modulo

func Modulo(args ...interface{}) Expr

Modulo computes the reminder after the division of a list of numbers.

Parameters:

args []number - A collection of numbers to compute the quotient of. The remainder will be returned.

Returns:

number - The remainder of the quotient of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Month

func Month(value interface{}) Expr

Month returns a time expression's month of the year, from 1 to 12.

Parameters:

value Object - The expression to convert.

Returns:

time - Month.

func MoveDatabase

func MoveDatabase(from interface{}, to interface{}) Expr

MoveDatabase moves a database to a new hierachy.

Parameters:

from Object - Source reference to be moved.
to Object   - New parent database reference.

Returns:

Object - instance.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func Multiply

func Multiply(args ...interface{}) Expr

Multiply computes the product of a list of numbers.

Parameters:

args []number - A collection of numbers to multiply together.

Returns:

number - The multiplication of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func NewId

func NewId() Expr

NewId produces a new identifier suitable for use when constructing refs.

Returns:

string - The new ID.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func NextID deprecated

func NextID() Expr

NextID produces a new identifier suitable for use when constructing refs.

Deprecated: Use NewId instead

Returns:

string - The new ID.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Not

func Not(boolean interface{}) Expr

Not returns the negation of a boolean value.

Parameters:

boolean bool - A boolean to produce the negation of.

Returns:

bool - The value negated.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Now

func Now() Expr

Now returns the current snapshot time.

Returns: Expr

See: https://docs.fauna.com/fauna/current/api/fql/functions/now

func Null

func Null() Expr

Null creates a NullV value.

Returns:

Value - A null value.

See: https://app.fauna.com/documentation/reference/queryapi#simple-type

func Or

func Or(args ...interface{}) Expr

Or returns the disjunction of a list of boolean values.

Parameters:

args []bool - A collection to compute the disjunction of.

Returns:

bool - true if at least one element is true, false otherwise.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Paginate

func Paginate(set interface{}, options ...OptionalParameter) Expr

Paginate retrieves a page from the provided set.

Parameters:

set SetRef - A set reference to paginate over. See Match() or MatchTerm() functions.

Optional parameters:

after Cursor - Return the next page of results after this cursor (inclusive). See After() function.
before Cursor - Return the previous page of results before this cursor (exclusive). See Before() function.
sources bool - If true, include the source sets along with each element. See Sources() function.
ts time - The snapshot time at which to get the document. See TS() function.

Returns:

Page - A page of elements.

See: https://app.fauna.com/documentation/reference/queryapi#read-functions

func Pow

func Pow(base, exp interface{}) Expr

Pow computes the Power of a number

Parameters:

base number - A number which is the base
exp number  - A number which is the exponent

Returns:

number - The Pow of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Prepend

func Prepend(elems, coll interface{}) Expr

Prepend returns a new collection that is the result of prepending elems to coll.

Parameters:

elems []Value - Elements to add to the beginning of the other collection.
coll []Value - The collection of elements.

Returns:

[]Value - A new collection.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func Query

func Query(lambda interface{}) Expr

Query creates an instance of the @query type with the specified lambda

Parameters:

lambda Lambda - A lambda representation. See Lambda() function.

Returns:

Query - The lambda wrapped in a @query type.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func RTrim

func RTrim(str interface{}) Expr

RTrim returns a string wtih trailing white space removed.

Parameters:

str string - A string to remove trailing white space

Returns:

string - A string with all trailing white space removed

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Radians

func Radians(value interface{}) Expr

Radians computes the Radians of a number

Parameters:

value number - A number which is convert to radians

Returns:

number - The Radians of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Range

func Range(set interface{}, from interface{}, to interface{}) Expr

Range filters the set based on the lower/upper bounds (inclusive).

Parameters:

set SetRef - Set to be filtered.
from - lower bound.
to - upper bound

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func Reduce

func Reduce(lambda, initial interface{}, collection interface{}) Expr

Reduce function applies a reducer Lambda function serially to each member of the collection to produce a single value.

Parameters: lambda Expr - The accumulator function initial Expr - The initial value collection Expr - The collection to be reduced

Returns: Expr

See: https://docs.fauna.com/fauna/current/api/fql/functions/reduce

func Ref

func Ref(idOrRef interface{}, id ...interface{}) Expr

Ref creates a new RefV value with the provided ID.

Parameters:

idOrRef Ref - A class reference or string repr to reference type.
id string - The document ID.

Returns:

Ref - A new reference type.

See: https://app.fauna.com/documentation/reference/queryapi#special-type

func RefClass deprecated

func RefClass(classRef, id interface{}) Expr

RefClass creates a new Ref based on the provided class and ID.

Parameters:

classRef Ref - A class reference.
id string|int64 - The document ID.

Deprecated: Use RefCollection instead, RefClass is kept for backwards compatibility

Returns:

Ref - A new reference type.

See: https://app.fauna.com/documentation/reference/queryapi#special-type

func RefCollection

func RefCollection(collectionRef, id interface{}) Expr

RefCollection creates a new Ref based on the provided collection and ID.

Parameters:

collectionRef Ref - A collection reference.
id string|int64 - The document ID.

Returns:

Ref - A new reference type.

See: https://app.fauna.com/documentation/reference/queryapi#special-type

func RegexEscape

func RegexEscape(value interface{}) Expr

RegexEscape It takes a string and returns a regex which matches the input string verbatim.

Parameters:

value string - the string to analyze pattern - the pattern to search for

Returns: boolean - was the search result found

See https://docs.fauna.com/fauna/current/api/fql/functions/regexescape

func Remove

func Remove(ref, ts, action interface{}) Expr

Remove deletes an event from the provided document's history.

Parameters:

ref Ref - The reference of the document whose event should be removed.
ts time - The valid time of the inserted event.
action string - The event action (ActionCreate, ActionUpdate or ActionDelete) that should be removed.

Returns:

Object - The deleted object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func Repeat

func Repeat(str interface{}, options ...OptionalParameter) Expr

Repeat returns a string wtih repeated n times

Parameters:

str string - A string to repeat
number int - The number of times to repeat the string

Optional parameters:

Number - Only replace the first found pattern.  See OnlyFirst() function.

Returns:

string - A string concatendanted the specified number of times

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Replace

func Replace(ref, params interface{}) Expr

Replace replaces the provided document.

Parameters:

ref Ref - The reference to replace.
params Object - An object representing the parameters of the document.

Returns:

Object - The replaced object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func ReplaceStr

func ReplaceStr(str, find, replace interface{}) Expr

ReplaceStr returns a string with every occurence of the "find" string changed to "replace" string

Parameters:

str string     - A source string
find string    - The substring to locate in in the source string
replace string - The string to replaice the "find" string when located

Returns:

string - returns a string with every occurence of the "find" string changed to "replace"

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func ReplaceStrRegex

func ReplaceStrRegex(value, pattern, replace interface{}, options ...OptionalParameter) Expr

ReplaceStrRegex returns a string with occurence(s) of the java regular expression "pattern" changed to "replace" string. Optional parameters: OnlyFirst

Parameters:

value string   - The source string
pattern string - A java regular expression to locate
replace string - The string to replace the pattern when located

Optional parameters:

OnlyFirst - Only replace the first found pattern.  See OnlyFirst() function.

Returns:

string - A string with occurence(s) of the java regular expression "pattern" changed to "replace" string

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Reverse

func Reverse(collection interface{}) Expr

Reverse accepts a set, array or page and returns the same type with elements in reversed order.

Parameters:

collection Expr - the collection

Returns: a new Expr instance

See: https://docs.fauna.com/fauna/current/api/fql/functions/reverse

func Role

func Role(name interface{}) Expr

Role create a new role ref.

Parameters:

name string - The name of the role.

Returns:

Ref - The role reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Roles

func Roles() Expr

Roles creates a native ref for roles.

Returns:

Ref - The reference of the roles set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Round

func Round(value interface{}, options ...OptionalParameter) Expr

Round a number at the given percission

Parameters:

value number - The number to truncate
precision number - precision where to truncate, defaults is 2

Returns:

number - The Rounded value.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func ScopedAccessProvider

func ScopedAccessProvider(name interface{}, scope interface{}) Expr

ScopedAccessProvider create a new access provider ref.

Parameters:

name string - The name of the access provider.
scope Ref - The reference of the scope.

Returns:

Ref - The access provider reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedAccessProviders

func ScopedAccessProviders(scope interface{}) Expr

ScopedAccessProviders creates a native ref for access providers inside a database.

Parameters:

scope Ref - The reference of the access provider's set scope.

Returns:

Ref - The reference of the access providers set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedClass deprecated

func ScopedClass(name interface{}, scope interface{}) Expr

ScopedClass creates a new class ref inside a database.

Parameters:

name string - The name of the class.
scope Ref - The reference of the class's scope.

Deprecated: Use ScopedCollection instead, ScopedClass is kept for backwards compatibility

Returns:

Ref - The collection reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedClasses deprecated

func ScopedClasses(scope interface{}) Expr

ScopedClasses creates a native ref for classes inside a database.

Parameters:

scope Ref - The reference of the class set's scope.

Deprecated: Use ScopedCollections instead, ScopedClasses is kept for backwards compatibility

Returns:

Ref - The reference of the class set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedCollection

func ScopedCollection(name interface{}, scope interface{}) Expr

ScopedCollection creates a new collection ref inside a database.

Parameters:

name string - The name of the collection.
scope Ref - The reference of the collection's scope.

Returns:

Ref - The collection reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedCollections

func ScopedCollections(scope interface{}) Expr

ScopedCollections creates a native ref for collections inside a database.

Parameters:

scope Ref - The reference of the collections set's scope.

Returns:

Ref - The reference of the collections set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedCredentials

func ScopedCredentials(scope interface{}) Expr

ScopedCredentials creates a native ref for credentials inside a database.

Parameters:

scope Ref - The reference of the credential set's scope.

Returns:

Ref - The reference of the credential set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedDatabase

func ScopedDatabase(name interface{}, scope interface{}) Expr

ScopedDatabase creates a new database ref inside a database.

Parameters:

name string - The name of the database.
scope Ref - The reference of the database's scope.

Returns:

Ref - The database reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedDatabases

func ScopedDatabases(scope interface{}) Expr

ScopedDatabases creates a native ref for databases inside a database.

Parameters:

scope Ref - The reference of the database set's scope.

Returns:

Ref - The reference of the database set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedFunction

func ScopedFunction(name interface{}, scope interface{}) Expr

ScopedFunction creates a new function ref inside a database.

Parameters:

name string - The name of the function.
scope Ref - The reference of the function's scope.

Returns:

Ref - The function reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedFunctions

func ScopedFunctions(scope interface{}) Expr

ScopedFunctions creates a native ref for functions inside a database.

Parameters:

scope Ref - The reference of the function set's scope.

Returns:

Ref - The reference of the function set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedIndex

func ScopedIndex(name interface{}, scope interface{}) Expr

ScopedIndex creates a new index ref inside a database.

Parameters:

name string - The name of the index.
scope Ref - The reference of the index's scope.

Returns:

Ref - The index reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedIndexes

func ScopedIndexes(scope interface{}) Expr

ScopedIndexes creates a native ref for indexes inside a database.

Parameters:

scope Ref - The reference of the index set's scope.

Returns:

Ref - The reference of the index set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedKeys

func ScopedKeys(scope interface{}) Expr

ScopedKeys creates a native ref for keys inside a database.

Parameters:

scope Ref - The reference of the key set's scope.

Returns:

Ref - The reference of the key set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedRole

func ScopedRole(name, scope interface{}) Expr

ScopedRole create a new role ref.

Parameters:

name string - The name of the role.
scope Ref - The reference of the role's scope.

Returns:

Ref - The role reference.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedRoles

func ScopedRoles(scope interface{}) Expr

ScopedRoles creates a native ref for roles inside a database.

Parameters:

scope Ref - The reference of the role set's scope.

Returns:

Ref - The reference of the role set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func ScopedTokens

func ScopedTokens(scope interface{}) Expr

ScopedTokens creates a native ref for tokens inside a database.

Parameters:

scope Ref - The reference of the token set's scope.

Returns:

Ref - The reference of the token set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Second

func Second(value interface{}) Expr

Second returns a time expression's second of the minute, from 0 to 59.

Parameters:

value Object - The expression to convert.

Returns:

time - year.

func Select

func Select(path, value interface{}, options ...OptionalParameter) Expr

Select traverses into the provided value, returning the value at the given path.

Parameters:

path []Path - An array representing a path to pull from an object. Path can be either strings or numbers.
value Object - The object to select from.

Optional parameters:

default Value - A default value if the path does not exist. See Default() function.

Returns:

Value - The value at the given path location.

See: https://app.fauna.com/documentation/reference/queryapi#read-functions

func SelectAll

func SelectAll(path, value interface{}) Expr

SelectAll traverses into the provided value flattening all values under the desired path.

Parameters:

path []Path - An array representing a path to pull from an object. Path can be either strings or numbers.
value Object - The object to select from.

Returns:

Value - The value at the given path location.

See: https://app.fauna.com/documentation/reference/queryapi#read-functions

func Sign

func Sign(value interface{}) Expr

Sign computes the Sign of a number

Parameters:

value number - A number to compute the Sign of

Returns:

number - The Sign of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Sin

func Sin(value interface{}) Expr

Sin computes the Sine of a number

Parameters:

value number - A number to compute the Sine of

Returns:

number - The Sine of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Singleton

func Singleton(ref interface{}) Expr

Singleton returns the history of the document's presence of the provided ref.

Parameters:

ref Ref - The reference of the document for which to retrieve the singleton set.

Returns:

SetRef - The singleton SetRef.

See: https://app.fauna.com/documentation/reference/queryapi#sets

func Sinh

func Sinh(value interface{}) Expr

Sinh computes the Hyperbolic Sine of a number

Parameters:

value number - A number to compute the Hyperbolic Sine of

Returns:

number - The Hyperbolic Sine of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Space

func Space(value interface{}) Expr

Space function returns "N" number of spaces

Parameters:

value int - the number of spaces

Returns:

string - function returns string with n spaces

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Sqrt

func Sqrt(value interface{}) Expr

Sqrt computes the square root of a number

Parameters:

value number - A number to compute the square root of

Returns:

number - The square root of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func StartsWith

func StartsWith(value interface{}, search interface{}) Expr

StartsWith returns true if the string starts with the given prefix value, or false if otherwise

Parameters:

value  string -  the string to evaluate
search string -  the prefix to search for

Returns:

boolean       - does `value` start with `search

See https://docs.fauna.com/fauna/current/api/fql/functions/startswith

func SubString

func SubString(str, start interface{}, options ...OptionalParameter) Expr

SubString returns a subset of the source string. Optional parameters: StrLength

Parameters:

str string - A source string
start int  - The position in the source string where SubString starts extracting characters

Optional parameters:

StrLength int - A value for the length of the extracted substring. See StrLength() function.

Returns:

string - function returns a subset of the source string

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Subtract

func Subtract(args ...interface{}) Expr

Subtract computes the difference of a list of numbers.

Parameters:

args []number - A collection of numbers to compute the difference of.

Returns:

number - The difference of all elements.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Sum

func Sum(collection interface{}) Expr

Sum sums the elements in the collection.

Parameters: collection Expr - the collection

Returns: a new Expr instance

See: https://docs.fauna.com/fauna/current/api/fql/functions/sum

func Take

func Take(num, coll interface{}) Expr

Take returns a new collection containing num elements from the head of the original collection.

Parameters:

num int64 - The number of elements to take from the collection.
coll []Value - The collection of elements.

Returns:

[]Value - A new collection.

See: https://app.fauna.com/documentation/reference/queryapi#collections

func Tan

func Tan(value interface{}) Expr

Tan computes the Tangent of a number

Parameters:

value number - A number to compute the Tangent of

Returns:

number - The Tangent of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Tanh

func Tanh(value interface{}) Expr

Tanh computes the Hyperbolic Tangent of a number

Parameters:

value number - A number to compute the Hyperbolic Tangent of

Returns:

number - The Hyperbolic Tangent of value

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Time

func Time(str interface{}) Expr

Time constructs a time from a ISO 8601 offset date/time string.

Parameters:

str string - A string to convert to a time object.

Returns:

time - A time object.

See: https://app.fauna.com/documentation/reference/queryapi#time-and-date

func TimeAdd

func TimeAdd(base interface{}, offset interface{}, unit interface{}) Expr

TimeAdd returns a new time or date with the offset in terms of the unit added.

Parameters: base - the base time or data offset - the number of units unit - the unit type

Returns: Expr

See: https://docs.fauna.com/fauna/current/api/fql/functions/timeadd

func TimeDiff

func TimeDiff(start interface{}, finish interface{}, unit interface{}) Expr

TimeDiff returns the number of intervals in terms of the unit between two times or dates. Both start and finish must be of the same type.

Parameters:

start the starting time or date, inclusive
finish the ending time or date, exclusive
unit the unit type//

Returns: Expr

See: https://docs.fauna.com/fauna/current/api/fql/functions/timediff

func TimeSubtract

func TimeSubtract(base interface{}, offset interface{}, unit interface{}) Expr

TimeSubtract returns a new time or date with the offset in terms of the unit subtracted.

Parameters: base - the base time or data offset - the number of units unit - the unit type

Returns: Expr

See: https://docs.fauna.com/fauna/current/api/fql/functions/timesubtract

func TitleCase

func TitleCase(str interface{}) Expr

TitleCase changes all characters in the string to TitleCase

Parameters:

str string - A string to convert to TitleCase

Returns:

string - A string in TitleCase.

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func ToArray

func ToArray(value interface{}) Expr

ToArray attempts to convert an expression to an array

Parameters:

value Object - The expression to convert.

Returns:

array - An array.

func ToDate

func ToDate(value interface{}) Expr

ToDate attempts to convert an expression to a date literal.

Parameters:

value Object - The expression to convert.

Returns:

date - A date literal.

func ToDouble

func ToDouble(value interface{}) Expr

ToDouble attempts to convert an expression to a double

Parameters:

value Object - The expression to convert.

Returns:

number - A double literal.

func ToInteger

func ToInteger(value interface{}) Expr

ToInteger attempts to convert an expression to an integer literal

Parameters:

value Object - The expression to convert.

Returns:

number - An integer literal.

func ToMicros

func ToMicros(value interface{}) Expr

ToMicros converts a time expression to microseconds since the UNIX epoch.

Parameters:

value Object - The expression to convert.

Returns:

time - A time literal.

func ToMillis

func ToMillis(value interface{}) Expr

ToMillis converts a time expression to milliseconds since the UNIX epoch.

Parameters:

value Object - The expression to convert.

Returns:

time - A time literal.

func ToNumber

func ToNumber(value interface{}) Expr

ToNumber attempts to convert an expression to a numeric literal - either an int64 or float64.

Parameters:

value Object - The expression to convert.

Returns:

number - A numeric literal.

func ToObject

func ToObject(value interface{}) Expr

ToObject attempts to convert an expression to an object

Parameters:

value Object - The expression to convert.

Returns:

object - An object.

func ToSeconds

func ToSeconds(value interface{}) Expr

ToSeconds converts a time expression to seconds since the UNIX epoch.

Parameters:

value Object - The expression to convert.

Returns:

time - A time literal.

func ToString

func ToString(value interface{}) Expr

ToString attempts to convert an expression to a string literal.

Parameters:

value Object - The expression to convert.

Returns:

string - A string literal.

func ToTime

func ToTime(value interface{}) Expr

ToTime attempts to convert an expression to a time literal.

Parameters:

value Object - The expression to convert.

Returns:

time - A time literal.

func Tokens

func Tokens() Expr

Tokens creates a native ref for tokens.

Returns:

Ref - The reference of the token set.

See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions

func Trim

func Trim(str interface{}) Expr

Trim returns a string wtih trailing white space removed.

Parameters:

str string - A string to remove trailing white space

Returns:

string - A string with all trailing white space removed

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Trunc

func Trunc(value interface{}, options ...OptionalParameter) Expr

Trunc truncates a number at the given percission

Parameters:

value number - The number to truncate
precision number - precision where to truncate, defaults is 2

Returns:

number - The truncated value.

See: https://app.fauna.com/documentation/reference/queryapi#mathematical-functions

func Union

func Union(sets ...interface{}) Expr

Union returns the set of documents that are present in at least one of the specified sets.

Parameters:

sets []SetRef - A list of SetRef to union together.

Returns:

SetRef

See: https://app.fauna.com/documentation/reference/queryapi#sets

func Update

func Update(ref, params interface{}) Expr

Update updates the provided document.

Parameters:

ref Ref - The reference to update.
params Object - An object representing the parameters of the document.

Returns:

Object - The updated object.

See: https://app.fauna.com/documentation/reference/queryapi#write-functions

func UpperCase

func UpperCase(str interface{}) Expr

UpperCase changes all characters in the string to uppercase

Parameters:

string - A string to convert to uppercase

Returns:

string - A string in uppercase.

See: https://app.fauna.com/documentation/reference/queryapi#string-functions

func Var

func Var(name string) Expr

Var refers to a value of a variable on the current lexical scope.

Parameters:

name string - The variable name.

Returns:

Value - The variable value.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func Year

func Year(value interface{}) Expr

Year returns the time expression's year, following the ISO-8601 standard.

Parameters:

value Object - The expression to convert.

Returns:

time - year.

type FaunaClient

type FaunaClient struct {
	// contains filtered or unexported fields
}

FaunaClient provides methods for performing queries on a FaunaDB cluster.

This structure should be reused as much as possible. Avoid copying this structure. If you need to create a client with a different secret, use the NewSessionClient method.

func NewFaunaClient

func NewFaunaClient(secret string, configs ...ClientConfig) *FaunaClient

NewFaunaClient creates a new FaunaClient structure. Possible configuration options:

Endpoint: sets a specific FaunaDB url. Default: https://db.fauna.com
HTTP: sets a specific http.Client. Default: a new net.Client with 60 seconds timeout.

func (*FaunaClient) BatchQuery

func (client *FaunaClient) BatchQuery(exprs []Expr) (values []Value, err error)

BatchQuery will sends multiple simultaneous queries to FaunaDB. values are returned in the same order as the queries.

func (*FaunaClient) BatchQueryResult

func (client *FaunaClient) BatchQueryResult(expr []Expr) (value []Value, headers map[string][]string, err error)

BatchQueryResult run and return the cost headers associated with this query.

func (*FaunaClient) GetLastTxnTime

func (client *FaunaClient) GetLastTxnTime() int64

GetLastTxnTime gets the freshest timestamp reported to this client.

func (*FaunaClient) NewSessionClient

func (client *FaunaClient) NewSessionClient(secret string) *FaunaClient

NewSessionClient creates a new child FaunaClient with a new secret. The returned client reuses its parent's internal http resources.

func (*FaunaClient) NewWithObserver

func (client *FaunaClient) NewWithObserver(observer ObserverCallback) *FaunaClient

NewWithObserver creates a new FaunaClient with a specific observer callback. The returned client reuses its parent's internal http resources.

func (*FaunaClient) Query

func (client *FaunaClient) Query(expr Expr, configs ...QueryConfig) (value Value, err error)

Query is the primary method used to send a query language expression to FaunaDB.

func (*FaunaClient) QueryResult

func (client *FaunaClient) QueryResult(expr Expr) (value Value, headers map[string][]string, err error)

QueryResult run and return the cost headers associated with this query.

func (*FaunaClient) Stream

func (client *FaunaClient) Stream(query Expr, config ...StreamConfig) StreamSubscription

Stream creates a stream subscription to the result of the given expression.

The subscription returned by this method does not issue any requests until the subscription's Start method is called. Make sure to subscribe to the events of interest, otherwise the received events are simply ignored.

func (*FaunaClient) SyncLastTxnTime

func (client *FaunaClient) SyncLastTxnTime(newTxnTime int64)

SyncLastTxnTime syncs the freshest timestamp seen by this client. This has no effect if more stale than the currently stored timestamp. WARNING: This should be used only when coordinating timestamps across

multiple clients. Moving the timestamp arbitrarily forward into
the future will cause transactions to stall.

type FaunaError

type FaunaError interface {
	error
	Status() int          // HTTP status code
	Errors() []QueryError // Errors returned by the server
}

A FaunaError wraps HTTP errors when sending queries to a FaunaDB cluster.

type Field

type Field struct {
	// contains filtered or unexported fields
}

Field is a field extractor for FaunaDB values.

func ArrIndex

func ArrIndex(indexes ...int) Field

ArrIndex creates a field extractor for a JSON array based on the provided indexes.

func ObjKey

func ObjKey(keys ...string) Field

ObjKey creates a field extractor for a JSON object based on the provided keys.

func (Field) At

func (f Field) At(other Field) Field

At creates a new field extractor based on the provided path.

func (Field) AtIndex

func (f Field) AtIndex(indexes ...int) Field

AtIndex creates a new field extractor based on the provided index.

func (Field) AtKey

func (f Field) AtKey(keys ...string) Field

AtKey creates a new field extractor based on the provided key.

type FieldValue

type FieldValue interface {
	GetValue() (Value, error) // GetValue returns the extracted FaunaDB value.
	Get(i interface{}) error  // Get decodes a FaunaDB value to a native Go type.
}

FieldValue describes an extracted field value.

type HistoryRewriteEvent

type HistoryRewriteEvent struct {
	StreamEvent
	// contains filtered or unexported fields
}

HistoryRewriteEvent represents a history rewrite event which occurs upon any modifications to the history of the subscribed document.

func (HistoryRewriteEvent) Event

func (event HistoryRewriteEvent) Event() Value

Event returns the stream event as a `Value`

func (HistoryRewriteEvent) String

func (event HistoryRewriteEvent) String() string

func (HistoryRewriteEvent) Txn

func (event HistoryRewriteEvent) Txn() int64

Txn returns the stream event timestamp

func (HistoryRewriteEvent) Type

func (event HistoryRewriteEvent) Type() StreamEventType

Type returns the stream event type

type InternalError

type InternalError struct{ FaunaError }

A InternalError wraps an HTTP 500 error response.

type InvalidFieldType

type InvalidFieldType struct {
	// contains filtered or unexported fields
}

InvalidFieldType describes an error that may occurs when extracting a field. InvalidFieldType will occur in the following cases: * When trying to extract a field by key from a something that is not an object, or * When trying to extract a field by index from something that is not an array.

func (InvalidFieldType) Error

func (i InvalidFieldType) Error() string

type LetBuilder

type LetBuilder struct {
	// contains filtered or unexported fields
}

LetBuilder builds Let expressions

func Let

func Let() *LetBuilder

Let binds values to one or more variables.

Returns:

*LetBuilder - Returns a LetBuilder.

See: https://app.fauna.com/documentation/reference/queryapi#basic-forms

func (*LetBuilder) Bind

func (lb *LetBuilder) Bind(key string, in interface{}) *LetBuilder

Bind binds a variable name to a value and returns a LetBuilder

func (*LetBuilder) In

func (lb *LetBuilder) In(in Expr) Expr

In sets the expression to be evaluated and returns the prepared Let.

type LongV

type LongV int64

LongV represents a valid JSON number.

func (LongV) At

func (num LongV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since LongV is not traversable.

func (LongV) Get

func (num LongV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a LongV or a numeric type.

type NotFound

type NotFound struct{ FaunaError }

A NotFound wraps an HTTP 404 error response.

type NullV

type NullV struct{}

NullV represents a valid JSON null.

func (NullV) At

func (null NullV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since NullV is not traversable.

func (NullV) Get

func (null NullV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to a either a NullV or a nil pointer.

func (NullV) MarshalJSON

func (null NullV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to JSON null representation.

type Obj

type Obj map[string]interface{}

Obj is a expression shortcut to represent any valid JSON object

func (Obj) MarshalJSON

func (obj Obj) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Obj expression

type ObjectV

type ObjectV map[string]Value

ObjectV represents a FaunaDB object type.

func (ObjectV) At

func (obj ObjectV) At(field Field) FieldValue

At implements the Value interface by traversing the object and extracting the provided field.

func (ObjectV) Get

func (obj ObjectV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a ObjectV or a native map type.

func (ObjectV) MarshalJSON

func (obj ObjectV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB object representation.

type ObserverCallback

type ObserverCallback func(*QueryResult)

ObserverCallback is the callback type for requests.

type OptionalParameter

type OptionalParameter func(Expr) Expr

OptionalParameter describes optional parameters for query language functions

func After

func After(ref interface{}) OptionalParameter

After is an optional parameter used when cursoring that refers to the specified cursor's the next page, inclusive. For more information about pages, check https://app.fauna.com/documentation/reference/queryapi#simple-type-pages.

Functions that accept this optional parameter are: Paginate.

func Before

func Before(ref interface{}) OptionalParameter

Before is an optional parameter used when cursoring that refers to the specified cursor's previous page, exclusive. For more information about pages, check https://app.fauna.com/documentation/reference/queryapi#simple-type-pages.

Functions that accept this optional parameter are: Paginate.

func ConflictResolver

func ConflictResolver(lambda interface{}) OptionalParameter

ConflictResolver is an optional parameter that specifies the lambda for resolving Merge conflicts

Functions that accept this optional parameter are: Merge

func Cursor added in v4.1.0

func Cursor(ref interface{}) OptionalParameter

func Default

func Default(value interface{}) OptionalParameter

Default is an optional parameter that specifies the default value for a select operation when the desired value path is absent.

Functions that accept this optional parameter are: Select.

func EventsOpt deprecated

func EventsOpt(events interface{}) OptionalParameter

EventsOpt is an boolean optional parameter that describes if the query should include historical events. For more information about events, check https://app.fauna.com/documentation/reference/queryapi#simple-type-events.

Functions that accept this optional parameter are: Paginate.

Deprecated: The Events function was renamed to EventsOpt to support the new history API. EventsOpt is provided here for backwards compatibility. Instead of using Paginate with the EventsOpt parameter, you should use the new Events function.

func Normalizer

func Normalizer(norm interface{}) OptionalParameter

Normalizer is a string optional parameter that specifies the normalization function for casefold operation.

Functions that accept this optional parameter are: Casefold.

func NumResults

func NumResults(num interface{}) OptionalParameter

NumResults is a numeric optional parameter that specifies the number of results returned.

Functions that accept this optional parameter are: FindStrRegex.

func Number

func Number(num interface{}) OptionalParameter

Number is a numeric optional parameter that specifies an optional number.

Functions that accept this optional parameter are: Repeat.

func OnlyFirst

func OnlyFirst() OptionalParameter

OnlyFirst is a boolean optional parameter that only replace the first string

Functions that accept this optional parameter are: ReplaceStrRegex

func Precision

func Precision(precision interface{}) OptionalParameter

Precision is an optional parameter that specifies the precision for a Trunc and Round operations.

Functions that accept this optional parameter are: Round and Trunc.

func Separator

func Separator(sep interface{}) OptionalParameter

Separator is a string optional parameter that specifies the separator for a concat operation.

Functions that accept this optional parameter are: Concat.

func Size

func Size(size interface{}) OptionalParameter

Size is a numeric optional parameter that specifies the size of a pagination cursor.

Functions that accept this optional parameter are: Paginate.

func Sources

func Sources(sources interface{}) OptionalParameter

Sources is a boolean optional parameter that specifies if a pagination cursor should include the source sets along with each element.

Functions that accept this optional parameter are: Paginate.

func Start

func Start(start interface{}) OptionalParameter

Start is a numeric optional parameter that specifies the start of where to search.

Functions that accept this optional parameter are: FindStr .

func StrLength

func StrLength(length interface{}) OptionalParameter

StrLength is a numeric optional parameter that specifies the amount to copy.

Functions that accept this optional parameter are: FindStr and FindStrRegex.

func TS

func TS(timestamp interface{}) OptionalParameter

TS is a timestamp optional parameter that specifies in which timestamp a query should be executed.

Functions that accept this optional parameter are: Get, Exists, and Paginate.

type PermissionDenied

type PermissionDenied struct{ FaunaError }

A PermissionDenied wraps an HTTP 403 error response.

type QueryConfig

type QueryConfig func(*faunaRequest)

QueryConfig is the base type for query specific configuration parameters.

func Tag added in v4.3.0

func Tag(key string, value string) QueryConfig

func Traceparent added in v4.3.0

func Traceparent(tp string) QueryConfig

type QueryError

type QueryError struct {
	Position    []string            `fauna:"position"`
	Code        string              `fauna:"code"`
	Description string              `fauna:"description"`
	Cause       []ValidationFailure `fauna:"cause"`
}

QueryError describes query errors returned by the server.

type QueryResult

type QueryResult struct {
	Client     *FaunaClient
	Query      Expr
	Result     Value
	Event      StreamEvent
	Streaming  bool
	StatusCode int
	Headers    map[string][]string
	StartTime  time.Time
	EndTime    time.Time
}

QueryResult is a structure containing the result context for a given FaunaDB query.

type QueryV

type QueryV struct {
	// contains filtered or unexported fields
}

QueryV represents a `@query` value in FaunaDB.

func (QueryV) At

func (query QueryV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since QueryV is not traversable.

func (QueryV) Get

func (query QueryV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to a QueryV.

func (QueryV) MarshalJSON

func (query QueryV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB query representation.

type RefV

type RefV struct {
	ID         string
	Collection *RefV
	Class      *RefV //Deprecated: As of 2.7 Class is deprecated, use Collection instead
	Database   *RefV
}

RefV represents a FaunaDB ref type.

func NativeClasses

func NativeClasses() *RefV

func NativeCollections

func NativeCollections() *RefV

func NativeCredentials

func NativeCredentials() *RefV

func NativeDatabases

func NativeDatabases() *RefV

func NativeFunctions

func NativeFunctions() *RefV

func NativeIndexes

func NativeIndexes() *RefV

func NativeKeys

func NativeKeys() *RefV

func NativeRoles

func NativeRoles() *RefV

func NativeTokens

func NativeTokens() *RefV

func (RefV) At

func (ref RefV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since RefV is not traversable.

func (RefV) Get

func (ref RefV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying ref to a RefV.

func (RefV) MarshalJSON

func (ref RefV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB ref representation.

type SetEvent added in v4.2.0

type SetEvent struct {
	StreamEvent
	// contains filtered or unexported fields
}

VersionEvent represents a version event that occurs upon any modifications to the current state of the subscribed document.

func (SetEvent) Event added in v4.2.0

func (event SetEvent) Event() Value

Event returns the stream event as a `Value`

func (SetEvent) String added in v4.2.0

func (event SetEvent) String() string

func (SetEvent) Txn added in v4.2.0

func (event SetEvent) Txn() int64

Txn returns the stream event timestamp

func (SetEvent) Type added in v4.2.0

func (event SetEvent) Type() StreamEventType

Type returns the stream event type

type SetRefV

type SetRefV struct {
	Parameters map[string]Value
}

SetRefV represents a FaunaDB setref type.

func (SetRefV) At

func (set SetRefV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since SetRefV is not traversable.

func (SetRefV) Get

func (set SetRefV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to a SetRefV.

func (SetRefV) MarshalJSON

func (set SetRefV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB setref representation.

type StartEvent

type StartEvent struct {
	StreamEvent
	// contains filtered or unexported fields
}

StartEvent emitted when a valid stream subscription begins. Upcoming events are guaranteed to have transaction timestamps equal to or greater than the stream's start timestamp.

func (StartEvent) Event

func (event StartEvent) Event() Value

Event returns the stream event as a `f.Value`

func (StartEvent) String

func (event StartEvent) String() string

func (StartEvent) Txn

func (event StartEvent) Txn() int64

Txn returns the stream event timestamp

func (StartEvent) Type

func (event StartEvent) Type() StreamEventType

Type returns the stream event type

type StreamConfig

type StreamConfig func(*StreamSubscription)

StreamConfig describes optional parameters for a stream subscription

func Fields

func Fields(fields ...StreamField) StreamConfig

Fields is optional stream parameter that describes the fields received on version and history_rewrite stream events.

type StreamConnectionStatus

type StreamConnectionStatus int

StreamConnectionStatus is a expression shortcut to represent the stream connection status

const (
	// StreamConnIdle represents an idle stream subscription
	StreamConnIdle StreamConnectionStatus = iota
	// StreamConnActive describes an active/established stream subscription
	StreamConnActive
	// StreamConnClosed describes a closed stream subscription
	StreamConnClosed
	// StreamConnError describes a stream subscription error
	StreamConnError
)

type StreamEvent

type StreamEvent interface {
	Type() StreamEventType
	Txn() int64
	String() string
}

StreamEvent represents a stream event with a `type` and `txn`

type StreamEventType

type StreamEventType = string

StreamEventType is a stream eveny type

const (
	// ErrorEventT is the stream error event type
	ErrorEventT StreamEventType = "error"

	// HistoryRewriteEventT is the stream history rewrite event type
	HistoryRewriteEventT StreamEventType = "history_rewrite"

	// StartEventT is the stream start event type
	StartEventT StreamEventType = "start"

	// VersionEventT is the stream version event type
	VersionEventT StreamEventType = "version"

	// SetT is the stream set event type
	SetEventT StreamEventType = "set"
)

type StreamField

type StreamField string

StreamField represents a stream field

const (
	DiffField     StreamField = "diff"
	PrevField     StreamField = "prev"
	DocumentField StreamField = "document"
	ActionField   StreamField = "action"
	IndexField    StreamField = "index"
)

type StreamSubscription

type StreamSubscription struct {
	// contains filtered or unexported fields
}

StreamSubscription dispatches events received to the registered listener functions. New subscriptions must be constructed via the FaunaClient stream method.

func (*StreamSubscription) Close

func (sub *StreamSubscription) Close()

func (*StreamSubscription) Query

func (sub *StreamSubscription) Query() Expr

Query returns the query used to initiate the stream

func (*StreamSubscription) Start

func (sub *StreamSubscription) Start() (err error)

func (*StreamSubscription) Status

Status returns the current stream status

func (*StreamSubscription) StreamEvents

func (sub *StreamSubscription) StreamEvents() <-chan StreamEvent

type StringV

type StringV string

StringV represents a valid JSON string.

func (StringV) At

func (str StringV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since StringV is not traversable.

func (StringV) Get

func (str StringV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a StringV or a string type.

type TimeV

type TimeV time.Time

TimeV represents a FaunaDB time type.

func (TimeV) At

func (localTime TimeV) At(field Field) FieldValue

At implements the Value interface by returning an invalid field since TimeV is not traversable.

func (TimeV) Get

func (localTime TimeV) Get(i interface{}) error

Get implements the Value interface by decoding the underlying value to either a TimeV or a time.Time type.

func (TimeV) MarshalJSON

func (localTime TimeV) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB time representation.

type Unauthorized

type Unauthorized struct{ FaunaError }

A Unauthorized wraps an HTTP 401 error response.

type Unavailable

type Unavailable struct{ FaunaError }

A Unavailable wraps an HTTP 503 error response.

type UnknownError

type UnknownError struct{ FaunaError }

A UnknownError wraps any unknown http error response.

type ValidationFailure

type ValidationFailure struct {
	Position    []string `fauna:"position"`
	Code        string   `fauna:"code"`
	Description string   `fauna:"description"`
}

ValidationFailure describes validation errors on a submitted query.

type Value

type Value interface {
	Expr
	Get(interface{}) error // Decode a FaunaDB value into a native Go type
	At(Field) FieldValue   // Traverse the value using the provided field extractor
}

Value represents valid FaunaDB values returned from the server. Values also implement the Expr interface. They can be sent back and forth to FaunaDB with no extra escaping needed.

The Get method is used to decode a FaunaDB value into a Go type. For example:

var t time.Time

faunaTime, _ := client.Query(Time("now"))
_ := faunaTime.Get(&t)

The At method uses field extractors to traverse the data to specify a field:

var firstEmail string

profile, _ := client.Query(RefCollection(Collection("profile), "43"))
profile.At(ObjKey("emails").AtIndex(0)).Get(&firstEmail)

For more information, check https://app.fauna.com/documentation/reference/queryapi#simple-type.

type ValueNotFound

type ValueNotFound struct {
	// contains filtered or unexported fields
}

ValueNotFound describes an error can occur when trying to extract a field, but that field could not be found.

func (ValueNotFound) Error

func (v ValueNotFound) Error() string

type VersionEvent

type VersionEvent struct {
	StreamEvent
	// contains filtered or unexported fields
}

VersionEvent represents a version event that occurs upon any modifications to the current state of the subscribed document.

func (VersionEvent) Event

func (event VersionEvent) Event() Value

Event returns the stream event as a `Value`

func (VersionEvent) String

func (event VersionEvent) String() string

func (VersionEvent) Txn

func (event VersionEvent) Txn() int64

Txn returns the stream event timestamp

func (VersionEvent) Type

func (event VersionEvent) Type() StreamEventType

Type returns the stream event type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL