forked from 18F/dynamoed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (48 loc) · 1.22 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const AWS = require('aws-sdk')
const Promise = require('bluebird')
AWS.config.setPromisesDependency(Promise)
const serialize = require('./lib/serializers')
const parse = require('./lib/parsers')
module.exports = function dynamoed(connectionParams) {
const client = new AWS.DynamoDB(connectionParams)
return () => { return new Wrapper(client) }
}
class Wrapper {
constructor(client) {
this.client = client
}
createTable(name, attributes) {
let params = serialize.createTable(name, attributes)
return this.client
.createTable(params)
.promise()
.then(() => {
return parse.table(params)
})
}
deleteTable(name) {
return this.client
.deleteTable(serialize.tableName(name))
.promise()
.then((tableParams) => {
return parse.table(tableParams.TableDescription)
})
}
listTables() {
return this.client
.listTables()
.promise()
.then((names) => {
return names.TableNames
})
}
describeTable(name) {
return this.client
.describeTable(serialize.tableName(name))
.promise()
.then((tableParams) => {
return parse.table(tableParams.Table)
})
}
}