├── .gitignore ├── README.md ├── bin └── recli.js ├── index.js ├── lib └── misc.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/* 3 | npm-debug.log -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## recli - RethinkDB CLI query tool and REPL 2 | **recli** is a command-line query tool and REPL for RethinkDB, with lots of options to control its output. It supports regular JavaScript syntax and CoffeeScript syntax. 3 | 4 | ### Installation 5 | Install recli using npm: 6 | ``` 7 | sudo npm install -g recli 8 | ``` 9 | This will give you a global `recli` command. If you prefer or need to install it locally, just drop the "sudo" and "-g". In that case, you can invoke it like so: 10 | ``` 11 | node ./node_modules/recli 12 | ``` 13 | or 14 | ``` 15 | ./node_modules/recli/bin/recli.js 16 | ``` 17 | 18 | You can of course create an alias to be able to type "recli", as if you had recli installed globally, just put something like this in your ~/.bash_profile or equivalent: 19 | ``` 20 | alias recli='YOURDIR/node_modules/recli/bin/recli.js' 21 | ``` 22 | 23 | ### Usage 24 | recli can either take a ReQL expression as an argument or be used as a REPL, which lets you type in ReQL expressions in a special shell and see the results immediately. 25 | 26 | Here’s how you would use it from the command line: 27 | ``` 28 | $ recli 'r.table("bikes")' 29 | ... (JSON output) ... 30 | 31 | $ recli 'r.table("bikes").get("123").update({foo: "bar"})' 32 | ... (JSON output) ... 33 | ``` 34 | 35 | If you don’t supply a ReQL expression on the command-line, recli will start a REPL for ReQL queries, like so: 36 | ``` 37 | $ recli 38 | recli> r.table("bikes") 39 | ... (JSON output) ... 40 | recli> r.table("bikes").get("123").update({foo: "bar"}) 41 | ... (JSON output) ... 42 | ``` 43 | Note that results from queries that return a cursor are automatically converted to arrays and printed as JSON documents. 44 | 45 | ### Output 46 | The default output from recli is a color-coded and pretty-formatted RethinkDB query result. It uses node’s util.inspect method, which means that it is actually a string representation of a Javascript object and NOT (by default) strictly valid JSON: 47 | ```js 48 | $ recli 'r.table("heroes")' 49 | [ { hero: 'Magneto', 50 | name: 'Max Eisenhardt', 51 | aka: ['Magnus', 'Erik Lehnsherr', 'Lehnsherr'], 52 | magazine_titles: 53 | [ 'Alpha Flight', 54 | 'Avengers', 55 | 'Avengers West Coast' ], 56 | appearances_count: 42 }, 57 | { hero: 'Professor Xavier', 58 | name: 'Charles Francis Xavier', 59 | magazine_titles: 60 | [ 'Alpha Flight', 61 | 'Avengers', 62 | 'Bishop', 63 | 'Defenders' ], 64 | appearances_count: 72 }, 65 | { hero: 'Storm', 66 | name: 'Ororo Monroe', 67 | magazine_titles: 68 | [ 'Amazing Spider-Man vs. Wolverine', 69 | 'Excalibur', 70 | 'Fantastic Four', 71 | 'Iron Fist' ], 72 | appearances_count: 72 } ] 73 | ``` 74 | Note that colors can be disabled by using the `-n`/`--no-colors` option. 75 | 76 | If you want valid JSON instead, but still nicely indented and readable, use the `-j`/`--json` option: 77 | ``` 78 | $ recli -j 'r.table("heroes")' 79 | [ 80 | { 81 | "hero": "Magneto", 82 | "name": "Max Eisenhardt", 83 | "aka": [ 84 | "Magnus", 85 | "Erik Lehnsherr", 86 | "Lehnsherr" 87 | ], 88 | "magazine_titles": [ 89 | "Alpha Flight", 90 | "Avengers", 91 | "Avengers West Coast" 92 | ], 93 | "appearances_count": 42 94 | }, 95 | { 96 | "hero": "Professor Xavier", 97 | "name": "Charles Francis Xavier", 98 | "magazine_titles": [ 99 | "Alpha Flight", 100 | "Avengers", 101 | "Bishop", 102 | "Defenders" 103 | ], 104 | "appearances_count": 72 105 | }, 106 | { 107 | "hero": "Storm", 108 | "name": "Ororo Monroe", 109 | "magazine_titles": [ 110 | "Amazing Spider-Man vs. Wolverine", 111 | "Excalibur", 112 | "Fantastic Four", 113 | "Iron Fist" 114 | ], 115 | "appearances_count": 72 116 | } 117 | ] 118 | ``` 119 | 120 | If you want raw, unformatted and unindented JSON, use the `-r`/`--raw` option. This isn’t straight-from-the-wire raw, though, it is the JSON.stringify-ed version of the RethinkDB result data (as returned by the JavaScript driver). 121 | 122 | ### CoffeeScript input 123 | If you prefer to use the CoffeeScript syntax, use the `-c`/`--coffee` option: 124 | ``` 125 | $ recli -c 'r.table "bikes"' 126 | ... (JSON output) ... 127 | ``` 128 | 129 | ### Database and connection options 130 | You can specify the database, host and port to connect to with the `-d`/`--database`, `-h`/`--host` and `-p`/`--port` options. 131 | 132 | Use `--help` to get the full usage info: 133 | ``` 134 | $ recli --help 135 | Usage: recli [options] [ReQL expression] 136 | 137 | REPL mode: 138 | If the ReQL expression is omitted, recli will enter REPL mode, 139 | which is a CLI where you can evaluate ReQL expressions. 140 | 141 | REQL EXPRESSION: 142 | A ReQL expression is anything that works in RethinkDB's Data 143 | Explorer, for example 144 | 145 | r.table('bikes').filter({brand: 'Scott'}) 146 | 147 | r.table('bikes').get('123').update({foo: 'bar'}) 148 | 149 | OPTIONAL options: 150 | -c, --coffee Evaluate code as CoffeeScript. 151 | 152 | -d, --database DATABASE Default database to perform queries against. 153 | Can be overridden in the ReQL expression. 154 | The default is 'test'. 155 | 156 | -f, --file FILE Read options from the supplied YAML config 157 | file. The default is to look for a global 158 | /etc/recli.yml and user overrides in ~/.recli.yml 159 | 160 | -h, --host HOST Host to connect to. The default is 'localhost'. 161 | 162 | -j, --json Output valid indented JSON instead of pretty- 163 | printing the result. 164 | 165 | -n, --no-colors Do not use colors when pretty-printing. 166 | 167 | -p, --port PORT TCP port to connect to. The default is 28015. 168 | 169 | -r, --raw Print the raw JSON from RethinkDB, with no 170 | formatting applied. 171 | 172 | -s, --stream Print a line break delimited JSON stream with one 173 | valid JSON object per line. 174 | 175 | -v, --version Print the current version of recli. 176 | ``` 177 | Any options specified on the command line take precedence over defaults and configuration file settings. 178 | 179 | Note that the `--coffee`, `--file`, `--json` and `--raw` options also support the `--no-