forked from fauna/fauna-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-database.js
45 lines (39 loc) · 1.01 KB
/
delete-database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const FaunaCommand = require('../lib/fauna-command.js')
const { errorOut } = require('../lib/misc.js')
const faunadb = require('faunadb')
const q = faunadb.query
class DeleteDatabaseCommand extends FaunaCommand {
async run() {
const log = this.log
const dbname = this.args.dbname
return this.query(
q.Delete(q.Database(dbname)),
`deleting database '${dbname}'`,
function (_) {
log(`database '${dbname}' deleted`)
},
function (error) {
if (error.message === 'invalid ref') {
errorOut(`Database '${dbname}' not found`, 1)
} else {
errorOut(`Error: ${error.message}`, 1)
}
}
)
}
}
DeleteDatabaseCommand.description = `
Deletes a database
`
DeleteDatabaseCommand.examples = ['$ fauna delete-database dbname']
DeleteDatabaseCommand.flags = {
...FaunaCommand.flags,
}
DeleteDatabaseCommand.args = [
{
name: 'dbname',
required: true,
description: 'database name',
},
]
module.exports = DeleteDatabaseCommand