ql2.proto 41 KB

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