unreql 0.2.1

Well documented and easy to use RethinkDB Rust Driver
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
use ql2::term::TermType;
use serde::Serialize;
use unreql_macros::create_cmd;

use crate::{
    cmd::{
        args::{ManyArgs, Opt},
        options::{CircleOptions, DistanceOptions, GetNearestOptions, Index},
    },
    Command,
};

create_cmd!(
    /// Construct a circular line or polygon.
    ///
    /// A circle in RethinkDB is a polygon or line approximating a circle of
    /// a given radius around a given center, consisting of a specified number
    /// of vertices (default 32).
    ///
    /// The center may be specified either by two floating point numbers,
    /// the latitude (−90 to 90) and longitude (−180 to 180) of the point
    /// on a perfect sphere (see Geospatial support for more information
    /// on ReQL’s coordinate system), or by a point object. The radius is
    /// a floating point number whose units are meters by default, although
    /// that may be changed with the `unit` argument.
    ///
    /// ## Example
    /// Define a circle.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # unreql::example(|r, conn| {
    /// r.table("geo").insert(rjson!({
    ///     "id": 300,
    ///     "name": "Hayes Valley",
    ///     "neighborhood": r.circle(r.args(([-122.423246,37.779388], 1000)))
    /// })).run(conn)
    /// # })
    /// ```
    ///
    /// # Related commands
    /// - [line](Self::line)
    /// - [polygon](Self::polygon)
    /// - [point](Self::point)
    /// - [distance](Self::distance)
    only_root,
    circle(point_radius: ManyArgs<CircleOptions>)
);

create_cmd!(
    /// Compute the distance between a point and another geometry object.
    ///
    /// At least one of the geometry objects specified must be a point.
    ///
    /// If one of the objects is a polygon or a line, the point will be
    /// projected onto the line or polygon assuming a perfect sphere model
    /// before the distance is computed (using the model specified with
    /// `geoSystem`). As a consequence, if the polygon or line is extremely
    /// large compared to Earth’s radius and the distance is being computed
    /// with the default WGS84 model, the results of `distance` should be
    /// considered approximate due to the deviation between the ellipsoid
    /// and spherical models.
    ///
    /// ## Example
    /// Compute the distance between two points on the Earth in kilometers.
    ///
    /// ```
    /// # use unreql::cmd::options::DistanceOptions;
    /// # unreql::example(|r, conn| {
    /// let point1 = r.point(-122.423246, 37.779388);
    /// let point2 = r.point(-117.220406, 32.719464);
    /// let opts = DistanceOptions::new().unit("km".into());
    /// r.distance(point1, point2, opts).run(conn)
    /// // Result: 734.1252496021841
    /// # })
    /// ```
    only_root,
    distance(point1: Serialize, point2: Serialize, opts: Opt<DistanceOptions>)
    only_command,
    distance(point: Serialize, opts: Opt<DistanceOptions>)
);

create_cmd!(
    /// Convert a Line object into a Polygon object.
    ///
    /// If the last point does not specify the same coordinates as the
    /// first point, polygon will close the polygon by connecting them.
    ///
    /// Longitude (−180 to 180) and latitude (−90 to 90) of vertices are
    /// plotted on a perfect sphere. See Geospatial support for more
    /// information on ReQL’s coordinate system.
    ///
    /// If the last point does not specify the same coordinates as the first
    /// point, polygon will close the polygon by connecting them. You cannot
    /// directly construct a polygon with holes in it using polygon, but you
    /// can use polygonSub to use a second polygon within the interior of the
    /// first to define a hole.
    ///
    /// ## Example
    /// Create a line object and then convert it to a polygon.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # use unreql::cmd::options::UpdateOptions;
    /// # unreql::example(|r, conn| {
    /// r.table("geo").insert(rjson!({
    ///     "id": 201,
    ///     "rectangle": r.line(r.args([
    ///         [-122.423246,37.779388],
    ///         [-122.423246,37.329898],
    ///         [-121.886420,37.329898],
    ///         [-121.886420,37.779388]
    ///     ]))
    /// })).run(conn)
    /// # });
    ///
    /// # unreql::example(|r, conn| {
    /// r.table("geo").get(201).update(r.with_opt(
    ///     rjson!({
    ///         "rectangle": r.row().g("rectangle").fill()
    ///     }),
    ///     UpdateOptions::new().non_atomic(true)
    /// )).run(conn)
    /// # })
    /// ```
    ///
    /// # Related commands
    /// - [line](Self::line)
    /// - [polygon](Self::polygon)
    only_command,
    fill
);

create_cmd!(
    /// Convert a [GeoJSON](http://geojson.org/) object to a ReQL geometry object.
    ///
    /// RethinkDB only allows conversion of GeoJSON objects which have ReQL
    /// equivalents: Point, LineString, and Polygon. MultiPoint,
    /// MultiLineString, and MultiPolygon are not supported. (You could,
    /// however, store multiple points, lines and polygons in an array and
    /// use a geospatial multi index with them.)
    ///
    /// Only longitude/latitude coordinates are supported. GeoJSON objects
    /// that use Cartesian coordinates, specify an altitude, or specify their
    /// own coordinate reference system will be rejected.
    ///
    /// ## Example
    /// Convert a GeoJSON object to a ReQL geometry object.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # unreql::example(|r, conn| {
    /// let geojson = rjson!({
    ///     "type": "Point",
    ///     "coordinates": [ -122.423246, 37.779388 ]
    /// });
    /// r.table("geo").insert(rjson!({
    ///     "id": "sfo",
    ///     "name": "San Francisco",
    ///     "location": r.geojson(geojson),
    /// })).run(conn)
    /// # })
    /// ```
    only_root,
    geojson(geojson: Serialize)
);

create_cmd!(
    /// Convert a ReQL geometry object to a [GeoJSON](http://geojson.org/) object.
    ///
    /// ## Example
    /// Convert a ReQL geometry object to a GeoJSON object.
    ///
    /// ```
    /// # unreql::example(|r, conn| {
    /// r.table("geo").get("sfo").g("location").to_geojson().run(conn)
    /// # })
    /// ```
    ///
    /// Result
    ///
    /// ```json
    /// {
    ///     "type": "Point",
    ///     "coordinates": [ -122.423246, 37.779388 ]
    /// }
    /// ```
    only_command,
    to_geojson
);

create_cmd!(
    /// Get all documents where the given geometry object intersects
    /// the geometry object of the requested geospatial index.
    ///
    /// The `index` argument is mandatory. This command returns the same
    /// results as `table.filter(r.row().g("index").intersects(geometry))`.
    /// The total number of results is limited to the array size limit
    /// which defaults to 100,000, but can be changed with the `arrayLimit`
    /// option to `run`.
    ///
    /// ## Example
    /// Which of the locations in a list of parks intersect circle1?
    ///
    /// ```
    /// # use unreql::cmd::options::CircleOptions;
    /// # unreql::example(|r, conn| {
    /// let unit = CircleOptions::new().unit("mi".into());
    /// let circle1 = r.circle(r.with_opt(r.args(([-117.220406,32.719464], 10)), unit));
    /// r.table("parks").get_intersecting(circle1, r.index("area")).run(conn)
    /// # })
    /// ```
    get_intersecting(geometry: Serialize, opts: Opt<Index>)
);

create_cmd!(
    /// Return a list of documents closest to a specified point based on
    /// a geospatial index, sorted in order of increasing distance.
    ///
    /// The `index` argument is mandatory.
    ///
    /// The return value will be an array of two-item objects with the keys
    /// dist and doc, set to the distance between the specified point and
    /// the document (in the units specified with unit, defaulting to meters)
    /// and the document itself, respectively. The array will be sorted by
    /// the values of dist.
    ///
    /// ## Example
    /// Return a list of the closest 25 enemy hideouts to the secret base.
    ///
    /// ```
    /// # use unreql::cmd::options::GetNearestOptions;
    /// # unreql::example(|r, conn| {
    /// let secret_base = r.point(-122.422876,37.777128);
    /// let opts = GetNearestOptions::new()
    ///     .index("area".into())
    ///     .max_results(25);
    /// r.table("hideouts").get_nearest(secret_base, opts).run(conn)
    /// # })
    /// ```
    ///
    /// *Note*: If you wish to find all points within a certain radius of
    /// another point, it’s often faster to use getIntersecting with circle,
    /// as long as the approximation of a circle that circle generates is
    /// sufficient.
    get_nearest(point: Serialize, opts: Opt<GetNearestOptions>)
);

create_cmd!(
    /// Tests whether a geometry object is completely contained within another.
    ///
    /// When applied to a sequence of geometry objects, includes acts as
    /// a filter, returning a sequence of objects from the sequence that
    /// include the argument.
    ///
    /// ## Example
    /// Is point2 included within a 2000-meter circle around point1?
    ///
    /// ```
    /// # unreql::example(|r, conn| {
    /// let point1 = r.point(-122.423246, 37.779388);
    /// let point2 = r.point(-117.220406, 32.719464);
    /// r.circle(r.args((point1, 2000))).includes(point2).run(conn)
    /// // Result: true
    /// # })
    /// ```
    includes(geometry: Serialize)
);

create_cmd!(
    /// Tests whether two geometry objects intersect with one another.
    ///
    /// When applied to a sequence of geometry objects, intersects acts as
    /// a filter, returning a sequence of objects from the sequence that
    /// intersect with the argument.
    ///
    /// ## Example
    /// Is point2 within a 2000-meter circle around point1?
    ///
    /// ```
    /// # unreql::example(|r, conn| {
    /// let point1 = r.point(-122.423246, 37.779388);
    /// let point2 = r.point(-117.220406, 32.719464);
    /// r.circle(r.args((point1, 2000))).intersects(point2).run(conn)
    /// // Result: true
    /// # })
    /// ```
    only_root,
    intersects(sequence_or_geometry: Serialize, geometry: Serialize),
    only_command,
    intersects(geometry: Serialize),
);

create_cmd!(
    /// Construct a geometry object of type Line.
    ///
    /// The line can be specified in one of two ways:
    ///
    /// - Two or more two-item arrays, specifying latitude and longitude
    ///   numbers of the line’s vertices;
    /// - Two or more Point objects specifying the line’s vertices.
    ///
    /// Longitude (−180 to 180) and latitude (−90 to 90) of vertices are
    /// plotted on a perfect sphere. See Geospatial support for more
    /// information on ReQL’s coordinate system.
    ///
    /// ## Example
    /// Define a line.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # unreql::example(|r, conn| {
    /// r.table("geo").insert(rjson!({
    ///     "id": 101,
    ///     "route": r.line(r.args([[-122.423246,37.779388], [-121.886420,37.329898]]))
    /// })).run(conn)
    /// # })
    /// ```
    ///
    /// ## Example
    /// Define a line using an array of points.
    /// You can use the args command to pass an array of Point objects (or latitude-longitude pairs) to line.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # unreql::example(|r, conn| {
    /// let route = [
    ///     [-122.423246, 37.779388],
    ///     [-121.886420, 37.329898],
    /// ];
    /// r.table("geo").insert(rjson!({
    ///     "id": 102,
    ///     "route": r.line(r.args(route)),
    /// })).run(conn)
    /// # })
    /// ```
    only_root,
    line(points: ManyArgs<()>)
);

create_cmd!(
    /// ruct a geometry object of type Point.
    ///
    /// The point is specified by two floating point numbers, the longitude
    /// (−180 to 180) and latitude (−90 to 90) of the point on a perfect
    /// sphere. See [Geospatial support](https://rethinkdb.com/docs/geo-support/javascript/) for more information on ReQL’s
    /// coordinate system.
    ///
    /// ## Example
    /// Define a point.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # unreql::example(|r, conn| {
    /// r.table("geo").insert(rjson!({
    ///     "id": 1,
    ///     "name": "San Francisco",
    ///     "location": r.point(-122.423246, 37.779388)
    /// })).run(conn)
    /// # })
    /// ```
    only_root,
    point(longitude: Serialize, latitude: Serialize)
);

create_cmd!(
    /// Construct a geometry object of type Polygon.
    ///
    /// The Polygon can be specified in one of two ways:
    ///
    /// - Three or more two-item arrays, specifying latitude and longitude
    ///   numbers of the polygon’s vertices;
    /// - Three or more Point objects specifying the polygon’s vertices.
    ///
    /// Longitude (−180 to 180) and latitude (−90 to 90) of vertices are
    /// plotted on a perfect sphere. See Geospatial support for more
    /// information on ReQL’s coordinate system.
    ///
    /// If the last point does not specify the same coordinates as the
    /// first point, polygon will close the polygon by connecting them.
    /// You cannot directly construct a polygon with holes in it using
    /// polygon, but you can use polygonSub to use a second polygon
    /// within the interior of the first to define a hole.
    ///
    /// ## Example
    /// Define a polygon.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # unreql::example(|r, conn| {
    /// r.table("geo").insert(rjson!({
    ///     "id": 101,
    ///     "rectangle": r.polygon(r.args([
    ///         [-122.423246,37.779388],
    ///         [-122.423246,37.329898],
    ///         [-121.886420,37.329898],
    ///         [-121.886420,37.779388]
    ///     ]))
    /// })).run(conn)
    /// # })
    /// ```
    only_root,
    polygon(points: ManyArgs<()>)
);

create_cmd!(
    /// Use `polygon2` to “punch out” a hole in `polygon1`.
    ///
    /// `polygon2` must be completely contained within `polygon1` and must
    /// have no holes itself (it must not be the output of `polygon_sub` itself).
    ///
    /// ## Example
    /// Define a polygon with a hole punched in it.
    ///
    /// ```
    /// # use unreql::rjson;
    /// # unreql::example(|r, conn| {
    /// let outer_polygon = r.polygon(r.args([
    ///     [-122.4,37.7],
    ///     [-122.4,37.3],
    ///     [-121.8,37.3],
    ///     [-121.8,37.7]
    /// ]));
    /// let inner_polygon = r.polygon(r.args([
    ///     [-122.3,37.4],
    ///     [-122.3,37.6],
    ///     [-122.0,37.6],
    ///     [-122.0,37.4]
    /// ]));
    /// outer_polygon.polygon_sub(inner_polygon).run(conn)
    /// # })
    /// ```
    polygon_sub(polygon2: Serialize)
);