1 | fauna-shell
|
2 | ===========
|
3 |
|
4 | [![CircleCI](https://circleci.com/gh/fauna/fauna/tree/master.svg?style=shield)](https://circleci.com/gh/fauna/fauna/tree/master)
|
5 | [![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/fauna/fauna?branch=master&svg=true)](https://ci.appveyor.com/project/fauna/fauna/branch/master)
|
6 | [![Codecov](https://codecov.io/gh/fauna/fauna/branch/master/graph/badge.svg)](https://codecov.io/gh/fauna/fauna)
|
7 | [![Downloads/week](https://img.shields.io/npm/dw/fauna.svg)](https://npmjs.org/package/fauna)
|
8 | [![License](https://img.shields.io/npm/l/fauna.svg)](https://github.com/fauna/fauna/blob/master/package.json) -->
|
9 |
|
10 | This tools gives you access to [FaunaDB](http://fauna.com/) directly from your CLI.
|
11 |
|
12 | It also includes a [Shell](#shell) so you can issue queries to FaunaDB without needing to install additional libraries.
|
13 |
|
14 | You can install it via npm like this:
|
15 |
|
16 | ```sh-session
|
17 | $ npm install -g fauna-shell
|
18 | ```
|
19 |
|
20 |
|
21 | * [Usage](#usage)
|
22 | * [Shell](#shell)
|
23 | * [Command Details](#command-details)
|
24 | * [Connecting to different endpoints](#connecting-to-different-endpoints)
|
25 | * [Overriding Connection Parameters](#overriding-connection-parameters)
|
26 | * [List of Commands](#list-of-commands)
|
27 |
|
28 |
|
29 | # Usage
|
30 |
|
31 | The **fauna-shell** allows you to do things like _creating_, _deleting_ and _listings_ databases.
|
32 |
|
33 | First lets configure an endpoint to connect to the FaunaDB cloud. (If you don't have an account, you can create a free account [here](https://fauna.com/sign-up)).
|
34 |
|
35 | Let's run the following command:
|
36 |
|
37 | ```sh-session
|
38 | $ fauna add-endpoint "https://db.fauna.com"
|
39 | Endpoint Key: ****************************************
|
40 | Endpoint Alias [db.fauna.com]: cloud
|
41 | ```
|
42 |
|
43 | When you are prompted for your `Endpoint Key` enter actual key from your [FaunaDB Cloud](https://dashboard.fauna.com/) account.
|
44 |
|
45 | The _Endpoint Alias_ should be a name that helps you remember the purpose of this endpoint, in this case we use `cloud`.
|
46 |
|
47 | Now that we have an endpoint to connect to we can try to create a database to start playing with FaunaDB.
|
48 |
|
49 | This is how you can create a database called `my_app`:
|
50 |
|
51 | ```sh-session
|
52 | $ fauna create-database my_app
|
53 | creating database my_app
|
54 |
|
55 | created database 'my_app'
|
56 |
|
57 | To start a shell with your new database, run:
|
58 |
|
59 | fauna shell 'my_app'
|
60 |
|
61 | Or, to create an application key for your database, run:
|
62 |
|
63 | fauna create-key 'my_app'
|
64 | ```
|
65 |
|
66 | And then listing your databases:
|
67 |
|
68 | ```sh-session
|
69 | $ fauna list-databases
|
70 | listing databases
|
71 | my_app
|
72 | my_second_app
|
73 | my_other_app
|
74 | ```
|
75 |
|
76 | You can also delete a particular database:
|
77 |
|
78 | ```sh-session
|
79 | $ fauna delete-database my_other_app
|
80 | deleting database 'my_other_app'
|
81 | database 'my_other_app' deleted
|
82 | ```
|
83 |
|
84 | You can also `create`, `list`, and `delete` _keys_.
|
85 |
|
86 | This is how you create a key for the database `my_app`:
|
87 |
|
88 | ```sh-session
|
89 | $ fauna create-key my_app
|
90 | creating key for database 'my_app' with role 'admin'
|
91 |
|
92 | created key for database 'my_app' with role 'admin'.
|
93 | secret: ****************************************
|
94 |
|
95 | To access 'my_app' with this key, create a client using
|
96 | the driver library for your language of choice using
|
97 | the above secret.
|
98 | ```
|
99 |
|
100 | This is how to list keys (the results may differ from what you see in your instance of FaunaDB)
|
101 |
|
102 | ```sh-session
|
103 | $ fauna list-keys
|
104 | listing keys
|
105 | Key ID Database Role
|
106 | 203269476002562560 my_app admin
|
107 | 203269731203940864 my_app admin
|
108 | 203269732275585536 my_app admin
|
109 | 203269735610057216 test admin
|
110 | ```
|
111 |
|
112 | And then delete the key with id: `200219702370238976`:
|
113 |
|
114 | ```sh-session
|
115 | fauna delete-key 200219702370238976
|
116 | deleting key 200219702370238976
|
117 | key 200219702370238976 deleted
|
118 | ```
|
119 |
|
120 | See [Commands](#commands) for a list of commands and help on their usage.
|
121 |
|
122 | # Shell
|
123 |
|
124 | The Fauna Shell lets you issue queries directly to your FaunaDB instance without the need for installing additional libraries.
|
125 |
|
126 | Let's create a database and then we'll jump straight into the Shell to start playing with FaunaDB's data model.
|
127 |
|
128 | ```sh-session
|
129 | fauna create-database my_app
|
130 | ```
|
131 |
|
132 | Our next step is to start the shell for a specific database, in this case `my_app`:
|
133 |
|
134 | ```sh-session
|
135 | fauna shell my_app
|
136 | starting shell for database my_app
|
137 | faunadb>
|
138 | ```
|
139 |
|
140 | Once you have the prompt ready, you can start issues queries against your FaunaDB instance. (Note that the results shown here might vary from the ones you see while running the examples).
|
141 |
|
142 | ```javascript
|
143 | faunadb> CreateClass({ name: "posts" })
|
144 | faunadb>
|
145 | {
|
146 | "ref": Class("posts"),
|
147 | "ts": 1530112459345314,
|
148 | "history_days": 30,
|
149 | "name": "posts"
|
150 | }
|
151 | ```
|
152 |
|
153 | Let's create an index for our _posts_.
|
154 |
|
155 | ```javascript
|
156 | faunadb> CreateIndex(
|
157 | {
|
158 | name: "posts_by_title",
|
159 | source: Class("posts"),
|
160 | terms: [{ field: ["data", "title"] }]
|
161 | })
|
162 | faunadb>
|
163 | {
|
164 | "ref": Index("posts_by_title"),
|
165 | "ts": 1530112490241958,
|
166 | "active": false,
|
167 | "partitions": 1,
|
168 | "name": "posts_by_title",
|
169 | "source": Class("posts"),
|
170 | "terms": [
|
171 | {
|
172 | "field": [
|
173 | "data",
|
174 | "title"
|
175 | ]
|
176 | }
|
177 | ]
|
178 | }
|
179 | ```
|
180 |
|
181 | Let's insert a _post_ item:
|
182 |
|
183 | ```javascript
|
184 | faunadb> Create(
|
185 | Class("posts"),
|
186 | { data: { title: "What I had for breakfast .." } })
|
187 | faunadb>
|
188 | {
|
189 | "ref": Ref(Class("posts"), "203270302096949760"),
|
190 | "ts": 1530112516389297,
|
191 | "data": {
|
192 | "title": "What I had for breakfast .."
|
193 | }
|
194 | }
|
195 | ```
|
196 |
|
197 | We can also insert items in bulk by using the `Map` function.
|
198 |
|
199 | ```javascript
|
200 | faunadb> Map(
|
201 | [
|
202 | "My cat and other marvels",
|
203 | "Pondering during a commute",
|
204 | "Deep meanings in a latte"
|
205 | ],
|
206 | Lambda("post_title",
|
207 | Create(
|
208 | Class("posts"), { data: { title: Var("post_title") } }
|
209 | ))
|
210 | )
|
211 | faunadb>
|
212 | [
|
213 | {
|
214 | "ref": Ref(Class("posts"), "203270317027623424"),
|
215 | "ts": 1530112530627575,
|
216 | "data": {
|
217 | "title": "My cat and other marvels"
|
218 | }
|
219 | },
|
220 | {
|
221 | "ref": Ref(Class("posts"), "203270317027624448"),
|
222 | "ts": 1530112530627575,
|
223 | "data": {
|
224 | "title": "Pondering during a commute"
|
225 | }
|
226 | },
|
227 | {
|
228 | "ref": Ref(Class("posts"), "203270317028672000"),
|
229 | "ts": 1530112530627575,
|
230 | "data": {
|
231 | "title": "Deep meanings in a latte"
|
232 | }
|
233 | }
|
234 | ]
|
235 | ```
|
236 |
|
237 | Now let's try to fetch our post about _latte_. We need to access it by _id_ like this:
|
238 |
|
239 | ```javascript
|
240 | faunadb> Get(Ref(Class("posts"),"203270317028672000"))
|
241 | {
|
242 | "ref": Ref(Class("posts"), "203270317028672000"),
|
243 | "ts": 1530112530627575,
|
244 | "data": {
|
245 | "title": "Deep meanings in a latte"
|
246 | }
|
247 | }
|
248 | ```
|
249 |
|
250 | Now let's update our post about our cat, by adding some tags:
|
251 |
|
252 | ```javascript
|
253 | faunadb> Update(
|
254 | Ref(Class("posts"), "203270317027623424"),
|
255 | { data: { tags: ["pet", "cute"] } })
|
256 | faunadb>
|
257 | {
|
258 | "ref": Ref(Class("posts"), "203270317027623424"),
|
259 | "ts": 1530112657679644,
|
260 | "data": {
|
261 | "title": "My cat and other marvels",
|
262 | "tags": [
|
263 | "pet",
|
264 | "cute"
|
265 | ]
|
266 | }
|
267 | }
|
268 | ```
|
269 |
|
270 | And now let's try to change the content of that post:
|
271 |
|
272 | ```javascript
|
273 | faunadb> Replace(
|
274 | Ref(Class("posts"), "203270317027623424"),
|
275 | { data: { title: "My dog and other marvels" } })
|
276 | {
|
277 | "ref": Ref(Class("posts"), "203270317027623424"),
|
278 | "ts": 1530112733994661,
|
279 | "data": {
|
280 | "title": "My dog and other marvels"
|
281 | }
|
282 | }
|
283 | faunadb>
|
284 |
|
285 | ```
|
286 |
|
287 | Now let's try to delete our post about _latte_:
|
288 |
|
289 | ```javascript
|
290 | faunadb> Delete(Ref(Class("posts"), "203270317028672000"))
|
291 | faunadb>
|
292 | {
|
293 | "ref": Ref(Class("posts"), "203270317028672000"),
|
294 | "ts": 1530112530627575,
|
295 | "data": {
|
296 | "title": "Deep meanings in a latte"
|
297 | }
|
298 | }
|
299 | ```
|
300 |
|
301 | If we try to fetch it, we will receive an error:
|
302 |
|
303 | ```javascript
|
304 | faunadb> Get(Ref(Class("posts"), "203270317028672000"))
|
305 | faunadb>
|
306 | Error: instance not found
|
307 | ```
|
308 |
|
309 | Finally you can exit the _shell_ by pressing `ctrl+d`.
|
310 |
|
311 | # Command Details
|
312 |
|
313 | ```sh-session
|
314 | $ fauna COMMAND
|
315 | running command...
|
316 | $ fauna (-v|--version|version)
|
317 | fauna/0.0.1 darwin-x64 node-v8.11.1
|
318 | $ fauna --help [COMMAND]
|
319 | USAGE
|
320 | $ fauna COMMAND
|
321 | ...
|
322 | ```
|
323 |
|
324 | # Connecting to different endpoints
|
325 |
|
326 | We can add endpoints by calling the following command `add-endpoint`. We will be prompted to enter the authentication key and an alias for the endpoint.
|
327 |
|
328 | ```sh-session
|
329 | $ fauna add-endpoint "https://db.fauna.com"
|
330 | Endpoint Key: ****************************************
|
331 | Endpoint Alias [db.fauna.com]: cloud
|
332 | ```
|
333 |
|
334 | If we have defined many endpoints, we could set one of them as the default one with the `default-endpoint` command:
|
335 |
|
336 | ```sh-session
|
337 | $ fauna default-endpoint cloud
|
338 | ```
|
339 |
|
340 | The _default endpoint_ will be used by the shell to connect to FaunaDB.
|
341 |
|
342 | Endpoints can be listed with the `list-endpoints` command like this:
|
343 |
|
344 | ```sh-session
|
345 | $ fauna list-endpoints
|
346 | localhost
|
347 | cloud *
|
348 | cluster-us-east
|
349 | ```
|
350 |
|
351 | Theere we see that the `cloud` endpoint has a `*` next to its name, meaning that it's the current default one.
|
352 |
|
353 | Finally, endpoints will be saved to a `~/.fauna-shell` file like this:
|
354 |
|
355 | ```ini
|
356 | default=cloud
|
357 |
|
358 | [localhost]
|
359 | domain=127.0.0.1
|
360 | port=8443
|
361 | scheme=http
|
362 | secret=the_secret
|
363 |
|
364 | [cloud]
|
365 | domain=db.fauna.com
|
366 | scheme=https
|
367 | secret=FAUNA_SECRET_KEY
|
368 |
|
369 | [cluster-us-east]
|
370 | domain=cluster-us-east.example.com
|
371 | port=443
|
372 | scheme=https
|
373 | secret=OTHER_FAUNA_SECRET
|
374 | ```
|
375 |
|
376 | # Overriding Connection Parameters
|
377 |
|
378 | Most commands support the following options. You can specify them if you want to connect to your local FaunaDB instance.
|
379 |
|
380 | ```
|
381 | OPTIONS
|
382 | --domain=domain [default: db.fauna.com] FaunaDB server domain
|
383 | --port=port [default: 443] Connection port
|
384 | --scheme=https|http [default: https] Connection scheme
|
385 | --secret=secret FaunaDB secret key
|
386 | --timeout=timeout [default: 80] Connection timeout in milliseconds
|
387 | ```
|
388 |
|
389 | They can be used like this:
|
390 |
|
391 | ```sh-session
|
392 | fauna create-database testdb --domain=127.0.0.1 port=8443 --scheme=http --secret=YOUR_FAUNA_SECRET_KEY --timeout=42
|
393 | ```
|
394 |
|
395 | Options provided via the CLI will override the values set in the `.fauna-shell` config file.
|
396 |
|
397 | Any options that are not specified either via the `.fauna-shell` config file or the CLI will be set to the defaults offered by the [faunadb-js client](https://github.com/fauna/faunadb-js).
|
398 |
|
399 |
|
400 | # List of Commands
|
401 |
|
402 | * [`fauna add-endpoint ENDPOINT`](#fauna-add-endpoint-endpoint)
|
403 | * [`fauna create-database DBNAME`](#fauna-create-database-dbname)
|
404 | * [`fauna create-key DBNAME [ROLE]`](#fauna-create-key-dbname-role)
|
405 | * [`fauna default-endpoint ENDPOINT_ALIAS`](#fauna-default-endpoint-endpoint-alias)
|
406 | * [`fauna delete-database DBNAME`](#fauna-delete-database-dbname)
|
407 | * [`fauna delete-key KEYNAME`](#fauna-delete-key-keyname)
|
408 | * [`fauna help [COMMAND]`](#fauna-help-command)
|
409 | * [`fauna list-databases`](#fauna-list-databases)
|
410 | * [`fauna list-endpoints`](#fauna-list-endpoints)
|
411 | * [`fauna list-keys`](#fauna-list-keys)
|
412 | * [`fauna shell DBNAME`](#fauna-shell-dbname)
|
413 |
|
414 | ## `fauna add-endpoint ENDPOINT`
|
415 |
|
416 | Adds a connection endpoint for FaunaDB
|
417 |
|
418 | ```
|
419 | USAGE
|
420 | $ fauna add-endpoint ENDPOINT
|
421 |
|
422 | ARGUMENTS
|
423 | ENDPOINT FaunaDB server endpoint
|
424 |
|
425 | DESCRIPTION
|
426 | Adds a connection endpoint for FaunaDB
|
427 |
|
428 |
|
429 | EXAMPLE
|
430 | $ fauna-shell add-endpoint https://db.fauna.com:443
|
431 | ```
|
432 |
|
433 | _See code: [src/commands/add-endpoint.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/add-endpoint.js)_
|
434 |
|
435 | ## `fauna create-database DBNAME`
|
436 |
|
437 | Creates a database
|
438 |
|
439 | ```
|
440 | USAGE
|
441 | $ fauna create-database DBNAME
|
442 |
|
443 | ARGUMENTS
|
444 | DBNAME database name
|
445 |
|
446 | DESCRIPTION
|
447 | Creates a database
|
448 |
|
449 |
|
450 | EXAMPLE
|
451 | $ fauna-shell create-database dbname
|
452 | ```
|
453 |
|
454 | _See code: [src/commands/create-database.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/create-database.js)_
|
455 |
|
456 | ## `fauna create-key DBNAME [ROLE]`
|
457 |
|
458 | Creates a key for the specified database
|
459 |
|
460 | ```
|
461 | USAGE
|
462 | $ fauna create-key DBNAME [ROLE]
|
463 |
|
464 | ARGUMENTS
|
465 | DBNAME database name
|
466 | ROLE key user role
|
467 |
|
468 | DESCRIPTION
|
469 | Creates a key for the specified database
|
470 |
|
471 |
|
472 | EXAMPLE
|
473 | $ fauna-shell create-key dbname admin
|
474 | ```
|
475 |
|
476 | _See code: [src/commands/create-key.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/create-key.js)_
|
477 |
|
478 | ## `fauna default-endpoint ENDPOINT_ALIAS`
|
479 |
|
480 | Sets an endpoint as the default one
|
481 |
|
482 | ```
|
483 | USAGE
|
484 | $ fauna default-endpoint ENDPOINT_ALIAS
|
485 |
|
486 | ARGUMENTS
|
487 | ENDPOINT_ALIAS FaunaDB server endpoint
|
488 |
|
489 | DESCRIPTION
|
490 | Sets an endpoint as the default one
|
491 |
|
492 |
|
493 | EXAMPLE
|
494 | $ fauna-shell default-endpoint endpoint
|
495 | ```
|
496 |
|
497 | _See code: [src/commands/default-endpoint.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/default-endpoint.js)_
|
498 |
|
499 | ## `fauna delete-database DBNAME`
|
500 |
|
501 | Deletes a database
|
502 |
|
503 | ```
|
504 | USAGE
|
505 | $ fauna delete-database DBNAME
|
506 |
|
507 | ARGUMENTS
|
508 | DBNAME database name
|
509 |
|
510 | DESCRIPTION
|
511 | Deletes a database
|
512 |
|
513 |
|
514 | EXAMPLE
|
515 | $ fauna-shell delete-database dbname
|
516 | ```
|
517 |
|
518 | _See code: [src/commands/delete-database.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/delete-database.js)_
|
519 |
|
520 | ## `fauna delete-key KEYNAME`
|
521 |
|
522 | Deletes a key
|
523 |
|
524 | ```
|
525 | USAGE
|
526 | $ fauna delete-key KEYNAME
|
527 |
|
528 | ARGUMENTS
|
529 | KEYNAME key name
|
530 |
|
531 | DESCRIPTION
|
532 | Deletes a key
|
533 |
|
534 |
|
535 | EXAMPLE
|
536 | $ fauna-shell delete-key 123456789012345678
|
537 | ```
|
538 |
|
539 | _See code: [src/commands/delete-key.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/delete-key.js)_
|
540 |
|
541 | ## `fauna help [COMMAND]`
|
542 |
|
543 | display help for fauna
|
544 |
|
545 | ```
|
546 | USAGE
|
547 | $ fauna help [COMMAND]
|
548 |
|
549 | ARGUMENTS
|
550 | COMMAND command to show help for
|
551 |
|
552 | OPTIONS
|
553 | --all see all commands in CLI
|
554 | ```
|
555 |
|
556 | _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v1.2.11/src/commands/help.ts)_
|
557 |
|
558 | ## `fauna list-databases`
|
559 |
|
560 | Lists top level databases
|
561 |
|
562 | ```
|
563 | USAGE
|
564 | $ fauna list-databases
|
565 |
|
566 | DESCRIPTION
|
567 | Lists top level databases
|
568 |
|
569 |
|
570 | EXAMPLE
|
571 | $ fauna-shell list-databases
|
572 | ```
|
573 |
|
574 | _See code: [src/commands/list-databases.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/list-databases.js)_
|
575 |
|
576 | ## `fauna list-endpoints`
|
577 |
|
578 | Lists FaunaDB connection endpoints
|
579 |
|
580 | ```
|
581 | USAGE
|
582 | $ fauna list-endpoints
|
583 |
|
584 | DESCRIPTION
|
585 | Lists FaunaDB connection endpoints
|
586 |
|
587 |
|
588 | EXAMPLE
|
589 | $ fauna-shell list-endpoints
|
590 | ```
|
591 |
|
592 | _See code: [src/commands/list-endpoints.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/list-endpoints.js)_
|
593 |
|
594 | ## `fauna list-keys`
|
595 |
|
596 | Lists top level keys
|
597 |
|
598 | ```
|
599 | USAGE
|
600 | $ fauna list-keys
|
601 |
|
602 | DESCRIPTION
|
603 | Lists top level keys
|
604 |
|
605 |
|
606 | EXAMPLE
|
607 | $ fauna-shell list-keys
|
608 | ```
|
609 |
|
610 | _See code: [src/commands/list-keys.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/list-keys.js)_
|
611 |
|
612 | ## `fauna shell DBNAME`
|
613 |
|
614 | Starts a FaunaDB shell
|
615 |
|
616 | ```
|
617 | USAGE
|
618 | $ fauna shell DBNAME
|
619 |
|
620 | ARGUMENTS
|
621 | DBNAME database name
|
622 |
|
623 | DESCRIPTION
|
624 | Starts a FaunaDB shell
|
625 |
|
626 |
|
627 | EXAMPLE
|
628 | $ fauna-shell dbname
|
629 | ```
|
630 |
|
631 | _See code: [src/commands/shell.js](https://github.com/fauna/fauna-shell/blob/v0.1.3/src/commands/shell.js)_
|
632 |
|