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/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 class to store profiles _, _ = client.Query(f.CreateClass(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.Class("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 ¶
- Constants
- type Arr
- type ArrayV
- type BadRequest
- type BooleanV
- type BytesV
- type ClientConfig
- type DateV
- type DecodeError
- type DoubleV
- type Expr
- func Abort(msg interface{}) Expr
- func Add(args ...interface{}) Expr
- func And(args ...interface{}) Expr
- func Append(elems, coll interface{}) Expr
- func At(timestamp, expr interface{}) Expr
- func Call(ref interface{}, args ...interface{}) Expr
- func Casefold(str interface{}, options ...OptionalParameter) Expr
- func Class(name interface{}) Expr
- func Classes() Expr
- func Concat(terms interface{}, options ...OptionalParameter) Expr
- func Contains(path, value interface{}) Expr
- func Create(ref, params interface{}) Expr
- func CreateClass(params interface{}) Expr
- func CreateDatabase(params interface{}) Expr
- func CreateFunction(params interface{}) Expr
- func CreateIndex(params interface{}) Expr
- func CreateKey(params interface{}) Expr
- func Credentials() Expr
- func Database(name interface{}) Expr
- func Databases() Expr
- func Date(str interface{}) Expr
- func Delete(ref interface{}) Expr
- func Difference(sets ...interface{}) Expr
- func Distinct(set interface{}) Expr
- func Divide(args ...interface{}) Expr
- func Do(exprs ...interface{}) Expr
- func Drop(num, coll interface{}) Expr
- func Epoch(num, unit interface{}) Expr
- func Equals(args ...interface{}) Expr
- func Events(refSet interface{}) Expr
- func Exists(ref interface{}, options ...OptionalParameter) Expr
- func Filter(coll, lambda interface{}) Expr
- func Foreach(coll, lambda interface{}) Expr
- func Function(name interface{}) Expr
- func Functions() Expr
- func GT(args ...interface{}) Expr
- func GTE(args ...interface{}) Expr
- func Get(ref interface{}, options ...OptionalParameter) Expr
- func HasIdentity() Expr
- func Identify(ref, password interface{}) Expr
- func Identity() Expr
- func If(cond, then, elze interface{}) Expr
- func Index(name interface{}) Expr
- func Indexes() Expr
- func Insert(ref, ts, action, params interface{}) Expr
- func Intersection(sets ...interface{}) Expr
- func Join(source, target interface{}) Expr
- func KeyFromSecret(secret interface{}) Expr
- func Keys() Expr
- func LT(args ...interface{}) Expr
- func LTE(args ...interface{}) Expr
- func Lambda(varName, expr interface{}) Expr
- func Let(bindings Obj, in interface{}) Expr
- func Login(ref, params interface{}) Expr
- func Logout(invalidateAll interface{}) Expr
- func Map(coll, lambda interface{}) Expr
- func Match(ref interface{}) Expr
- func MatchTerm(ref, terms interface{}) Expr
- func Modulo(args ...interface{}) Expr
- func Multiply(args ...interface{}) Expr
- func NewId() Expr
- func NextID() Exprdeprecated
- func Not(boolean interface{}) Expr
- func Null() Expr
- func Or(args ...interface{}) Expr
- func Paginate(set interface{}, options ...OptionalParameter) Expr
- func Prepend(elems, coll interface{}) Expr
- func Query(lambda interface{}) Expr
- func Ref(id string) Expr
- func RefClass(classRef, id interface{}) Expr
- func Remove(ref, ts, action interface{}) Expr
- func Replace(ref, params interface{}) Expr
- func ScopedClass(name interface{}, scope interface{}) Expr
- func ScopedClasses(scope interface{}) Expr
- func ScopedCredentials(scope interface{}) Expr
- func ScopedDatabase(name interface{}, scope interface{}) Expr
- func ScopedDatabases(scope interface{}) Expr
- func ScopedFunction(name interface{}, scope interface{}) Expr
- func ScopedFunctions(scope interface{}) Expr
- func ScopedIndex(name interface{}, scope interface{}) Expr
- func ScopedIndexes(scope interface{}) Expr
- func ScopedKeys(scope interface{}) Expr
- func ScopedTokens(scope interface{}) Expr
- func Select(path, value interface{}, options ...OptionalParameter) Expr
- func SelectAll(path, value interface{}) Expr
- func Singleton(ref interface{}) Expr
- func Subtract(args ...interface{}) Expr
- func Take(num, coll interface{}) Expr
- func Time(str interface{}) Expr
- func Tokens() Expr
- func Union(sets ...interface{}) Expr
- func Update(ref, params interface{}) Expr
- func Var(name string) Expr
- type FaunaClient
- type FaunaError
- type Field
- type FieldValue
- type InternalError
- type InvalidFieldType
- type LongV
- type NotFound
- type NullV
- type Obj
- type ObjectV
- type OptionalParameter
- func After(ref interface{}) OptionalParameter
- func Before(ref interface{}) OptionalParameter
- func Default(value interface{}) OptionalParameter
- func EventsOpt(events interface{}) OptionalParameterdeprecated
- func Normalizer(norm interface{}) OptionalParameter
- func Separator(sep interface{}) OptionalParameter
- func Size(size interface{}) OptionalParameter
- func Sources(sources interface{}) OptionalParameter
- func TS(timestamp interface{}) OptionalParameter
- type PermissionDenied
- type QueryError
- type QueryV
- type RefV
- type SetRefV
- type StringV
- type TimeV
- type Unauthorized
- type Unavailable
- type UnknownError
- type ValidationFailure
- type Value
- type ValueNotFound
Examples ¶
Constants ¶
const ( ActionCreate = "create" ActionDelete = "delete" )
Event's action types. Usually used as a parameter for Insert or Remove functions.
See: https://fauna.com/documentation/queries#values-events
const ( TimeUnitSecond = "second" TimeUnitMillisecond = "millisecond" TimeUnitMicrosecond = "microsecond" TimeUnitNanosecond = "nanosecond" )
Time unit. Usually used as a parameter for Epoch function.
See: https://fauna.com/documentation/queries#time_functions-epoch_num_unit_unit
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Arr ¶
type Arr []interface{}
Arr is a expression shortcut to represent any valid JSON array
func (Arr) MarshalJSON ¶
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 transversing the array and extracting the field informed.
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 transversable.
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 transversable.
func (BytesV) Get ¶
Get implements the Value interface by decoding the underlying value to either a ByteV or a []byte type.
func (BytesV) MarshalJSON ¶
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 EnableTxnTimePassthrough ¶
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.
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.
type DateV ¶
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 transversable.
func (DateV) Get ¶
Get implements the Value interface by decoding the underlying value to either a DateV or a time.Time type.
func (DateV) MarshalJSON ¶
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 transversable.
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( Ref("classes/users"), Obj{"data": User{"John"}}, ), )
func And ¶
func And(args ...interface{}) Expr
And returns the conjunction of a list of boolean values.
func Append ¶
func Append(elems, coll interface{}) Expr
Append returns a new collection that is the result of appending elems to coll.
See: https://fauna.com/documentation/queries#collection_functions
func Call ¶
func Call(ref interface{}, args ...interface{}) Expr
Call invokes the specified function passing in a variable number of arguments
func Casefold ¶
func Casefold(str interface{}, options ...OptionalParameter) Expr
Casefold normalizes strings according to the Unicode Standard section 5.18 "Case Mappings".
See: https://fauna.com/documentation/queries#string_functions
func Concat ¶
func Concat(terms interface{}, options ...OptionalParameter) Expr
Concat concatenates a list of strings into a single string. Optional parameters: Separator.
See: https://fauna.com/documentation/queries#string_functions
func Contains ¶
func Contains(path, value interface{}) Expr
Contains checks if the value informed contains the path specified.
func Create ¶
func Create(ref, params interface{}) Expr
Create creates an instance of the specified class.
See: https://fauna.com/documentation/queries#write_functions
func CreateClass ¶
func CreateClass(params interface{}) Expr
CreateClass creates a new class.
See: https://fauna.com/documentation/queries#write_functions
func CreateDatabase ¶
func CreateDatabase(params interface{}) Expr
CreateDatabase creates an new database.
See: https://fauna.com/documentation/queries#write_functions
func CreateFunction ¶
func CreateFunction(params interface{}) Expr
CreateFunction creates a new function.
See: https://fauna.com/documentation/queries#write_functions
func CreateIndex ¶
func CreateIndex(params interface{}) Expr
CreateIndex creates a new index.
See: https://fauna.com/documentation/queries#write_functions
func CreateKey ¶
func CreateKey(params interface{}) Expr
CreateKey creates a new key.
See: https://fauna.com/documentation/queries#write_functions
func Date ¶
func Date(str interface{}) Expr
Date constructs a date from a ISO 8601 offset date/time string.
func Delete ¶
func Delete(ref interface{}) Expr
Delete deletes the provided instance.
See: https://fauna.com/documentation/queries#write_functions
func Difference ¶
func Difference(sets ...interface{}) Expr
Difference returns the set of instances that are present in the source set but not in any of the other specified sets.
func Distinct ¶
func Distinct(set interface{}) Expr
Distinct returns the set of instances with duplicates removed.
func Divide ¶
func Divide(args ...interface{}) Expr
Divide computes the quotient of a list of numbers.
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.
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.
See: https://fauna.com/documentation/queries#collection_functions
func Epoch ¶
func Epoch(num, unit interface{}) Expr
Epoch constructs a time relative to the epoch "1970-01-01T00:00:00Z".
func Events ¶
func Events(refSet interface{}) Expr
Events returns the history of instance's data of the provided ref.
func Exists ¶
func Exists(ref interface{}, options ...OptionalParameter) Expr
Exists returns boolean true if the provided ref exists (in the case of an instance), or is non-empty (in the case of a set), and false otherwise. Optional parameters: TS.
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.
See: https://fauna.com/documentation/queries#collection_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.
See: https://fauna.com/documentation/queries#collection_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.
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.
func Get ¶
func Get(ref interface{}, options ...OptionalParameter) Expr
Get retrieves the instance identified by the ref informed. Optional parameters: TS.
func HasIdentity ¶
func HasIdentity() Expr
HasIdentity checks if the current key has an identity associated to it.
func Identify ¶
func Identify(ref, password interface{}) Expr
Identify checks the given password against the provided ref's credentials.
func Identity ¶
func Identity() Expr
Identity returns the instance reference associated with the current key.
For example, the current key token created using:
Create(Tokens(), Obj{"instance": someRef})
or via:
Login(someRef, Obj{"password":"sekrit"})
will return "someRef" as the result of this function.
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
func Insert ¶
func Insert(ref, ts, action, params interface{}) Expr
Insert adds an event to the provided instance's history.
See: https://fauna.com/documentation/queries#write_functions
func Intersection ¶
func Intersection(sets ...interface{}) Expr
Intersection returns the set of instances that are present in all of the specified sets.
func Join ¶
func Join(source, target interface{}) Expr
Join derives a set of resources by applying each instance in the source set to the target set.
func KeyFromSecret ¶
func KeyFromSecret(secret interface{}) Expr
KeyFromSecret retrieves the key object from the given secret.
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.
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.
func Lambda ¶
func Lambda(varName, expr interface{}) Expr
Lambda creates an anonymous function. Mostly used with Collection functions.
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.
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.
See: https://fauna.com/documentation/queries#collection_functions
func Match ¶
func Match(ref interface{}) Expr
Match returns the set of instances for the specified index.
func MatchTerm ¶
func MatchTerm(ref, terms interface{}) Expr
MatchTerm returns th set of instances that match the terms in an index.
func Modulo ¶
func Modulo(args ...interface{}) Expr
Modulo computes the reminder after the division of a list of numbers.
func Multiply ¶
func Multiply(args ...interface{}) Expr
Multiply computes the product of a list of numbers.
func NewId ¶
func NewId() Expr
NewId produces a new identifier suitable for use when constructing refs.
func Or ¶
func Or(args ...interface{}) Expr
Or returnsj the disjunction of a list of boolean values.
func Paginate ¶
func Paginate(set interface{}, options ...OptionalParameter) Expr
Paginate retrieves a page from the set informed. Optional parameters: TS, After, Before, Size, EventsOpt, and Sources.
func Prepend ¶
func Prepend(elems, coll interface{}) Expr
Prepend returns a new collection that is the result of prepending elems to coll.
See: https://fauna.com/documentation/queries#collection_functions
func Query ¶
func Query(lambda interface{}) Expr
Query creates an instance of the `@query` type with the specified lambda
func Ref ¶
Ref creates a new RefV value with the ID informed.
See: https://fauna.com/documentation/queries#values-special_types
func RefClass ¶
func RefClass(classRef, id interface{}) Expr
RefClass creates a new Ref based on the class and ID informed.
See: https://fauna.com/documentation/queries#values-special_types
func Remove ¶
func Remove(ref, ts, action interface{}) Expr
Remove deletes an event from the provided instance's history.
See: https://fauna.com/documentation/queries#write_functions
func Replace ¶
func Replace(ref, params interface{}) Expr
Replace replaces the provided instance.
See: https://fauna.com/documentation/queries#write_functions
func ScopedClass ¶
func ScopedClass(name interface{}, scope interface{}) Expr
ScopedClass creates a new class ref inside a database.
func ScopedClasses ¶
func ScopedClasses(scope interface{}) Expr
ScopedClasses creates a native ref for classes inside a database.
func ScopedCredentials ¶
func ScopedCredentials(scope interface{}) Expr
ScopedCredentials creates a native ref for credentials inside a database.
func ScopedDatabase ¶
func ScopedDatabase(name interface{}, scope interface{}) Expr
ScopedDatabase creates a new database ref inside a database.
func ScopedDatabases ¶
func ScopedDatabases(scope interface{}) Expr
ScopedDatabases creates a native ref for databases inside a database.
func ScopedFunction ¶
func ScopedFunction(name interface{}, scope interface{}) Expr
ScopedFunction creates a new function ref inside a database.
func ScopedFunctions ¶
func ScopedFunctions(scope interface{}) Expr
ScopedFunctions creates a native ref for functions inside a database.
func ScopedIndex ¶
func ScopedIndex(name interface{}, scope interface{}) Expr
ScopedIndex creates a new index ref inside a database.
func ScopedIndexes ¶
func ScopedIndexes(scope interface{}) Expr
ScopedIndexes creates a native ref for indexes inside a database.
func ScopedKeys ¶
func ScopedKeys(scope interface{}) Expr
ScopedKeys creates a native ref for keys inside a database.
func ScopedTokens ¶
func ScopedTokens(scope interface{}) Expr
ScopedTokens creates a native ref for tokens inside a database.
func Select ¶
func Select(path, value interface{}, options ...OptionalParameter) Expr
Select traverses into the provided value, returning the value at the given path.
func SelectAll ¶
func SelectAll(path, value interface{}) Expr
SelectAll traverses into the value informed flattening all values under the desired path.
func Singleton ¶
func Singleton(ref interface{}) Expr
Singleton returns the history of the instance's presence of the provided ref.
func Subtract ¶
func Subtract(args ...interface{}) Expr
Subtract computes the difference of a list of numbers.
func Take ¶
func Take(num, coll interface{}) Expr
Take returns a new collection containing num elements from the head of the original collection.
See: https://fauna.com/documentation/queries#collection_functions
func Time ¶
func Time(str interface{}) Expr
Time constructs a time from a ISO 8601 offset date/time string.
func Union ¶
func Union(sets ...interface{}) Expr
Union returns the set of instances that are present in at least one of the specified sets.
func Update ¶
func Update(ref, params interface{}) Expr
Update updates the provided instance.
See: https://fauna.com/documentation/queries#write_functions
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) 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.
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.
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 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 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 transversable.
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 transversable.
func (NullV) Get ¶
Get implements the Value interface by decoding the underlying value to a either a NullV or a nil pointer.
func (NullV) MarshalJSON ¶
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 ¶
MarshalJSON implements json.Marshaler for Obj expression
type ObjectV ¶
ObjectV represents a FaunaDB object type.
func (ObjectV) At ¶
func (obj ObjectV) At(field Field) FieldValue
At implements the Value interface by transversing the object and extracting the field informed.
func (ObjectV) Get ¶
Get implements the Value interface by decoding the underlying value to either a ObjectV or a native map type.
func (ObjectV) MarshalJSON ¶
MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB object representation.
type OptionalParameter ¶
type OptionalParameter func(unescapedObj)
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://fauna.com/documentation/queries#values-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://fauna.com/documentation/queries#values-pages.
Functions that accept this optional parameter are: Paginate.
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://fauna.com/documentation/queries#values-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 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 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, Insert, Remove, Exists, and Paginate.
type PermissionDenied ¶
type PermissionDenied struct{ FaunaError }
A PermissionDenied wraps an HTTP 403 error response.
type QueryError ¶
type QueryError struct { Position []string `fauna:"position"` Code string `fauna:"code"` Description string `fauna:"description"` Failures []ValidationFailure `fauna:"failures"` }
QueryError describes query errors returned by the server.
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 transversable.
func (QueryV) Get ¶
Get implements the Value interface by decoding the underlying value to a QueryV.
func (QueryV) MarshalJSON ¶
MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB query representation.
type RefV ¶
RefV represents a FaunaDB ref type.
func NativeClasses ¶
func NativeClasses() *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 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 transversable.
func (RefV) MarshalJSON ¶
MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB ref representation.
type SetRefV ¶
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 transversable.
func (SetRefV) Get ¶
Get implements the Value interface by decoding the underlying value to a SetRefV.
func (SetRefV) MarshalJSON ¶
MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB setref representation.
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 transversable.
type TimeV ¶
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 transversable.
func (TimeV) Get ¶
Get implements the Value interface by decoding the underlying value to either a TimeV or a time.Time type.
func (TimeV) MarshalJSON ¶
MarshalJSON implements json.Marshaler by escaping its value according to FaunaDB time representation.
type UnknownError ¶
type UnknownError struct{ FaunaError }
A UnknownError wraps any unknown http error response.
type ValidationFailure ¶
type ValidationFailure struct { Field []string `fauna:"field"` 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 // Transverse the value using the field extractor informed }
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 transverse the data to specify a field:
var firstEmail string profile, _ := client.Query(Ref("classes/profile/43")) profile.At(ObjKey("emails").AtIndex(0)).Get(&firstEmail)
For more information, check https://fauna.com/documentation/queries#values.
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