class Fauna::Client
The Ruby client for FaunaDB.
All methods return a converted JSON response. This is a Hash containing Arrays, ints, floats, strings, and other Hashes. Hash keys are always Symbols.
Any Ref, SetRef, Time or
Date values in it will also be parsed. (So instead of {
"@ref": { "id": "123", "class": {
"@ref": { "id": "frogs", "class": {
"@ref": { "id": "classes" } } } } } }
,
you will get Fauna::Ref.new("123",
Fauna::Ref.new("frogs", Fauna::Native.classes))
).
Attributes
Faraday adapter in use.
Open timeout in seconds.
An array of the user and pass used for authentication when sending requests.
The domain requests will be sent to.
Callback that will be passed a RequestResult
after every
completed request.
Port used when sending requests.
Read timeout in seconds.
Scheme used when sending requests (either http
or
https
).
Public Class Methods
Create a new Client.
params
-
A list of parameters to configure the connection with.
:domain
-
The domain to send requests to.
:scheme
-
Scheme to use when sending requests (either
http
orhttps
). :port
-
Port to use when sending requests.
:secret
-
Credentials to use when sending requests. User and pass must be separated by a colon.
:read_timeout
-
Read timeout in seconds.
:connection_timeout
-
Open timeout in seconds.
:observer
-
Callback that will be passed a RequestResult after every completed request.
:adapter
-
Faraday adapter to use. Either can be a symbol for the adapter, or an array of arguments.
# File lib/fauna/client.rb, line 42 def initialize(params = {}) @domain = params[:domain] || 'db.fauna.com' @scheme = params[:scheme] || 'https' @port = params[:port] || (scheme == 'https' ? 443 : 80) @read_timeout = params[:read_timeout] || 60 @connection_timeout = params[:connection_timeout] || 60 @observer = params[:observer] @adapter = params[:adapter] || :net_http_persistent init_credentials(params[:secret]) init_connection end
Public Instance Methods
Creates a Fauna::Page for paging/iterating over a set.
set
-
A set query to paginate over.
params
-
A list of parameters to pass to paginate.
fauna_map
-
Optional block to wrap the generated paginate query with. The block will be run in a query context. The paginate query will be passed into the block as an argument.
# File lib/fauna/client.rb, line 100 def paginate(set, params = {}, &fauna_map) Fauna::Page.new(self, set, params, &fauna_map) end
Create a new client from the existing config with a given secret.
:secret
-
Credentials to use when sending requests. User and pass must be separated by a colon.
# File lib/fauna/client.rb, line 59 def with_secret(secret) with_dup do |client| client.send(:init_credentials, secret) end end
Query Methods
↑ topPublic Instance Methods
Issues a query to FaunaDB.
Queries are built via the Query helpers. See FaunaDB Query API for information on constructing queries.
expression
-
A query expression
expr_block
-
May be provided instead of expression. Block is used to build an expression with Fauna.query.
Example using expression:
client.query(Fauna::Query.add(1, 2, Fauna::Query.subtract(3,
2)))
Example using block:
client.query { add(1, 2, subtract(3, 2)) }
Reference: Executing FaunaDB Queries
# File lib/fauna/client.rb, line 85 def query(expression = nil, &expr_block) if expr_block.nil? execute(:post, :'', nil, Fauna::Query::Expr.wrap(expression)) else execute(:post, :'', nil, Fauna::Query.expr(&expr_block)) end end
REST Methods
↑ topPublic Instance Methods
Ping FaunaDB.
Reference: FaunaDB Rest API.
# File lib/fauna/client.rb, line 110 def ping(params = {}) execute(:get, :ping, params) end