gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/ql2/ql2.proto (about) 1 //////////////////////////////////////////////////////////////////////////////// 2 // THE HIGH-LEVEL VIEW // 3 //////////////////////////////////////////////////////////////////////////////// 4 5 // Process: When you first open a connection, send the magic number 6 // for the version of the protobuf you're targeting (in the [Version] 7 // enum). This should **NOT** be sent as a protobuf; just send the 8 // little-endian 32-bit integer over the wire raw. This number should 9 // only be sent once per connection. 10 11 // The magic number shall be followed by an authorization key. The 12 // first 4 bytes are the length of the key to be sent as a little-endian 13 // 32-bit integer, followed by the key string. Even if there is no key, 14 // an empty string should be sent (length 0 and no data). 15 16 // Following the authorization key, the client shall send a magic number 17 // for the communication protocol they want to use (in the [Protocol] 18 // enum). This shall be a little-endian 32-bit integer. 19 20 // The server will then respond with a NULL-terminated string response. 21 // "SUCCESS" indicates that the connection has been accepted. Any other 22 // response indicates an error, and the response string should describe 23 // the error. 24 25 // Next, for each query you want to send, construct a [Query] protobuf 26 // and serialize it to a binary blob. Send the blob's size to the 27 // server encoded as a little-endian 32-bit integer, followed by the 28 // blob itself. You will recieve a [Response] protobuf back preceded 29 // by its own size, once again encoded as a little-endian 32-bit 30 // integer. You can see an example exchange below in **EXAMPLE**. 31 32 // A query consists of a [Term] to evaluate and a unique-per-connection 33 // [token]. 34 35 // Tokens are used for two things: 36 // * Keeping track of which responses correspond to which queries. 37 // * Batched queries. Some queries return lots of results, so we send back 38 // batches of <1000, and you need to send a [CONTINUE] query with the same 39 // token to get more results from the original query. 40 //////////////////////////////////////////////////////////////////////////////// 41 42 syntax = "proto2"; 43 44 message VersionDummy { // We need to wrap it like this for some 45 // non-conforming protobuf libraries 46 // This enum contains the magic numbers for your version. See **THE HIGH-LEVEL 47 // VIEW** for what to do with it. 48 enum Version { 49 V0_1 = 0x3f61ba36; 50 V0_2 = 0x723081e1; // Authorization key during handshake 51 V0_3 = 0x5f75e83e; // Authorization key and protocol during handshake 52 V0_4 = 0x400c2d20; // Queries execute in parallel 53 V1_0 = 0x34c2bdc3; // Users and permissions 54 } 55 56 // The protocol to use after the handshake, specified in V0_3 57 enum Protocol { 58 PROTOBUF = 0x271ffc41; 59 JSON = 0x7e6970c7; 60 } 61 } 62 63 // You send one of: 64 // * A [START] query with a [Term] to evaluate and a unique-per-connection token. 65 // * A [CONTINUE] query with the same token as a [START] query that returned 66 // [SUCCESS_PARTIAL] in its [Response]. 67 // * A [STOP] query with the same token as a [START] query that you want to stop. 68 // * A [NOREPLY_WAIT] query with a unique per-connection token. The server answers 69 // with a [WAIT_COMPLETE] [Response]. 70 // * A [SERVER_INFO] query. The server answers with a [SERVER_INFO] [Response]. 71 message Query { 72 enum QueryType { 73 START = 1; // Start a new query. 74 CONTINUE = 2; // Continue a query that returned [SUCCESS_PARTIAL] 75 // (see [Response]). 76 STOP = 3; // Stop a query partway through executing. 77 NOREPLY_WAIT = 4; // Wait for noreply operations to finish. 78 SERVER_INFO = 5; // Get server information. 79 } 80 optional QueryType type = 1; 81 // A [Term] is how we represent the operations we want a query to perform. 82 optional Term query = 2; // only present when [type] = [START] 83 optional int64 token = 3; 84 // This flag is ignored on the server. `noreply` should be added 85 // to `global_optargs` instead (the key "noreply" should map to 86 // either true or false). 87 optional bool OBSOLETE_noreply = 4 [default = false]; 88 89 // If this is set to [true], then [Datum] values will sometimes be 90 // of [DatumType] [R_JSON] (see below). This can provide enormous 91 // speedups in languages with poor protobuf libraries. 92 optional bool accepts_r_json = 5 [default = false]; 93 94 message AssocPair { 95 optional string key = 1; 96 optional Term val = 2; 97 } 98 repeated AssocPair global_optargs = 6; 99 } 100 101 // A backtrace frame (see `backtrace` in Response below) 102 message Frame { 103 enum FrameType { 104 POS = 1; // Error occurred in a positional argument. 105 OPT = 2; // Error occurred in an optional argument. 106 } 107 optional FrameType type = 1; 108 optional int64 pos = 2; // The index of the positional argument. 109 optional string opt = 3; // The name of the optional argument. 110 } 111 message Backtrace { 112 repeated Frame frames = 1; 113 } 114 115 // You get back a response with the same [token] as your query. 116 message Response { 117 enum ResponseType { 118 // These response types indicate success. 119 SUCCESS_ATOM = 1; // Query returned a single RQL datatype. 120 SUCCESS_SEQUENCE = 2; // Query returned a sequence of RQL datatypes. 121 SUCCESS_PARTIAL = 3; // Query returned a partial sequence of RQL 122 // datatypes. If you send a [CONTINUE] query with 123 // the same token as this response, you will get 124 // more of the sequence. Keep sending [CONTINUE] 125 // queries until you get back [SUCCESS_SEQUENCE]. 126 WAIT_COMPLETE = 4; // A [NOREPLY_WAIT] query completed. 127 SERVER_INFO = 5; // The data for a [SERVER_INFO] request. This is 128 // the same as `SUCCESS_ATOM` except that there will 129 // never be profiling data. 130 131 // These response types indicate failure. 132 CLIENT_ERROR = 16; // Means the client is buggy. An example is if the 133 // client sends a malformed protobuf, or tries to 134 // send [CONTINUE] for an unknown token. 135 COMPILE_ERROR = 17; // Means the query failed during parsing or type 136 // checking. For example, if you pass too many 137 // arguments to a function. 138 RUNTIME_ERROR = 18; // Means the query failed at runtime. An example is 139 // if you add together two values from a table, but 140 // they turn out at runtime to be booleans rather 141 // than numbers. 142 } 143 optional ResponseType type = 1; 144 145 // If `ResponseType` is `RUNTIME_ERROR`, this may be filled in with more 146 // information about the error. 147 enum ErrorType { 148 INTERNAL = 1000000; 149 RESOURCE_LIMIT = 2000000; 150 QUERY_LOGIC = 3000000; 151 NON_EXISTENCE = 3100000; 152 OP_FAILED = 4100000; 153 OP_INDETERMINATE = 4200000; 154 USER = 5000000; 155 PERMISSION_ERROR = 6000000; 156 } 157 optional ErrorType error_type = 7; 158 159 // ResponseNotes are used to provide information about the query 160 // response that may be useful for people writing drivers or ORMs. 161 // Currently all the notes we send indicate that a stream has certain 162 // special properties. 163 enum ResponseNote { 164 // The stream is a changefeed stream (e.g. `r.table('test').changes()`). 165 SEQUENCE_FEED = 1; 166 // The stream is a point changefeed stream 167 // (e.g. `r.table('test').get(0).changes()`). 168 ATOM_FEED = 2; 169 // The stream is an order_by_limit changefeed stream 170 // (e.g. `r.table('test').order_by(index: 'id').limit(5).changes()`). 171 ORDER_BY_LIMIT_FEED = 3; 172 // The stream is a union of multiple changefeed types that can't be 173 // collapsed to a single type 174 // (e.g. `r.table('test').changes().union(r.table('test').get(0).changes())`). 175 UNIONED_FEED = 4; 176 // The stream is a changefeed stream and includes notes on what state 177 // the changefeed stream is in (e.g. objects of the form `{state: 178 // 'initializing'}`). 179 INCLUDES_STATES = 5; 180 } 181 repeated ResponseNote notes = 6; 182 183 optional int64 token = 2; // Indicates what [Query] this response corresponds to. 184 185 // [response] contains 1 RQL datum if [type] is [SUCCESS_ATOM] or 186 // [SERVER_INFO]. [response] contains many RQL data if [type] is 187 // [SUCCESS_SEQUENCE] or [SUCCESS_PARTIAL]. [response] contains 1 188 // error message (of type [R_STR]) in all other cases. 189 repeated Datum response = 3; 190 191 // If [type] is [CLIENT_ERROR], [TYPE_ERROR], or [RUNTIME_ERROR], then a 192 // backtrace will be provided. The backtrace says where in the query the 193 // error occurred. Ideally this information will be presented to the user as 194 // a pretty-printed version of their query with the erroneous section 195 // underlined. A backtrace is a series of 0 or more [Frame]s, each of which 196 // specifies either the index of a positional argument or the name of an 197 // optional argument. (Those words will make more sense if you look at the 198 // [Term] message below.) 199 optional Backtrace backtrace = 4; // Contains n [Frame]s when you get back an error. 200 201 // If the [global_optargs] in the [Query] that this [Response] is a 202 // response to contains a key "profile" which maps to a static value of 203 // true then [profile] will contain a [Datum] which provides profiling 204 // information about the execution of the query. This field should be 205 // returned to the user along with the result that would normally be 206 // returned (a datum or a cursor). In official drivers this is accomplished 207 // by putting them inside of an object with "value" mapping to the return 208 // value and "profile" mapping to the profile object. 209 optional Datum profile = 5; 210 } 211 212 // A [Datum] is a chunk of data that can be serialized to disk or returned to 213 // the user in a Response. Currently we only support JSON types, but we may 214 // support other types in the future (e.g., a date type or an integer type). 215 message Datum { 216 enum DatumType { 217 R_NULL = 1; 218 R_BOOL = 2; 219 R_NUM = 3; // a double 220 R_STR = 4; 221 R_ARRAY = 5; 222 R_OBJECT = 6; 223 // This [DatumType] will only be used if [accepts_r_json] is 224 // set to [true] in [Query]. [r_str] will be filled with a 225 // JSON encoding of the [Datum]. 226 R_JSON = 7; // uses r_str 227 } 228 optional DatumType type = 1; 229 optional bool r_bool = 2; 230 optional double r_num = 3; 231 optional string r_str = 4; 232 233 repeated Datum r_array = 5; 234 message AssocPair { 235 optional string key = 1; 236 optional Datum val = 2; 237 } 238 repeated AssocPair r_object = 6; 239 } 240 241 // A [Term] is either a piece of data (see **Datum** above), or an operator and 242 // its operands. If you have a [Datum], it's stored in the member [datum]. If 243 // you have an operator, its positional arguments are stored in [args] and its 244 // optional arguments are stored in [optargs]. 245 // 246 // A note about type signatures: 247 // We use the following notation to denote types: 248 // arg1_type, arg2_type, argrest_type... -> result_type 249 // So, for example, if we have a function `avg` that takes any number of 250 // arguments and averages them, we might write: 251 // NUMBER... -> NUMBER 252 // Or if we had a function that took one number modulo another: 253 // NUMBER, NUMBER -> NUMBER 254 // Or a function that takes a table and a primary key of any Datum type, then 255 // retrieves the entry with that primary key: 256 // Table, DATUM -> OBJECT 257 // Some arguments must be provided as literal values (and not the results of sub 258 // terms). These are marked with a `!`. 259 // Optional arguments are specified within curly braces as argname `:` value 260 // type (e.x `{noreply:BOOL}`) 261 // Many RQL operations are polymorphic. For these, alterantive type signatures 262 // are separated by `|`. 263 // 264 // The RQL type hierarchy is as follows: 265 // Top 266 // DATUM 267 // NULL 268 // BOOL 269 // NUMBER 270 // STRING 271 // OBJECT 272 // SingleSelection 273 // ARRAY 274 // Sequence 275 // ARRAY 276 // Stream 277 // StreamSelection 278 // Table 279 // Database 280 // Function 281 // Ordering - used only by ORDER_BY 282 // Pathspec -- an object, string, or array that specifies a path 283 // Error 284 message Term { 285 enum TermType { 286 // A RQL datum, stored in `datum` below. 287 DATUM = 1; 288 289 MAKE_ARRAY = 2; // DATUM... -> ARRAY 290 // Evaluate the terms in [optargs] and make an object 291 MAKE_OBJ = 3; // {...} -> OBJECT 292 293 // * Compound types 294 295 // Takes an integer representing a variable and returns the value stored 296 // in that variable. It's the responsibility of the client to translate 297 // from their local representation of a variable to a unique _non-negative_ 298 // integer for that variable. (We do it this way instead of letting 299 // clients provide variable names as strings to discourage 300 // variable-capturing client libraries, and because it's more efficient 301 // on the wire.) 302 VAR = 10; // !NUMBER -> DATUM 303 // Takes some javascript code and executes it. 304 JAVASCRIPT = 11; // STRING {timeout: !NUMBER} -> DATUM | 305 // STRING {timeout: !NUMBER} -> Function(*) 306 UUID = 169; // () -> DATUM 307 308 // Takes an HTTP URL and gets it. If the get succeeds and 309 // returns valid JSON, it is converted into a DATUM 310 HTTP = 153; // STRING {data: OBJECT | STRING, 311 // timeout: !NUMBER, 312 // method: STRING, 313 // params: OBJECT, 314 // header: OBJECT | ARRAY, 315 // attempts: NUMBER, 316 // redirects: NUMBER, 317 // verify: BOOL, 318 // page: FUNC | STRING, 319 // page_limit: NUMBER, 320 // auth: OBJECT, 321 // result_format: STRING, 322 // } -> STRING | STREAM 323 324 // Takes a string and throws an error with that message. 325 // Inside of a `default` block, you can omit the first 326 // argument to rethrow whatever error you catch (this is most 327 // useful as an argument to the `default` filter optarg). 328 ERROR = 12; // STRING -> Error | -> Error 329 // Takes nothing and returns a reference to the implicit variable. 330 IMPLICIT_VAR = 13; // -> DATUM 331 332 // * Data Operators 333 // Returns a reference to a database. 334 DB = 14; // STRING -> Database 335 // Returns a reference to a table. 336 TABLE = 15; // Database, STRING, {read_mode:STRING, identifier_format:STRING} -> Table 337 // STRING, {read_mode:STRING, identifier_format:STRING} -> Table 338 // Gets a single element from a table by its primary or a secondary key. 339 GET = 16; // Table, STRING -> SingleSelection | Table, NUMBER -> SingleSelection | 340 // Table, STRING -> NULL | Table, NUMBER -> NULL | 341 GET_ALL = 78; // Table, DATUM..., {index:!STRING} => ARRAY 342 343 // Simple DATUM Ops 344 EQ = 17; // DATUM... -> BOOL 345 NE = 18; // DATUM... -> BOOL 346 LT = 19; // DATUM... -> BOOL 347 LE = 20; // DATUM... -> BOOL 348 GT = 21; // DATUM... -> BOOL 349 GE = 22; // DATUM... -> BOOL 350 NOT = 23; // BOOL -> BOOL 351 // ADD can either add two numbers or concatenate two arrays. 352 ADD = 24; // NUMBER... -> NUMBER | STRING... -> STRING 353 SUB = 25; // NUMBER... -> NUMBER 354 MUL = 26; // NUMBER... -> NUMBER 355 DIV = 27; // NUMBER... -> NUMBER 356 MOD = 28; // NUMBER, NUMBER -> NUMBER 357 358 FLOOR = 183; // NUMBER -> NUMBER 359 CEIL = 184; // NUMBER -> NUMBER 360 ROUND = 185; // NUMBER -> NUMBER 361 362 // DATUM Array Ops 363 // Append a single element to the end of an array (like `snoc`). 364 APPEND = 29; // ARRAY, DATUM -> ARRAY 365 // Prepend a single element to the end of an array (like `cons`). 366 PREPEND = 80; // ARRAY, DATUM -> ARRAY 367 //Remove the elements of one array from another array. 368 DIFFERENCE = 95; // ARRAY, ARRAY -> ARRAY 369 370 // DATUM Set Ops 371 // Set ops work on arrays. They don't use actual sets and thus have 372 // performance characteristics you would expect from arrays rather than 373 // from sets. All set operations have the post condition that they 374 // array they return contains no duplicate values. 375 SET_INSERT = 88; // ARRAY, DATUM -> ARRAY 376 SET_INTERSECTION = 89; // ARRAY, ARRAY -> ARRAY 377 SET_UNION = 90; // ARRAY, ARRAY -> ARRAY 378 SET_DIFFERENCE = 91; // ARRAY, ARRAY -> ARRAY 379 380 SLICE = 30; // Sequence, NUMBER, NUMBER -> Sequence 381 SKIP = 70; // Sequence, NUMBER -> Sequence 382 LIMIT = 71; // Sequence, NUMBER -> Sequence 383 OFFSETS_OF = 87; // Sequence, DATUM -> Sequence | Sequence, Function(1) -> Sequence 384 CONTAINS = 93; // Sequence, (DATUM | Function(1))... -> BOOL 385 386 // Stream/Object Ops 387 // Get a particular field from an object, or map that over a 388 // sequence. 389 GET_FIELD = 31; // OBJECT, STRING -> DATUM 390 // | Sequence, STRING -> Sequence 391 // Return an array containing the keys of the object. 392 KEYS = 94; // OBJECT -> ARRAY 393 // Return an array containing the values of the object. 394 VALUES = 186; // OBJECT -> ARRAY 395 // Creates an object 396 OBJECT = 143; // STRING, DATUM, ... -> OBJECT 397 // Check whether an object contains all the specified fields, 398 // or filters a sequence so that all objects inside of it 399 // contain all the specified fields. 400 HAS_FIELDS = 32; // OBJECT, Pathspec... -> BOOL 401 // x.with_fields(...) <=> x.has_fields(...).pluck(...) 402 WITH_FIELDS = 96; // Sequence, Pathspec... -> Sequence 403 // Get a subset of an object by selecting some attributes to preserve, 404 // or map that over a sequence. (Both pick and pluck, polymorphic.) 405 PLUCK = 33; // Sequence, Pathspec... -> Sequence | OBJECT, Pathspec... -> OBJECT 406 // Get a subset of an object by selecting some attributes to discard, or 407 // map that over a sequence. (Both unpick and without, polymorphic.) 408 WITHOUT = 34; // Sequence, Pathspec... -> Sequence | OBJECT, Pathspec... -> OBJECT 409 // Merge objects (right-preferential) 410 MERGE = 35; // OBJECT... -> OBJECT | Sequence -> Sequence 411 412 // Sequence Ops 413 // Get all elements of a sequence between two values. 414 // Half-open by default, but the openness of either side can be 415 // changed by passing 'closed' or 'open for `right_bound` or 416 // `left_bound`. 417 BETWEEN_DEPRECATED = 36; // Deprecated version of between, which allows `null` to specify unboundedness 418 // With the newer version, clients should use `r.minval` and `r.maxval` for unboundedness 419 BETWEEN = 182; // StreamSelection, DATUM, DATUM, {index:!STRING, right_bound:STRING, left_bound:STRING} -> StreamSelection 420 REDUCE = 37; // Sequence, Function(2) -> DATUM 421 MAP = 38; // Sequence, Function(1) -> Sequence 422 // The arity of the function should be 423 // Sequence..., Function(sizeof...(Sequence)) -> Sequence 424 425 FOLD = 187; // Sequence, Datum, Function(2), {Function(3), Function(1) 426 427 // Filter a sequence with either a function or a shortcut 428 // object (see API docs for details). The body of FILTER is 429 // wrapped in an implicit `.default(false)`, and you can 430 // change the default value by specifying the `default` 431 // optarg. If you make the default `r.error`, all errors 432 // caught by `default` will be rethrown as if the `default` 433 // did not exist. 434 FILTER = 39; // Sequence, Function(1), {default:DATUM} -> Sequence | 435 // Sequence, OBJECT, {default:DATUM} -> Sequence 436 // Map a function over a sequence and then concatenate the results together. 437 CONCAT_MAP = 40; // Sequence, Function(1) -> Sequence 438 // Order a sequence based on one or more attributes. 439 ORDER_BY = 41; // Sequence, (!STRING | Ordering)..., {index: (!STRING | Ordering)} -> Sequence 440 // Get all distinct elements of a sequence (like `uniq`). 441 DISTINCT = 42; // Sequence -> Sequence 442 // Count the number of elements in a sequence, or only the elements that match 443 // a given filter. 444 COUNT = 43; // Sequence -> NUMBER | Sequence, DATUM -> NUMBER | Sequence, Function(1) -> NUMBER 445 IS_EMPTY = 86; // Sequence -> BOOL 446 // Take the union of multiple sequences (preserves duplicate elements! (use distinct)). 447 UNION = 44; // Sequence... -> Sequence 448 // Get the Nth element of a sequence. 449 NTH = 45; // Sequence, NUMBER -> DATUM 450 // do NTH or GET_FIELD depending on target object 451 BRACKET = 170; // Sequence | OBJECT, NUMBER | STRING -> DATUM 452 // OBSOLETE_GROUPED_MAPREDUCE = 46; 453 // OBSOLETE_GROUPBY = 47; 454 455 INNER_JOIN = 48; // Sequence, Sequence, Function(2) -> Sequence 456 OUTER_JOIN = 49; // Sequence, Sequence, Function(2) -> Sequence 457 // An inner-join that does an equality comparison on two attributes. 458 EQ_JOIN = 50; // Sequence, !STRING, Sequence, {index:!STRING} -> Sequence 459 ZIP = 72; // Sequence -> Sequence 460 RANGE = 173; // -> Sequence [0, +inf) 461 // NUMBER -> Sequence [0, a) 462 // NUMBER, NUMBER -> Sequence [a, b) 463 464 // Array Ops 465 // Insert an element in to an array at a given index. 466 INSERT_AT = 82; // ARRAY, NUMBER, DATUM -> ARRAY 467 // Remove an element at a given index from an array. 468 DELETE_AT = 83; // ARRAY, NUMBER -> ARRAY | 469 // ARRAY, NUMBER, NUMBER -> ARRAY 470 // Change the element at a given index of an array. 471 CHANGE_AT = 84; // ARRAY, NUMBER, DATUM -> ARRAY 472 // Splice one array in to another array. 473 SPLICE_AT = 85; // ARRAY, NUMBER, ARRAY -> ARRAY 474 475 // * Type Ops 476 // Coerces a datum to a named type (e.g. "bool"). 477 // If you previously used `stream_to_array`, you should use this instead 478 // with the type "array". 479 COERCE_TO = 51; // Top, STRING -> Top 480 // Returns the named type of a datum (e.g. TYPE_OF(true) = "BOOL") 481 TYPE_OF = 52; // Top -> STRING 482 483 // * Write Ops (the OBJECTs contain data about number of errors etc.) 484 // Updates all the rows in a selection. Calls its Function with the row 485 // to be updated, and then merges the result of that call. 486 UPDATE = 53; // StreamSelection, Function(1), {non_atomic:BOOL, durability:STRING, return_changes:BOOL} -> OBJECT | 487 // SingleSelection, Function(1), {non_atomic:BOOL, durability:STRING, return_changes:BOOL} -> OBJECT | 488 // StreamSelection, OBJECT, {non_atomic:BOOL, durability:STRING, return_changes:BOOL} -> OBJECT | 489 // SingleSelection, OBJECT, {non_atomic:BOOL, durability:STRING, return_changes:BOOL} -> OBJECT 490 // Deletes all the rows in a selection. 491 DELETE = 54; // StreamSelection, {durability:STRING, return_changes:BOOL} -> OBJECT | SingleSelection -> OBJECT 492 // Replaces all the rows in a selection. Calls its Function with the row 493 // to be replaced, and then discards it and stores the result of that 494 // call. 495 REPLACE = 55; // StreamSelection, Function(1), {non_atomic:BOOL, durability:STRING, return_changes:BOOL} -> OBJECT | SingleSelection, Function(1), {non_atomic:BOOL, durability:STRING, return_changes:BOOL} -> OBJECT 496 // Inserts into a table. If `conflict` is replace, overwrites 497 // entries with the same primary key. If `conflict` is 498 // update, does an update on the entry. If `conflict` is 499 // error, or is omitted, conflicts will trigger an error. 500 INSERT = 56; // Table, OBJECT, {conflict:STRING, durability:STRING, return_changes:BOOL} -> OBJECT | Table, Sequence, {conflict:STRING, durability:STRING, return_changes:BOOL} -> OBJECT 501 502 // * Administrative OPs 503 // Creates a database with a particular name. 504 DB_CREATE = 57; // STRING -> OBJECT 505 // Drops a database with a particular name. 506 DB_DROP = 58; // STRING -> OBJECT 507 // Lists all the databases by name. (Takes no arguments) 508 DB_LIST = 59; // -> ARRAY 509 // Creates a table with a particular name in a particular 510 // database. (You may omit the first argument to use the 511 // default database.) 512 TABLE_CREATE = 60; // Database, STRING, {primary_key:STRING, shards:NUMBER, replicas:NUMBER, primary_replica_tag:STRING} -> OBJECT 513 // Database, STRING, {primary_key:STRING, shards:NUMBER, replicas:OBJECT, primary_replica_tag:STRING} -> OBJECT 514 // STRING, {primary_key:STRING, shards:NUMBER, replicas:NUMBER, primary_replica_tag:STRING} -> OBJECT 515 // STRING, {primary_key:STRING, shards:NUMBER, replicas:OBJECT, primary_replica_tag:STRING} -> OBJECT 516 // Drops a table with a particular name from a particular 517 // database. (You may omit the first argument to use the 518 // default database.) 519 TABLE_DROP = 61; // Database, STRING -> OBJECT 520 // STRING -> OBJECT 521 // Lists all the tables in a particular database. (You may 522 // omit the first argument to use the default database.) 523 TABLE_LIST = 62; // Database -> ARRAY 524 // -> ARRAY 525 // Returns the row in the `rethinkdb.table_config` or `rethinkdb.db_config` table 526 // that corresponds to the given database or table. 527 CONFIG = 174; // Database -> SingleSelection 528 // Table -> SingleSelection 529 // Returns the row in the `rethinkdb.table_status` table that corresponds to the 530 // given table. 531 STATUS = 175; // Table -> SingleSelection 532 // Called on a table, waits for that table to be ready for read/write operations. 533 // Called on a database, waits for all of the tables in the database to be ready. 534 // Returns the corresponding row or rows from the `rethinkdb.table_status` table. 535 WAIT = 177; // Table -> OBJECT 536 // Database -> OBJECT 537 // Generates a new config for the given table, or all tables in the given database 538 // The `shards` and `replicas` arguments are required. If `emergency_repair` is 539 // specified, it will enter a completely different mode of repairing a table 540 // which has lost half or more of its replicas. 541 RECONFIGURE = 176; // Database|Table, {shards:NUMBER, replicas:NUMBER [, 542 // dry_run:BOOLEAN] 543 // } -> OBJECT 544 // Database|Table, {shards:NUMBER, replicas:OBJECT [, 545 // primary_replica_tag:STRING, 546 // nonvoting_replica_tags:ARRAY, 547 // dry_run:BOOLEAN] 548 // } -> OBJECT 549 // Table, {emergency_repair:STRING, dry_run:BOOLEAN} -> OBJECT 550 // Balances the table's shards but leaves everything else the same. Can also be 551 // applied to an entire database at once. 552 REBALANCE = 179; // Table -> OBJECT 553 // Database -> OBJECT 554 555 // Ensures that previously issued soft-durability writes are complete and 556 // written to disk. 557 SYNC = 138; // Table -> OBJECT 558 559 // Set global, database, or table-specific permissions 560 GRANT = 188; // -> OBJECT 561 // Database -> OBJECT 562 // Table -> OBJECT 563 564 // * Secondary indexes OPs 565 // Creates a new secondary index with a particular name and definition. 566 INDEX_CREATE = 75; // Table, STRING, Function(1), {multi:BOOL} -> OBJECT 567 // Drops a secondary index with a particular name from the specified table. 568 INDEX_DROP = 76; // Table, STRING -> OBJECT 569 // Lists all secondary indexes on a particular table. 570 INDEX_LIST = 77; // Table -> ARRAY 571 // Gets information about whether or not a set of indexes are ready to 572 // be accessed. Returns a list of objects that look like this: 573 // {index:STRING, ready:BOOL[, progress:NUMBER]} 574 INDEX_STATUS = 139; // Table, STRING... -> ARRAY 575 // Blocks until a set of indexes are ready to be accessed. Returns the 576 // same values INDEX_STATUS. 577 INDEX_WAIT = 140; // Table, STRING... -> ARRAY 578 // Renames the given index to a new name 579 INDEX_RENAME = 156; // Table, STRING, STRING, {overwrite:BOOL} -> OBJECT 580 581 // * Write hook Function OPs 582 // Creates a new write hook function with a particular definition 583 SET_WRITE_HOOK = 189; // Table, Function(2) 584 // Gets an existing write hook function on a table 585 GET_WRITE_HOOK = 190; // Table 586 587 588 589 // * Control Operators 590 // Calls a function on data 591 FUNCALL = 64; // Function(*), DATUM... -> DATUM 592 // Executes its first argument, and returns its second argument if it 593 // got [true] or its third argument if it got [false] (like an `if` 594 // statement). 595 BRANCH = 65; // BOOL, Top, Top -> Top 596 // Returns true if any of its arguments returns true (short-circuits). 597 OR = 66; // BOOL... -> BOOL 598 // Returns true if all of its arguments return true (short-circuits). 599 AND = 67; // BOOL... -> BOOL 600 // Calls its Function with each entry in the sequence 601 // and executes the array of terms that Function returns. 602 FOR_EACH = 68; // Sequence, Function(1) -> OBJECT 603 604 //////////////////////////////////////////////////////////////////////////////// 605 ////////// Special Terms 606 //////////////////////////////////////////////////////////////////////////////// 607 608 // An anonymous function. Takes an array of numbers representing 609 // variables (see [VAR] above), and a [Term] to execute with those in 610 // scope. Returns a function that may be passed an array of arguments, 611 // then executes the Term with those bound to the variable names. The 612 // user will never construct this directly. We use it internally for 613 // things like `map` which take a function. The "arity" of a [Function] is 614 // the number of arguments it takes. 615 // For example, here's what `_X_.map{|x| x+2}` turns into: 616 // Term { 617 // type = MAP; 618 // args = [_X_, 619 // Term { 620 // type = Function; 621 // args = [Term { 622 // type = DATUM; 623 // datum = Datum { 624 // type = R_ARRAY; 625 // r_array = [Datum { type = R_NUM; r_num = 1; }]; 626 // }; 627 // }, 628 // Term { 629 // type = ADD; 630 // args = [Term { 631 // type = VAR; 632 // args = [Term { 633 // type = DATUM; 634 // datum = Datum { type = R_NUM; 635 // r_num = 1}; 636 // }]; 637 // }, 638 // Term { 639 // type = DATUM; 640 // datum = Datum { type = R_NUM; r_num = 2; }; 641 // }]; 642 // }]; 643 // }]; 644 FUNC = 69; // ARRAY, Top -> ARRAY -> Top 645 646 // Indicates to ORDER_BY that this attribute is to be sorted in ascending order. 647 ASC = 73; // !STRING -> Ordering 648 // Indicates to ORDER_BY that this attribute is to be sorted in descending order. 649 DESC = 74; // !STRING -> Ordering 650 651 // Gets info about anything. INFO is most commonly called on tables. 652 INFO = 79; // Top -> OBJECT 653 654 // `a.match(b)` returns a match object if the string `a` 655 // matches the regular expression `b`. 656 MATCH = 97; // STRING, STRING -> DATUM 657 658 // Change the case of a string. 659 UPCASE = 141; // STRING -> STRING 660 DOWNCASE = 142; // STRING -> STRING 661 662 // Select a number of elements from sequence with uniform distribution. 663 SAMPLE = 81; // Sequence, NUMBER -> Sequence 664 665 // Evaluates its first argument. If that argument returns 666 // NULL or throws an error related to the absence of an 667 // expected value (for instance, accessing a non-existent 668 // field or adding NULL to an integer), DEFAULT will either 669 // return its second argument or execute it if it's a 670 // function. If the second argument is a function, it will be 671 // passed either the text of the error or NULL as its 672 // argument. 673 DEFAULT = 92; // Top, Top -> Top 674 675 // Parses its first argument as a json string and returns it as a 676 // datum. 677 JSON = 98; // STRING -> DATUM 678 679 // Parses its first arguments as an ISO 8601 time and returns it as a 680 // datum. 681 ISO8601 = 99; // STRING -> PSEUDOTYPE(TIME) 682 // Prints a time as an ISO 8601 time. 683 TO_ISO8601 = 100; // PSEUDOTYPE(TIME) -> STRING 684 685 // Returns a time given seconds since epoch in UTC. 686 EPOCH_TIME = 101; // NUMBER -> PSEUDOTYPE(TIME) 687 // Returns seconds since epoch in UTC given a time. 688 TO_EPOCH_TIME = 102; // PSEUDOTYPE(TIME) -> NUMBER 689 690 // The time the query was received by the server. 691 NOW = 103; // -> PSEUDOTYPE(TIME) 692 // Puts a time into an ISO 8601 timezone. 693 IN_TIMEZONE = 104; // PSEUDOTYPE(TIME), STRING -> PSEUDOTYPE(TIME) 694 // a.during(b, c) returns whether a is in the range [b, c) 695 DURING = 105; // PSEUDOTYPE(TIME), PSEUDOTYPE(TIME), PSEUDOTYPE(TIME) -> BOOL 696 // Retrieves the date portion of a time. 697 DATE = 106; // PSEUDOTYPE(TIME) -> PSEUDOTYPE(TIME) 698 // x.time_of_day == x.date - x 699 TIME_OF_DAY = 126; // PSEUDOTYPE(TIME) -> NUMBER 700 // Returns the timezone of a time. 701 TIMEZONE = 127; // PSEUDOTYPE(TIME) -> STRING 702 703 // These access the various components of a time. 704 YEAR = 128; // PSEUDOTYPE(TIME) -> NUMBER 705 MONTH = 129; // PSEUDOTYPE(TIME) -> NUMBER 706 DAY = 130; // PSEUDOTYPE(TIME) -> NUMBER 707 DAY_OF_WEEK = 131; // PSEUDOTYPE(TIME) -> NUMBER 708 DAY_OF_YEAR = 132; // PSEUDOTYPE(TIME) -> NUMBER 709 HOURS = 133; // PSEUDOTYPE(TIME) -> NUMBER 710 MINUTES = 134; // PSEUDOTYPE(TIME) -> NUMBER 711 SECONDS = 135; // PSEUDOTYPE(TIME) -> NUMBER 712 713 // Construct a time from a date and optional timezone or a 714 // date+time and optional timezone. 715 TIME = 136; // NUMBER, NUMBER, NUMBER, STRING -> PSEUDOTYPE(TIME) | 716 // NUMBER, NUMBER, NUMBER, NUMBER, NUMBER, NUMBER, STRING -> PSEUDOTYPE(TIME) | 717 718 // Constants for ISO 8601 days of the week. 719 MONDAY = 107; // -> 1 720 TUESDAY = 108; // -> 2 721 WEDNESDAY = 109; // -> 3 722 THURSDAY = 110; // -> 4 723 FRIDAY = 111; // -> 5 724 SATURDAY = 112; // -> 6 725 SUNDAY = 113; // -> 7 726 727 // Constants for ISO 8601 months. 728 JANUARY = 114; // -> 1 729 FEBRUARY = 115; // -> 2 730 MARCH = 116; // -> 3 731 APRIL = 117; // -> 4 732 MAY = 118; // -> 5 733 JUNE = 119; // -> 6 734 JULY = 120; // -> 7 735 AUGUST = 121; // -> 8 736 SEPTEMBER = 122; // -> 9 737 OCTOBER = 123; // -> 10 738 NOVEMBER = 124; // -> 11 739 DECEMBER = 125; // -> 12 740 741 // Indicates to MERGE to replace, or remove in case of an empty literal, the 742 // other object rather than merge it. 743 LITERAL = 137; // -> Merging 744 // JSON -> Merging 745 746 // SEQUENCE, STRING -> GROUPED_SEQUENCE | SEQUENCE, FUNCTION -> GROUPED_SEQUENCE 747 GROUP = 144; 748 SUM = 145; 749 AVG = 146; 750 MIN = 147; 751 MAX = 148; 752 753 // `str.split()` splits on whitespace 754 // `str.split(" ")` splits on spaces only 755 // `str.split(" ", 5)` splits on spaces with at most 5 results 756 // `str.split(nil, 5)` splits on whitespace with at most 5 results 757 SPLIT = 149; // STRING -> ARRAY | STRING, STRING -> ARRAY | STRING, STRING, NUMBER -> ARRAY | STRING, NULL, NUMBER -> ARRAY 758 759 UNGROUP = 150; // GROUPED_DATA -> ARRAY 760 761 // Takes a range of numbers and returns a random number within the range 762 RANDOM = 151; // NUMBER, NUMBER {float:BOOL} -> DATUM 763 764 CHANGES = 152; // TABLE -> STREAM 765 ARGS = 154; // ARRAY -> SPECIAL (used to splice arguments) 766 767 // BINARY is client-only at the moment, it is not supported on the server 768 BINARY = 155; // STRING -> PSEUDOTYPE(BINARY) 769 770 GEOJSON = 157; // OBJECT -> PSEUDOTYPE(GEOMETRY) 771 TO_GEOJSON = 158; // PSEUDOTYPE(GEOMETRY) -> OBJECT 772 POINT = 159; // NUMBER, NUMBER -> PSEUDOTYPE(GEOMETRY) 773 LINE = 160; // (ARRAY | PSEUDOTYPE(GEOMETRY))... -> PSEUDOTYPE(GEOMETRY) 774 POLYGON = 161; // (ARRAY | PSEUDOTYPE(GEOMETRY))... -> PSEUDOTYPE(GEOMETRY) 775 DISTANCE = 162; // PSEUDOTYPE(GEOMETRY), PSEUDOTYPE(GEOMETRY) {geo_system:STRING, unit:STRING} -> NUMBER 776 INTERSECTS = 163; // PSEUDOTYPE(GEOMETRY), PSEUDOTYPE(GEOMETRY) -> BOOL 777 INCLUDES = 164; // PSEUDOTYPE(GEOMETRY), PSEUDOTYPE(GEOMETRY) -> BOOL 778 CIRCLE = 165; // PSEUDOTYPE(GEOMETRY), NUMBER {num_vertices:NUMBER, geo_system:STRING, unit:STRING, fill:BOOL} -> PSEUDOTYPE(GEOMETRY) 779 GET_INTERSECTING = 166; // TABLE, PSEUDOTYPE(GEOMETRY) {index:!STRING} -> StreamSelection 780 FILL = 167; // PSEUDOTYPE(GEOMETRY) -> PSEUDOTYPE(GEOMETRY) 781 GET_NEAREST = 168; // TABLE, PSEUDOTYPE(GEOMETRY) {index:!STRING, max_results:NUM, max_dist:NUM, geo_system:STRING, unit:STRING} -> ARRAY 782 POLYGON_SUB = 171; // PSEUDOTYPE(GEOMETRY), PSEUDOTYPE(GEOMETRY) -> PSEUDOTYPE(GEOMETRY) 783 784 // Returns the datum as a JSON string. 785 // N.B.: we would really prefer this be named TO_JSON and that exists as 786 // an alias in Python and JavaScript drivers; however it conflicts with the 787 // standard `to_json` method defined by Ruby's standard json library. 788 TO_JSON_STRING = 172; // DATUM -> STRING 789 790 // Constants for specifying key ranges 791 MINVAL = 180; 792 MAXVAL = 181; 793 794 // Bitwise operations 795 BIT_AND = 191; 796 BIT_OR = 192; 797 BIT_XOR = 193; 798 BIT_NOT = 194; 799 BIT_SAL = 195; 800 BIT_SAR = 196; 801 } 802 optional TermType type = 1; 803 804 // This is only used when type is DATUM. 805 optional Datum datum = 2; 806 807 repeated Term args = 3; // Holds the positional arguments of the query. 808 message AssocPair { 809 optional string key = 1; 810 optional Term val = 2; 811 } 812 repeated AssocPair optargs = 4; // Holds the optional arguments of the query. 813 // (Note that the order of the optional arguments doesn't matter; think of a 814 // Hash.) 815 } 816 817 //////////////////////////////////////////////////////////////////////////////// 818 // EXAMPLE // 819 //////////////////////////////////////////////////////////////////////////////// 820 // ```ruby 821 // r.table('tbl', {:read_mode => 'outdated'}).insert([{:id => 0}, {:id => 1}]) 822 // ``` 823 // Would turn into: 824 // Term { 825 // type = INSERT; 826 // args = [Term { 827 // type = TABLE; 828 // args = [Term { 829 // type = DATUM; 830 // datum = Datum { type = R_STR; r_str = "tbl"; }; 831 // }]; 832 // optargs = [["read_mode", 833 // Term { 834 // type = DATUM; 835 // datum = Datum { type = R_STR; r_bool = "outdated"; }; 836 // }]]; 837 // }, 838 // Term { 839 // type = MAKE_ARRAY; 840 // args = [Term { 841 // type = DATUM; 842 // datum = Datum { type = R_OBJECT; r_object = [["id", 0]]; }; 843 // }, 844 // Term { 845 // type = DATUM; 846 // datum = Datum { type = R_OBJECT; r_object = [["id", 1]]; }; 847 // }]; 848 // }] 849 // } 850 // And the server would reply: 851 // Response { 852 // type = SUCCESS_ATOM; 853 // token = 1; 854 // response = [Datum { type = R_OBJECT; r_object = [["inserted", 2]]; }]; 855 // } 856 // Or, if there were an error: 857 // Response { 858 // type = RUNTIME_ERROR; 859 // token = 1; 860 // response = [Datum { type = R_STR; r_str = "The table `tbl` doesn't exist!"; }]; 861 // backtrace = [Frame { type = POS; pos = 0; }, Frame { type = POS; pos = 0; }]; 862 // }