fauna 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 534fc367754718ef48a607ae41a65d4bb4a34868
4
- data.tar.gz: 52a4a948e7bddb08eb830daef2dff25081b10342
3
+ metadata.gz: 79e3f29b34209d1fd34ebfb3a878fe2210cc6a34
4
+ data.tar.gz: eb8887d649b435f9e1064717c04232ace5af76d2
5
5
  SHA512:
6
- metadata.gz: e5ed3b7fc306db43a75044561fa37e290a64a94521b8691706937bab01f98d639f44ce05953a37ace7e92e178461d03e7b309979424b6363f5dabf46255c0d33
7
- data.tar.gz: 9fbccbc8cb75506a4adddb74ffe19ec0182b6f9a2da664b81aadc302902b0ed707fb6353c652b3818798f515608662e4ea08483cca077be3f86fe51c3295b0ce
6
+ metadata.gz: 9b23b487d4202f26858139562129d66132cfdc0d313067381acd077504a80bee7b74b22e084dc0cc4b4564857ad8ff90c9145dc3f58e7b9c79432ba458e0468f
7
+ data.tar.gz: 0ae0ecc0c29346e8aeb64228c67e9ca8f059de588c9acaa3de2b4cd165ab9228ef5dd8aaf5276263b1bc5ff98400c27ecf11357951a21e21888221a1841036d3
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 2.2.0
2
+ * Added `create_class`, `create_index`, `create_database`, `create_key`, `database`, `class`,
3
+ and `index` query functions.
4
+ * Removed `count` query function.
5
+ * Raises `Fauna::UnavailableError` for all 503s and for Faraday network errors.
6
+ * Fix documentation errors and update links.
7
+
1
8
  2.1.2
2
9
  * Change default domain to `cloud.faunadb.com`.
3
10
 
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # FaunaDB
2
2
 
3
- Ruby driver for [FaunaDB](https://faunadb.com).
3
+ [![Build Status](https://img.shields.io/travis/faunadb/faunadb-ruby/master.svg?maxAge=21600)](https://travis-ci.org/faunadb/faunadb-ruby)
4
+ [![Coverage Status](https://img.shields.io/codecov/c/github/faunadb/faunadb-ruby/master.svg?maxAge=21600)](https://codecov.io/gh/faunadb/faunadb-ruby/branch/master)
5
+ [![Gem Version](https://img.shields.io/gem/v/fauna.svg?maxAge=21600)](https://rubygems.org/gems/fauna)
6
+ [![License](https://img.shields.io/badge/license-MPL_2.0-blue.svg?maxAge=2592000)](https://raw.githubusercontent.com/faunadb/faunadb-ruby/master/LICENSE)
7
+
8
+ Ruby driver for [FaunaDB](https://fauna.com).
4
9
 
5
10
  ## Installation
6
11
 
@@ -16,6 +21,15 @@ And then execute:
16
21
 
17
22
  $ bundle
18
23
 
24
+ ## Documentation
25
+
26
+ The driver documentation is [hosted on GitHub Pages](https://faunadb.github.io/faunadb-ruby/).
27
+
28
+ Please see the [FaunaDB Documentation](https://fauna.com/documentation) for
29
+ a complete API reference, or look in
30
+ [`/test`](https://github.com/faunadb/faunadb-ruby/tree/master/test) for more
31
+ examples.
32
+
19
33
  ## Compatibility
20
34
 
21
35
  Tested and compatible with the following ruby versions:
@@ -95,39 +109,28 @@ $fauna.query { delete user[:ref] }
95
109
  ## Running Tests
96
110
 
97
111
  You can run tests against FaunaDB Cloud yourself.
98
- [Create an admin key](https://faunadb.com/account/keys) and set
99
- `FAUNA_ROOT_KEY` environment variable to it's secret. Then run `rake test`:
112
+ [Create an admin key](https://fauna.com/account/keys) and set
113
+ `FAUNA_ROOT_KEY` environment variable to it's secret. Then run `rake spec`:
100
114
 
101
115
  ```bash
102
116
  export FAUNA_ROOT_KEY='kqnPAbijGhkgAAC03-36hjCvcTnWf4Pl8w97UE1HeWo'
103
- rake test
117
+ rake spec
104
118
  ```
105
119
 
106
120
  To run a single test, use e.g. `ruby test/client_test.rb`.
107
121
 
108
122
  Coverage is automatically run as part of the tests. After running tests, check
109
123
  `coverage/index.html` for the coverage report. If using jruby, use
110
- `JRUBY_OPTS="--debug" bundle exec rake test` to ensure coverage is generated
124
+ `JRUBY_OPTS="--debug" bundle exec rake spec` to ensure coverage is generated
111
125
  correctly.
112
126
 
113
- ## Documenting
114
-
115
- Use `rake rdoc` to generate documentation.
116
-
117
- ## Further Reading
118
-
119
- Please see the [FaunaDB Documentation](https://faunadb.com/documentation) for
120
- a complete API reference, or look in
121
- [`/test`](https://github.com/faunadb/faunadb-ruby/tree/master/test) for more
122
- examples.
123
-
124
127
  ## Contributing
125
128
 
126
129
  GitHub pull requests are very welcome.
127
130
 
128
131
  ## LICENSE
129
132
 
130
- Copyright 2016 [Fauna, Inc.](https://faunadb.com/)
133
+ Copyright 2016 [Fauna, Inc.](https://fauna.com/)
131
134
 
132
135
  Licensed under the Mozilla Public License, Version 2.0 (the
133
136
  "License"); you may not use this software except in compliance with
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.name = 'fauna'
6
6
  s.version = Fauna::VERSION.dup
7
7
  s.author = 'Fauna, Inc.'
8
- s.email = 'priority@faunadb.com'
8
+ s.email = 'priority@fauna.com'
9
9
  s.summary = 'FaunaDB Ruby driver'
10
10
  s.description = 'Ruby driver for FaunaDB.'
11
11
  s.homepage = 'https://github.com/faunadb/faunadb-ruby'
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.add_runtime_dependency 'json', '~> 1.8'
23
23
  s.add_development_dependency 'rspec', '~> 3.4'
24
24
  s.add_development_dependency 'rubocop', '~> 0.38.0'
25
- s.add_development_dependency 'coveralls', '= 0.8.14'
25
+ s.add_development_dependency 'codecov', '~> 0.1.5'
26
26
  end
@@ -7,7 +7,7 @@ require 'zlib'
7
7
  require 'time'
8
8
 
9
9
  ##
10
- # Main namespace for the FaunaDB client.
10
+ # Main namespace for the FaunaDB driver.
11
11
  module Fauna; end
12
12
 
13
13
  require 'fauna/version'
@@ -24,7 +24,7 @@ module Fauna
24
24
  attr_reader :connection_timeout
25
25
  # Callback that will be passed a +RequestResult+ after every completed request.
26
26
  attr_reader :observer
27
- # Faraday adapter in use.
27
+ # Faraday[https://github.com/lostisland/faraday] adapter in use.
28
28
  attr_reader :adapter
29
29
 
30
30
  ##
@@ -65,7 +65,7 @@ module Fauna
65
65
  ##
66
66
  # Issues a query to FaunaDB.
67
67
  #
68
- # Queries are built via the Query helpers. See {FaunaDB Query API}[https://faunadb.com/documentation/queries]
68
+ # Queries are built via the Query helpers. See {FaunaDB Query API}[https://fauna.com/documentation/queries]
69
69
  # for information on constructing queries.
70
70
  #
71
71
  # +expression+:: A query expression
@@ -79,7 +79,7 @@ module Fauna
79
79
  #
80
80
  # <code>client.query { add(1, 2, subtract(3, 2)) }</code>
81
81
  #
82
- # Reference: {Executing FaunaDB Queries}[https://faunadb.com/documentation#queries]
82
+ # Reference: {Executing FaunaDB Queries}[https://fauna.com/documentation#queries]
83
83
  #
84
84
  # :category: Query Methods
85
85
  def query(expression = nil, &expr_block)
@@ -94,7 +94,7 @@ module Fauna
94
94
  # Creates a Fauna::Page for paging/iterating over a set.
95
95
  #
96
96
  # +set+:: A set query to paginate over.
97
- # +params+:: A list of parameters to pass to {paginate}[https://faunadb.com/documentation/queries#read_functions-paginate_set].
97
+ # +params+:: A list of parameters to pass to {paginate}[https://fauna.com/documentation/queries#read_functions-paginate_set].
98
98
  # +fauna_map+:: Optional block to wrap the generated paginate query with. The block will be run in a query context.
99
99
  # The paginate query will be passed into the block as an argument.
100
100
  def paginate(set, params = {}, &fauna_map)
@@ -107,7 +107,7 @@ module Fauna
107
107
  # +path+:: Path to +GET+.
108
108
  # +query+:: Query parameters to append to the path.
109
109
  #
110
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
110
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
111
111
  #
112
112
  # :category: REST Methods
113
113
  def get(path, query = {})
@@ -120,7 +120,7 @@ module Fauna
120
120
  # +path+:: Path to +POST+.
121
121
  # +data+:: Data to post as the body. +data+ is automatically converted to JSON.
122
122
  #
123
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
123
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
124
124
  #
125
125
  # :category: REST Methods
126
126
  def post(path, data = {})
@@ -133,7 +133,7 @@ module Fauna
133
133
  # +path+:: Path to +PUT+.
134
134
  # +data+:: Data to post as the body. +data+ is automatically converted to JSON.
135
135
  #
136
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
136
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
137
137
  #
138
138
  # :category: REST Methods
139
139
  def put(path, data = {})
@@ -146,7 +146,7 @@ module Fauna
146
146
  # +path+:: Path to +PATCH+.
147
147
  # +data+:: Data to post as the body. +data+ is automatically converted to JSON.
148
148
  #
149
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
149
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
150
150
  #
151
151
  # :category: REST Methods
152
152
  def patch(path, data = {})
@@ -158,7 +158,7 @@ module Fauna
158
158
  #
159
159
  # +path+:: Path to +DELETE+.
160
160
  #
161
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
161
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
162
162
  #
163
163
  # :category: REST Methods
164
164
  def delete(path)
@@ -168,7 +168,7 @@ module Fauna
168
168
  ##
169
169
  # Ping FaunaDB.
170
170
  #
171
- # Reference: {FaunaDB Rest API}[https://faunadb.com/documentation#rest-other].
171
+ # Reference: {FaunaDB Rest API}[https://fauna.com/documentation#rest-other].
172
172
  #
173
173
  # :category: REST Methods
174
174
  def ping(params = {})
@@ -209,7 +209,22 @@ module Fauna
209
209
  path = path.to_s
210
210
 
211
211
  start_time = Time.now
212
- response = perform_request action, path, query, data
212
+ begin
213
+ response = perform_request action, path, query, data
214
+ rescue Faraday::ClientError => e
215
+ end_time = Time.now
216
+
217
+ message = e.class.name
218
+ unless e.message.nil?
219
+ message += ": #{e.message}"
220
+ end
221
+
222
+ request_result = RequestResult.new(self,
223
+ action, path, query, data,
224
+ nil, nil, nil, nil,
225
+ start_time, end_time)
226
+ raise UnexpectedError.new(message, request_result)
227
+ end
213
228
  end_time = Time.now
214
229
 
215
230
  response_raw = response.body
@@ -223,7 +238,7 @@ module Fauna
223
238
 
224
239
  @observer.call(request_result) unless @observer.nil?
225
240
 
226
- if response_json.nil?
241
+ if response_json.nil? && response.status != 503
227
242
  fail UnexpectedError.new('Invalid JSON.', request_result)
228
243
  end
229
244
 
@@ -237,6 +252,8 @@ module Fauna
237
252
  req.body = FaunaJson.to_json(data) unless data.nil?
238
253
  req.url(path || '')
239
254
  end
255
+ rescue Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::SSLError => e
256
+ raise UnavailableError.new(e)
240
257
  end
241
258
  end
242
259
 
@@ -46,7 +46,7 @@ module Fauna
46
46
  # +path+:: Path to +GET+.
47
47
  # +query+:: Query parameters to append to the path.
48
48
  #
49
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
49
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
50
50
  #
51
51
  # :category: Client Methods
52
52
  def self.get(path, query = {})
@@ -59,7 +59,7 @@ module Fauna
59
59
  # +path+:: Path to +POST+.
60
60
  # +data+:: Data to post as the body.
61
61
  #
62
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
62
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
63
63
  #
64
64
  # :category: Client Methods
65
65
  def self.post(path, data = {})
@@ -72,7 +72,7 @@ module Fauna
72
72
  # +path+:: Path to +PUT+.
73
73
  # +data+:: Data to post as the body.
74
74
  #
75
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
75
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
76
76
  #
77
77
  # :category: Client Methods
78
78
  def self.put(path, data = {})
@@ -85,7 +85,7 @@ module Fauna
85
85
  # +path+:: Path to +PATCH+.
86
86
  # +data+:: Data to post as the body.
87
87
  #
88
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
88
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
89
89
  #
90
90
  # :category: Client Methods
91
91
  def self.patch(path, data = {})
@@ -98,7 +98,7 @@ module Fauna
98
98
  # +path+:: Path to +DELETE+.
99
99
  # +data+:: Data to post as the body.
100
100
  #
101
- # Reference: {FaunaDB REST API}[https://faunadb.com/documentation/rest]
101
+ # Reference: {FaunaDB REST API}[https://fauna.com/documentation/rest]
102
102
  #
103
103
  # :category: Client Methods
104
104
  def self.delete(path)
@@ -108,7 +108,7 @@ module Fauna
108
108
  ##
109
109
  # Issues a query to FaunaDB with the current client context.
110
110
  #
111
- # Queries are built via the Query helpers. See {FaunaDB Query API}[https://faunadb.com/documentation/queries]
111
+ # Queries are built via the Query helpers. See {FaunaDB Query API}[https://fauna.com/documentation/queries]
112
112
  # for information on constructing queries.
113
113
  #
114
114
  # +expression+:: A query expression
@@ -122,7 +122,7 @@ module Fauna
122
122
  # Creates a Fauna::Page for paging/iterating over a set with the current client context.
123
123
  #
124
124
  # +set+:: A set query to paginate over.
125
- # +params+:: A list of parameters to pass to {paginate}[https://faunadb.com/documentation/queries#read_functions-paginate_set].
125
+ # +params+:: A list of parameters to pass to {paginate}[https://fauna.com/documentation/queries#read_functions-paginate_set].
126
126
  # +fauna_map+:: Optional block to wrap the generated paginate query with. The block will be run in a query context.
127
127
  # The paginate query will be passed into the block as an argument.
128
128
  def self.paginate(set, params = {}, &fauna_map)
@@ -20,7 +20,7 @@ module Fauna
20
20
 
21
21
  ##
22
22
  # Error returned by the FaunaDB server.
23
- # For documentation of error types, see the docs[https://faunadb.com/documentation#errors].
23
+ # For documentation of error types, see the docs[https://fauna.com/documentation#errors].
24
24
  class FaunaError < RuntimeError
25
25
  # List of ErrorData objects returned by the server.
26
26
  attr_reader :errors
@@ -55,34 +55,52 @@ module Fauna
55
55
  end
56
56
  end
57
57
 
58
- # Creates a new error from a given RequestResult.
58
+ # Creates a new error from a given RequestResult or Exception.
59
59
  def initialize(request_result)
60
- @request_result = request_result
61
- errors_raw = UnexpectedError.get_or_raise request_result, request_result.response_content, :errors
62
- @errors = catch :invalid_response do
63
- throw :invalid_response unless errors_raw.is_a? Array
64
- errors_raw.map { |error| ErrorData.from_hash(error) }
65
- end
60
+ message = nil
66
61
 
67
- if @errors.nil?
68
- fail UnexpectedError.new('Error data has an unexpected format.', request_result)
69
- elsif @errors.empty?
70
- fail UnexpectedError.new('Error data returned was blank.', request_result)
71
- end
62
+ if request_result.is_a? RequestResult
63
+ @request_result = request_result
72
64
 
73
- message = @errors.map do |error|
74
- msg = 'Error'
75
- msg += " at #{error.position}" unless error.position.nil?
76
- msg += ": #{error.code} - #{error.description}"
65
+ begin
66
+ errors_raw = UnexpectedError.get_or_raise request_result, request_result.response_content, :errors
67
+ @errors = catch :invalid_response do
68
+ throw :invalid_response unless errors_raw.is_a? Array
69
+ errors_raw.map { |error| ErrorData.from_hash(error) }
70
+ end
77
71
 
78
- unless error.failures.nil?
79
- msg += ' (' + error.failures.map do |failure|
80
- "Failure at #{failure.field}: #{failure.code} - #{failure.description}"
81
- end.join(' ') + ')'
82
- end
72
+ if @errors.nil?
73
+ fail UnexpectedError.new('Error data has an unexpected format.', request_result)
74
+ elsif @errors.empty?
75
+ fail UnexpectedError.new('Error data returned was blank.', request_result)
76
+ end
83
77
 
84
- msg
85
- end.join(' ')
78
+ message = @errors.map do |error|
79
+ msg = 'Error'
80
+ msg += " at #{error.position}" unless error.position.nil?
81
+ msg += ": #{error.code} - #{error.description}"
82
+
83
+ unless error.failures.nil?
84
+ msg += ' (' + error.failures.map do |failure|
85
+ "Failure at #{failure.field}: #{failure.code} - #{failure.description}"
86
+ end.join(' ') + ')'
87
+ end
88
+
89
+ msg
90
+ end.join(' ')
91
+ rescue UnexpectedError => e
92
+ if request_result.status_code != 503
93
+ raise e
94
+ end
95
+
96
+ message = request_result.response_raw
97
+ end
98
+ elsif request_result.is_a? Exception
99
+ message = request_result.class.name
100
+ unless request_result.message.nil?
101
+ message += ": #{request_result.message}"
102
+ end
103
+ end
86
104
 
87
105
  super(message)
88
106
  end
@@ -117,7 +135,7 @@ module Fauna
117
135
  ##
118
136
  # Error code.
119
137
  #
120
- # Reference: {FaunaDB Error codes}[https://faunadb.com/documentation#errors]
138
+ # Reference: {FaunaDB Error codes}[https://fauna.com/documentation#errors]
121
139
  attr_reader :code
122
140
  # Error description.
123
141
  attr_reader :description
@@ -148,7 +166,7 @@ module Fauna
148
166
 
149
167
  ##
150
168
  # Part of ErrorData.
151
- # For more information, see the {docs}[https://faunadb.com/documentation#errors-invalid_data].
169
+ # For more information, see the {docs}[https://fauna.com/documentation#errors-invalid_data].
152
170
  class Failure
153
171
  # Failure code.
154
172
  attr_reader :code
@@ -2,7 +2,7 @@ module Fauna
2
2
  ##
3
3
  # A Ref.
4
4
  #
5
- # Reference: {FaunaDB Special Types}[https://faunadb.com/documentation/queries-values-special_types]
5
+ # Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries-values-special_types]
6
6
  class Ref
7
7
  # The raw ref string.
8
8
  attr_accessor :value
@@ -63,7 +63,7 @@ module Fauna
63
63
  ##
64
64
  # A SetRef.
65
65
  #
66
- # Reference: {FaunaDB Special Types}[https://faunadb.com/documentation/queries-values-special_types]
66
+ # Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries-values-special_types]
67
67
  class SetRef
68
68
  # The raw set hash.
69
69
  attr_accessor :value
@@ -73,7 +73,7 @@ module Fauna
73
73
  #
74
74
  # +params+:: Hash of parameters to build the SetRef with.
75
75
  #
76
- # Reference: {FaunaDB Special Types}[https://faunadb.com/documentation/queries-values-special_types]
76
+ # Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries-values-special_types]
77
77
  def initialize(params = {})
78
78
  self.value = params
79
79
  end
@@ -46,7 +46,7 @@ module Fauna
46
46
  #
47
47
  # +client+:: Client to execute queries with.
48
48
  # +set+:: A set query to paginate over.
49
- # +params+:: A list of parameters to pass to {paginate}[https://faunadb.com/documentation/queries#read_functions-paginate_set].
49
+ # +params+:: A list of parameters to pass to {paginate}[https://fauna.com/documentation/queries#read_functions-paginate_set].
50
50
  # +lambda+:: Optional lambda to map the generated paginate query with. The block will be run in a query context.
51
51
  # An element from the current page will be passed into the block as an argument. See #map for more info.
52
52
  def initialize(client, set, params = {}, &lambda)
@@ -128,7 +128,7 @@ module Fauna
128
128
  ##
129
129
  # Returns a copy of the page with the given +params+ set.
130
130
  #
131
- # See {paginate}[https://faunadb.com/documentation/queries#read_functions-paginate_set] for more details.
131
+ # See {paginate}[https://fauna.com/documentation/queries#read_functions-paginate_set] for more details.
132
132
  def with_params(params = {})
133
133
  with_dup do |page|
134
134
  page_params = page.instance_variable_get(:@params)
@@ -42,7 +42,7 @@ module Fauna
42
42
  ##
43
43
  # Construct a ref value
44
44
  #
45
- # Reference: {FaunaDB Values}[https://faunadb.com/documentation/queries#values]
45
+ # Reference: {FaunaDB Values}[https://fauna.com/documentation/queries#values]
46
46
  def ref(str, id = nil)
47
47
  if id.nil?
48
48
  Ref.new(str)
@@ -59,7 +59,7 @@ module Fauna
59
59
  # Fauna.query { { x: 1, y: add(1, 2) } }
60
60
  # Fauna.query { object(x: 1, y: add(1, 2)) }
61
61
  #
62
- # Reference: {FaunaDB Basic Forms}[https://faunadb.com/documentation/queries#basic_forms]
62
+ # Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
63
63
  def object(fields)
64
64
  Expr.new object: Expr.wrap_values(fields)
65
65
  end
@@ -75,7 +75,7 @@ module Fauna
75
75
  #
76
76
  # Expression example: <code>Fauna.query { let({ x: 2 }, add(1, var(:x))) }</code>.
77
77
  #
78
- # Reference: {FaunaDB Basic Forms}[https://faunadb.com/documentation/queries#basic_forms]
78
+ # Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
79
79
  def let(vars, expr = nil, &block)
80
80
  in_ =
81
81
  if block.nil?
@@ -97,7 +97,7 @@ module Fauna
97
97
  ##
98
98
  # A var expression
99
99
  #
100
- # Reference: {FaunaDB Basic Forms}[https://faunadb.com/documentation/queries#basic_forms]
100
+ # Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
101
101
  def var(name)
102
102
  Expr.new var: Expr.wrap(name)
103
103
  end
@@ -105,7 +105,7 @@ module Fauna
105
105
  ##
106
106
  # An if expression
107
107
  #
108
- # Reference: {FaunaDB Basic Forms}[https://faunadb.com/documentation/queries#basic_forms]
108
+ # Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
109
109
  def if_(condition, then_, else_)
110
110
  Expr.new if: Expr.wrap(condition), then: Expr.wrap(then_), else: Expr.wrap(else_)
111
111
  end
@@ -113,7 +113,7 @@ module Fauna
113
113
  ##
114
114
  # A do expression
115
115
  #
116
- # Reference: {FaunaDB Basic Forms}[https://faunadb.com/documentation/queries#basic_forms]
116
+ # Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
117
117
  def do_(*expressions)
118
118
  Expr.new do: Expr.wrap_varargs(expressions)
119
119
  end
@@ -121,7 +121,7 @@ module Fauna
121
121
  ##
122
122
  # A lambda expression
123
123
  #
124
- # Reference: {FaunaDB Basic Forms}[https://faunadb.com/documentation/queries#basic_forms]
124
+ # Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
125
125
  #
126
126
  # This form generates #var objects for you, and is called like:
127
127
  #
@@ -159,7 +159,7 @@ module Fauna
159
159
  ##
160
160
  # A raw lambda expression
161
161
  #
162
- # Reference: {FaunaDB Basic Forms}[https://faunadb.com/documentation/queries#basic_forms]
162
+ # Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
163
163
  #
164
164
  # See also #lambda.
165
165
  def lambda_expr(var, expr)
@@ -174,7 +174,7 @@ module Fauna
174
174
  # Only one of +lambda_expr+ or +lambda_block+ should be provided.
175
175
  # For example: <code>Fauna.query { map(collection) { |a| add a, 1 } }</code>.
176
176
  #
177
- # Reference: {FaunaDB Collections}[https://faunadb.com/documentation/queries#collection_functions]
177
+ # Reference: {FaunaDB Collections}[https://fauna.com/documentation/queries#collection_functions]
178
178
  def map(collection, lambda_expr = nil, &lambda_block)
179
179
  Expr.new map: Expr.wrap(lambda_expr || lambda_block), collection: Expr.wrap(collection)
180
180
  end
@@ -185,7 +185,7 @@ module Fauna
185
185
  # Only one of +lambda_expr+ or +lambda_block+ should be provided.
186
186
  # For example: <code>Fauna.query { foreach(collection) { |a| delete a } }</code>.
187
187
  #
188
- # Reference: {FaunaDB Collections}[https://faunadb.com/documentation/queries#collection_functions]
188
+ # Reference: {FaunaDB Collections}[https://fauna.com/documentation/queries#collection_functions]
189
189
  def foreach(collection, lambda_expr = nil, &lambda_block)
190
190
  Expr.new foreach: Expr.wrap(lambda_expr || lambda_block), collection: Expr.wrap(collection)
191
191
  end
@@ -196,7 +196,7 @@ module Fauna
196
196
  # Only one of +lambda_expr+ or +lambda_block+ should be provided.
197
197
  # For example: <code>Fauna.query { filter(collection) { |a| equals a, 1 } }</code>.
198
198
  #
199
- # Reference: {FaunaDB Collections}[https://faunadb.com/documentation/queries#collection_functions]
199
+ # Reference: {FaunaDB Collections}[https://fauna.com/documentation/queries#collection_functions]
200
200
  def filter(collection, lambda_expr = nil, &lambda_block)
201
201
  Expr.new filter: Expr.wrap(lambda_expr || lambda_block), collection: Expr.wrap(collection)
202
202
  end
@@ -204,7 +204,7 @@ module Fauna
204
204
  ##
205
205
  # A take expression
206
206
  #
207
- # Reference: {FaunaDB Collections}[https://faunadb.com/documentation/queries#collection_functions]
207
+ # Reference: {FaunaDB Collections}[https://fauna.com/documentation/queries#collection_functions]
208
208
  def take(number, collection)
209
209
  Expr.new take: Expr.wrap(number), collection: Expr.wrap(collection)
210
210
  end
@@ -212,7 +212,7 @@ module Fauna
212
212
  ##
213
213
  # A drop expression
214
214
  #
215
- # Reference: {FaunaDB Collections}[https://faunadb.com/documentation/queries#collection_functions]
215
+ # Reference: {FaunaDB Collections}[https://fauna.com/documentation/queries#collection_functions]
216
216
  def drop(number, collection)
217
217
  Expr.new drop: Expr.wrap(number), collection: Expr.wrap(collection)
218
218
  end
@@ -220,7 +220,7 @@ module Fauna
220
220
  ##
221
221
  # A prepend expression
222
222
  #
223
- # Reference: {FaunaDB Collections}[https://faunadb.com/documentation/queries#collection_functions]
223
+ # Reference: {FaunaDB Collections}[https://fauna.com/documentation/queries#collection_functions]
224
224
  def prepend(collection, elements)
225
225
  Expr.new prepend: Expr.wrap(elements), collection: Expr.wrap(collection)
226
226
  end
@@ -228,7 +228,7 @@ module Fauna
228
228
  ##
229
229
  # An append expression
230
230
  #
231
- # Reference: {FaunaDB Collections}[https://faunadb.com/documentation/queries#collection_functions]
231
+ # Reference: {FaunaDB Collections}[https://fauna.com/documentation/queries#collection_functions]
232
232
  def append(collection, elements)
233
233
  Expr.new append: Expr.wrap(elements), collection: Expr.wrap(collection)
234
234
  end
@@ -238,7 +238,7 @@ module Fauna
238
238
  ##
239
239
  # A get expression
240
240
  #
241
- # Reference: {FaunaDB Read functions}[https://faunadb.com/documentation/queries#read_functions]
241
+ # Reference: {FaunaDB Read functions}[https://fauna.com/documentation/queries#read_functions]
242
242
  def get(ref, params = {})
243
243
  Expr.new Expr.wrap_values(params).merge(get: Expr.wrap(ref))
244
244
  end
@@ -246,7 +246,7 @@ module Fauna
246
246
  ##
247
247
  # A paginate expression
248
248
  #
249
- # Reference: {FaunaDB Read functions}[https://faunadb.com/documentation/queries#read_functions]
249
+ # Reference: {FaunaDB Read functions}[https://fauna.com/documentation/queries#read_functions]
250
250
  def paginate(set, params = {})
251
251
  Expr.new Expr.wrap_values(params).merge(paginate: Expr.wrap(set))
252
252
  end
@@ -254,25 +254,17 @@ module Fauna
254
254
  ##
255
255
  # An exists expression
256
256
  #
257
- # Reference: {FaunaDB Read functions}[https://faunadb.com/documentation/queries#read_functions]
257
+ # Reference: {FaunaDB Read functions}[https://fauna.com/documentation/queries#read_functions]
258
258
  def exists(ref, params = {})
259
259
  Expr.new Expr.wrap_values(params).merge(exists: Expr.wrap(ref))
260
260
  end
261
261
 
262
- ##
263
- # A count expression
264
- #
265
- # Reference: {FaunaDB Read functions}[https://faunadb.com/documentation/queries#read_functions]
266
- def count(set, params = {})
267
- Expr.new Expr.wrap_values(params).merge(count: Expr.wrap(set))
268
- end
269
-
270
262
  # :section: Write Functions
271
263
 
272
264
  ##
273
265
  # A create expression
274
266
  #
275
- # Reference: {FaunaDB Write functions}[https://faunadb.com/documentation/queries#write_functions]
267
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
276
268
  def create(class_ref, params)
277
269
  Expr.new create: Expr.wrap(class_ref), params: Expr.wrap(params)
278
270
  end
@@ -280,7 +272,7 @@ module Fauna
280
272
  ##
281
273
  # An update expression
282
274
  #
283
- # Reference: {FaunaDB Write functions}[https://faunadb.com/documentation/queries#write_functions]
275
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
284
276
  def update(ref, params)
285
277
  Expr.new update: Expr.wrap(ref), params: Expr.wrap(params)
286
278
  end
@@ -288,7 +280,7 @@ module Fauna
288
280
  ##
289
281
  # A replace expression
290
282
  #
291
- # Reference: {FaunaDB Write functions}[https://faunadb.com/documentation/queries#write_functions]
283
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
292
284
  def replace(ref, params)
293
285
  Expr.new replace: Expr.wrap(ref), params: Expr.wrap(params)
294
286
  end
@@ -296,7 +288,7 @@ module Fauna
296
288
  ##
297
289
  # A delete expression
298
290
  #
299
- # Reference: {FaunaDB Write functions}[https://faunadb.com/documentation/queries#write_functions]
291
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
300
292
  def delete(ref)
301
293
  Expr.new delete: Expr.wrap(ref)
302
294
  end
@@ -304,7 +296,7 @@ module Fauna
304
296
  ##
305
297
  # An insert expression
306
298
  #
307
- # Reference: {FaunaDB Write functions}[https://faunadb.com/documentation/queries#write_functions]
299
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
308
300
  def insert(ref, ts, action, params)
309
301
  Expr.new insert: Expr.wrap(ref), ts: Expr.wrap(ts), action: Expr.wrap(action), params: Expr.wrap(params)
310
302
  end
@@ -312,17 +304,49 @@ module Fauna
312
304
  ##
313
305
  # A remove expression
314
306
  #
315
- # Reference: {FaunaDB Write functions}[https://faunadb.com/documentation/queries#write_functions]
307
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
316
308
  def remove(ref, ts, action)
317
309
  Expr.new remove: Expr.wrap(ref), ts: Expr.wrap(ts), action: Expr.wrap(action)
318
310
  end
319
311
 
312
+ ##
313
+ # A create class expression
314
+ #
315
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
316
+ def create_class(params)
317
+ Expr.new create_class: Expr.wrap(params)
318
+ end
319
+
320
+ ##
321
+ # A create index expression
322
+ #
323
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
324
+ def create_index(params)
325
+ Expr.new create_index: Expr.wrap(params)
326
+ end
327
+
328
+ ##
329
+ # A create database expression
330
+ #
331
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
332
+ def create_database(params)
333
+ Expr.new create_database: Expr.wrap(params)
334
+ end
335
+
336
+ ##
337
+ # A create key expression
338
+ #
339
+ # Reference: {FaunaDB Write functions}[https://fauna.com/documentation/queries#write_functions]
340
+ def create_key(params)
341
+ Expr.new create_key: Expr.wrap(params)
342
+ end
343
+
320
344
  # :section: Set Functions
321
345
 
322
346
  ##
323
347
  # A match expression
324
348
  #
325
- # Reference: {FaunaDB Sets}[https://faunadb.com/documentation/queries#sets]
349
+ # Reference: {FaunaDB Sets}[https://fauna.com/documentation/queries#sets]
326
350
  def match(index, *terms)
327
351
  Expr.new match: Expr.wrap(index), terms: Expr.wrap_varargs(terms)
328
352
  end
@@ -330,7 +354,7 @@ module Fauna
330
354
  ##
331
355
  # A union expression
332
356
  #
333
- # Reference: {FaunaDB Sets}[https://faunadb.com/documentation/queries#sets]
357
+ # Reference: {FaunaDB Sets}[https://fauna.com/documentation/queries#sets]
334
358
  def union(*sets)
335
359
  Expr.new union: Expr.wrap_varargs(sets)
336
360
  end
@@ -338,7 +362,7 @@ module Fauna
338
362
  ##
339
363
  # An intersection expression
340
364
  #
341
- # Reference: {FaunaDB Sets}[https://faunadb.com/documentation/queries#sets]
365
+ # Reference: {FaunaDB Sets}[https://fauna.com/documentation/queries#sets]
342
366
  def intersection(*sets)
343
367
  Expr.new intersection: Expr.wrap_varargs(sets)
344
368
  end
@@ -346,7 +370,7 @@ module Fauna
346
370
  ##
347
371
  # A difference expression
348
372
  #
349
- # Reference: {FaunaDB Sets}[https://faunadb.com/documentation/queries#sets]
373
+ # Reference: {FaunaDB Sets}[https://fauna.com/documentation/queries#sets]
350
374
  def difference(*sets)
351
375
  Expr.new difference: Expr.wrap_varargs(sets)
352
376
  end
@@ -354,7 +378,7 @@ module Fauna
354
378
  ##
355
379
  # A distinct expression
356
380
  #
357
- # Reference: {FaunaDB Sets}[https://faunadb.com/documentation/queries#sets]
381
+ # Reference: {FaunaDB Sets}[https://fauna.com/documentation/queries#sets]
358
382
  def distinct(set)
359
383
  Expr.new distinct: Expr.wrap(set)
360
384
  end
@@ -365,7 +389,7 @@ module Fauna
365
389
  # Only one of +target_expr+ or +target_block+ should be provided.
366
390
  # For example: <code>Fauna.query { join(source) { |x| match some_index, x } }</code>.
367
391
  #
368
- # Reference: {FaunaDB Sets}[https://faunadb.com/documentation/queries#sets]
392
+ # Reference: {FaunaDB Sets}[https://fauna.com/documentation/queries#sets]
369
393
  def join(source, target_expr = nil, &target_block)
370
394
  Expr.new join: Expr.wrap(source), with: Expr.wrap(target_expr || target_block)
371
395
  end
@@ -375,7 +399,7 @@ module Fauna
375
399
  ##
376
400
  # A login function
377
401
  #
378
- # Reference: {FaunaDB Authentication}[https://faunadb.com/documentation/queries#auth_functions]
402
+ # Reference: {FaunaDB Authentication}[https://fauna.com/documentation/queries#auth_functions]
379
403
  def login(ref, params)
380
404
  Expr.new login: Expr.wrap(ref), params: Expr.wrap(params)
381
405
  end
@@ -383,7 +407,7 @@ module Fauna
383
407
  ##
384
408
  # A logout function
385
409
  #
386
- # Reference: {FaunaDB Authentication}[https://faunadb.com/documentation/queries#auth_functions]
410
+ # Reference: {FaunaDB Authentication}[https://fauna.com/documentation/queries#auth_functions]
387
411
  def logout(all_tokens)
388
412
  Expr.new logout: Expr.wrap(all_tokens)
389
413
  end
@@ -391,7 +415,7 @@ module Fauna
391
415
  ##
392
416
  # An identify function
393
417
  #
394
- # Reference: {FaunaDB Authentication}[https://faunadb.com/documentation/queries#auth_functions]
418
+ # Reference: {FaunaDB Authentication}[https://fauna.com/documentation/queries#auth_functions]
395
419
  def identify(ref, password)
396
420
  Expr.new identify: Expr.wrap(ref), password: Expr.wrap(password)
397
421
  end
@@ -401,7 +425,7 @@ module Fauna
401
425
  ##
402
426
  # A concat function
403
427
  #
404
- # Reference: {FaunaDB String Functions}[https://faunadb.com/documentation/queries#string_functions]
428
+ # Reference: {FaunaDB String Functions}[https://fauna.com/documentation/queries#string_functions]
405
429
  def concat(strings, separator = nil)
406
430
  if separator.nil?
407
431
  Expr.new concat: Expr.wrap(strings)
@@ -413,7 +437,7 @@ module Fauna
413
437
  ##
414
438
  # A casefold function
415
439
  #
416
- # Reference: {FaunaDB String Functions}[https://faunadb.com/documentation/queries#string_functions]
440
+ # Reference: {FaunaDB String Functions}[https://fauna.com/documentation/queries#string_functions]
417
441
  def casefold(string)
418
442
  Expr.new casefold: Expr.wrap(string)
419
443
  end
@@ -423,7 +447,7 @@ module Fauna
423
447
  ##
424
448
  # A time expression
425
449
  #
426
- # Reference: {FaunaDB Time Functions}[https://faunadb.com/documentation/queries#time_functions]
450
+ # Reference: {FaunaDB Time Functions}[https://fauna.com/documentation/queries#time_functions]
427
451
  def time(string)
428
452
  Expr.new time: Expr.wrap(string)
429
453
  end
@@ -431,7 +455,7 @@ module Fauna
431
455
  ##
432
456
  # An epoch expression
433
457
  #
434
- # Reference: {FaunaDB Time Functions}[https://faunadb.com/documentation/queries#time_functions]
458
+ # Reference: {FaunaDB Time Functions}[https://fauna.com/documentation/queries#time_functions]
435
459
  def epoch(number, unit)
436
460
  Expr.new epoch: Expr.wrap(number), unit: Expr.wrap(unit)
437
461
  end
@@ -439,7 +463,7 @@ module Fauna
439
463
  ##
440
464
  # A date expression
441
465
  #
442
- # Reference: {FaunaDB Time Functions}[https://faunadb.com/documentation/queries#time_functions]
466
+ # Reference: {FaunaDB Time Functions}[https://fauna.com/documentation/queries#time_functions]
443
467
  def date(string)
444
468
  Expr.new date: Expr.wrap(string)
445
469
  end
@@ -449,15 +473,39 @@ module Fauna
449
473
  ##
450
474
  # A next_id function
451
475
  #
452
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation#queries-misc_functions]
476
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation#queries-misc_functions]
453
477
  def next_id
454
478
  Expr.new next_id: nil
455
479
  end
456
480
 
481
+ ##
482
+ # A database function
483
+ #
484
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation#queries-misc_functions]
485
+ def database(name)
486
+ Expr.new database: Expr.wrap(name)
487
+ end
488
+
489
+ ##
490
+ # A class function
491
+ #
492
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation#queries-misc_functions]
493
+ def class_(name)
494
+ Expr.new class: Expr.wrap(name)
495
+ end
496
+
497
+ ##
498
+ # An index function
499
+ #
500
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation#queries-misc_functions]
501
+ def index(name)
502
+ Expr.new index: Expr.wrap(name)
503
+ end
504
+
457
505
  ##
458
506
  # An equals function
459
507
  #
460
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation#queries-misc_functions]
508
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation#queries-misc_functions]
461
509
  def equals(*values)
462
510
  Expr.new equals: Expr.wrap_varargs(values)
463
511
  end
@@ -465,7 +513,7 @@ module Fauna
465
513
  ##
466
514
  # A contains function
467
515
  #
468
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
516
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
469
517
  def contains(path, in_)
470
518
  Expr.new contains: Expr.wrap(path), in: Expr.wrap(in_)
471
519
  end
@@ -473,7 +521,7 @@ module Fauna
473
521
  ##
474
522
  # A select function
475
523
  #
476
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
524
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
477
525
  def select(path, from, params = {})
478
526
  Expr.new Expr.wrap_values(params).merge(select: Expr.wrap(path), from: Expr.wrap(from))
479
527
  end
@@ -481,7 +529,7 @@ module Fauna
481
529
  ##
482
530
  # An add function
483
531
  #
484
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
532
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
485
533
  def add(*numbers)
486
534
  Expr.new add: Expr.wrap_varargs(numbers)
487
535
  end
@@ -489,7 +537,7 @@ module Fauna
489
537
  ##
490
538
  # A multiply function
491
539
  #
492
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
540
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
493
541
  def multiply(*numbers)
494
542
  Expr.new multiply: Expr.wrap_varargs(numbers)
495
543
  end
@@ -497,7 +545,7 @@ module Fauna
497
545
  ##
498
546
  # A subtract function
499
547
  #
500
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
548
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
501
549
  def subtract(*numbers)
502
550
  Expr.new subtract: Expr.wrap_varargs(numbers)
503
551
  end
@@ -505,7 +553,7 @@ module Fauna
505
553
  ##
506
554
  # A divide function
507
555
  #
508
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
556
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
509
557
  def divide(*numbers)
510
558
  Expr.new divide: Expr.wrap_varargs(numbers)
511
559
  end
@@ -513,7 +561,7 @@ module Fauna
513
561
  ##
514
562
  # A modulo function
515
563
  #
516
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
564
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
517
565
  def modulo(*numbers)
518
566
  Expr.new modulo: Expr.wrap_varargs(numbers)
519
567
  end
@@ -521,7 +569,7 @@ module Fauna
521
569
  ##
522
570
  # A less than function
523
571
  #
524
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
572
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
525
573
  def lt(*values)
526
574
  Expr.new lt: Expr.wrap_varargs(values)
527
575
  end
@@ -529,7 +577,7 @@ module Fauna
529
577
  ##
530
578
  # A less than or equal function
531
579
  #
532
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
580
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
533
581
  def lte(*values)
534
582
  Expr.new lte: Expr.wrap_varargs(values)
535
583
  end
@@ -537,7 +585,7 @@ module Fauna
537
585
  ##
538
586
  # A greater than function
539
587
  #
540
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
588
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
541
589
  def gt(*values)
542
590
  Expr.new gt: Expr.wrap_varargs(values)
543
591
  end
@@ -545,7 +593,7 @@ module Fauna
545
593
  ##
546
594
  # A greater than or equal function
547
595
  #
548
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
596
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
549
597
  def gte(*values)
550
598
  Expr.new gte: Expr.wrap_varargs(values)
551
599
  end
@@ -553,7 +601,7 @@ module Fauna
553
601
  ##
554
602
  # An and function
555
603
  #
556
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
604
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
557
605
  def and_(*booleans)
558
606
  Expr.new and: Expr.wrap_varargs(booleans)
559
607
  end
@@ -561,7 +609,7 @@ module Fauna
561
609
  ##
562
610
  # An or function
563
611
  #
564
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
612
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
565
613
  def or_(*booleans)
566
614
  Expr.new or: Expr.wrap_varargs(booleans)
567
615
  end
@@ -569,7 +617,7 @@ module Fauna
569
617
  ##
570
618
  # A not function
571
619
  #
572
- # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation/queries#misc_functions]
620
+ # Reference: {FaunaDB Miscellaneous Functions}[https://fauna.com/documentation/queries#misc_functions]
573
621
  def not_(boolean)
574
622
  Expr.new not: Expr.wrap(boolean)
575
623
  end
@@ -1,4 +1,4 @@
1
1
  module Fauna
2
2
  # The version of the Fauna gem
3
- VERSION = '2.1.2'.freeze
3
+ VERSION = '2.2.0'.freeze
4
4
  end
@@ -31,6 +31,15 @@ RSpec.describe 'Fauna Errors' do
31
31
  Fauna::Client.new(adapter: [:test, stubs])
32
32
  end
33
33
 
34
+ # Create client with stub adapter responding to / with the given exception
35
+ def stub_error(exception)
36
+ stubs = Faraday::Adapter::Test::Stubs.new
37
+ stubs.get '/' do
38
+ fail exception
39
+ end
40
+ Fauna::Client.new(adapter: [:test, stubs])
41
+ end
42
+
34
43
  it 'sets request result' do
35
44
  expect { client.post '', foo: 'bar' }.to raise_error do |err|
36
45
  expect(err).to be_a(Fauna::BadRequest)
@@ -114,10 +123,25 @@ RSpec.describe 'Fauna Errors' do
114
123
  end
115
124
 
116
125
  describe Fauna::UnavailableError do
117
- it 'is handled' do
126
+ it 'handles fauna 503' do
118
127
  stub_client = stub_get 503, '{"errors": [{"code": "unavailable", "description": "on vacation"}]}'
119
128
  expect { stub_client.get '' }.to raise_fauna_error(Fauna::UnavailableError, 'unavailable')
120
129
  end
130
+
131
+ it 'handles upstream 503' do
132
+ stub_client = stub_get 503, 'Unable to reach server'
133
+ expect { stub_client.get '' }.to raise_error(Fauna::UnavailableError, 'Unable to reach server')
134
+ end
135
+
136
+ it 'handles timeout error' do
137
+ stub_client = stub_error Faraday::TimeoutError.new('timeout')
138
+ expect { stub_client.get '' }.to raise_error(Fauna::UnavailableError, 'Faraday::TimeoutError: timeout')
139
+ end
140
+
141
+ it 'handles connection error' do
142
+ stub_client = stub_error Faraday::ConnectionFailed.new('connection refused')
143
+ expect { stub_client.get '' }.to raise_error(Fauna::UnavailableError, 'Faraday::ConnectionFailed: connection refused')
144
+ end
121
145
  end
122
146
 
123
147
  describe Fauna::UnexpectedError do
@@ -144,5 +168,9 @@ RSpec.describe 'Fauna Errors' do
144
168
  it 'raised for empty errors' do
145
169
  expect { stub_get(500, '{"errors": []}').get('') }.to raise_error(Fauna::UnexpectedError, /blank/)
146
170
  end
171
+
172
+ it 'raised for parsing error' do
173
+ expect { stub_error(Faraday::ParsingError.new('parse error')).get('') }.to raise_error(Fauna::UnexpectedError, /parse error/)
174
+ end
147
175
  end
148
176
  end
@@ -23,6 +23,11 @@ module FaunaTestHelpers
23
23
  @server_client
24
24
  end
25
25
 
26
+ def admin_client
27
+ fail 'Admin client not initialized' if @admin_client.nil?
28
+ @admin_client
29
+ end
30
+
26
31
  def create_test_db
27
32
  @db_ref = Fauna::Ref.new "databases/faunadb-ruby-test-#{random_string}"
28
33
 
@@ -31,6 +36,7 @@ module FaunaTestHelpers
31
36
 
32
37
  begin
33
38
  server_key = root.query { create ref('keys'), database: @db_ref, role: 'server' }
39
+ admin_key = root.query { create ref('keys'), database: @db_ref, role: 'admin' }
34
40
  rescue
35
41
  root.query { delete @db_ref }
36
42
  @db_ref = nil
@@ -39,6 +45,8 @@ module FaunaTestHelpers
39
45
 
40
46
  @server_secret = server_key[:secret]
41
47
  @server_client = get_client secret: @server_secret
48
+ @admin_secret = admin_key[:secret]
49
+ @admin_client = get_client secret: @admin_secret
42
50
  end
43
51
 
44
52
  def destroy_test_db
@@ -320,20 +320,6 @@ RSpec.describe Fauna::Query do
320
320
  end
321
321
  end
322
322
 
323
- describe '#count' do
324
- before do
325
- @x_value = random_number
326
- @x_refs = (1..3).collect { create_instance(x: @x_value)[:ref] }
327
- end
328
-
329
- it 'performs count' do
330
- set = Fauna::Query.match(@test_by_x, @x_value)
331
-
332
- # Count is only approximate; should be equal to @x_refs.length
333
- expect(client.query { count set }).to be_a(Integer)
334
- end
335
- end
336
-
337
323
  describe '#create' do
338
324
  it 'performs create' do
339
325
  instance = client.query { create(@test_class, {}) }
@@ -406,6 +392,48 @@ RSpec.describe Fauna::Query do
406
392
  end
407
393
  end
408
394
 
395
+ describe '#create_class' do
396
+ it 'creates a class' do
397
+ # Create a class
398
+ ref = client.query { create_class(name: random_string) }[:ref]
399
+
400
+ # Assert it was created
401
+ expect(client.query { exists(ref) }).to be(true)
402
+ end
403
+ end
404
+
405
+ describe '#create_index' do
406
+ it 'creates an index' do
407
+ # Create an index
408
+ class_ref = client.query { create(ref('classes'), name: random_string) }[:ref]
409
+ ref = client.query { create_index(name: random_string, source: class_ref) }[:ref]
410
+
411
+ # Assert it was created
412
+ expect(client.query { exists(ref) }).to be(true)
413
+ end
414
+ end
415
+
416
+ describe '#create_database' do
417
+ it 'creates a database' do
418
+ # Create a database
419
+ ref = admin_client.query { create_database(name: random_string) }[:ref]
420
+
421
+ # Assert it was created
422
+ expect(admin_client.query { exists(ref) }).to be(true)
423
+ end
424
+ end
425
+
426
+ describe '#create_key' do
427
+ it 'creates a key' do
428
+ # Create a key
429
+ db_ref = admin_client.query { create(ref('databases'), name: random_string) }[:ref]
430
+ ref = admin_client.query { create_key(database: db_ref, role: 'server') }[:ref]
431
+
432
+ # Assert it was created
433
+ expect(admin_client.query { exists(ref) }).to be(true)
434
+ end
435
+ end
436
+
409
437
  describe 'sets' do
410
438
  before do
411
439
  @x_value = random_number
@@ -593,6 +621,40 @@ RSpec.describe Fauna::Query do
593
621
  end
594
622
  end
595
623
 
624
+ describe '#database' do
625
+ it 'gets an existing database' do
626
+ # Create a database
627
+ name = random_string
628
+ ref = admin_client.query { create_database(name: name) }[:ref]
629
+
630
+ # Get the database ref
631
+ expect(admin_client.query { database(name) }).to eq(ref)
632
+ end
633
+ end
634
+
635
+ describe '#class' do
636
+ it 'gets an existing class' do
637
+ # Create a class
638
+ name = random_string
639
+ ref = client.query { create_class(name: name) }[:ref]
640
+
641
+ # Get the class ref
642
+ expect(client.query { class_(name) }).to eq(ref)
643
+ end
644
+ end
645
+
646
+ describe '#index' do
647
+ it 'gets an existing index' do
648
+ # Create an index
649
+ class_ref = client.query { create_class(name: random_string) }[:ref]
650
+ name = random_string
651
+ ref = client.query { create_index(name: name, source: class_ref) }[:ref]
652
+
653
+ # Get the index ref
654
+ expect(client.query { index(name) }).to eq(ref)
655
+ end
656
+ end
657
+
596
658
  describe '#equals' do
597
659
  it 'performs equals' do
598
660
  expect(client.query { equals(1, 1, 1) }).to be(true)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fauna
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fauna, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-06 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -81,21 +81,21 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.38.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: coveralls
84
+ name: codecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.14
89
+ version: 0.1.5
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.14
96
+ version: 0.1.5
97
97
  description: Ruby driver for FaunaDB.
98
- email: priority@faunadb.com
98
+ email: priority@fauna.com
99
99
  executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files:
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.5.1
161
+ rubygems_version: 2.4.5.1
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: FaunaDB Ruby driver