-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.go
75 lines (65 loc) · 1.86 KB
/
table.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package harper
type DescribeTableResponse struct {
Record
HashAttribute string `json:"hash_attribute"`
ID string `json:"id"`
Name string `json:"name"`
Residence string `json:"residence"` // TODO Not verified
Schema string `json:"schema"`
Attributes []TableAttribute `json:"attributes"`
RecordCount int `json:"record_count"`
}
type DescribeAllResponse map[string]map[string]DescribeTableResponse
type TableAttribute struct {
Attribute string `json:"attribute"`
}
func (c *Client) CreateTable(schema, table, hashAttribute string) error {
return c.opRequest(operation{
Operation: OP_CREATE_TABLE,
Schema: schema,
Table: table,
HashAttribute: hashAttribute,
}, nil)
}
func (c *Client) DropTable(schema, table, hashAttribute string) error {
return c.opRequest(operation{
Operation: OP_DROP_TABLE,
Schema: schema,
Table: table,
}, nil)
}
func (c *Client) DescribeTable(schema, table string) (*DescribeTableResponse, error) {
resp := DescribeTableResponse{}
err := c.opRequest(operation{
Operation: OP_DESCRIBE_TABLE,
Table: table,
Schema: schema,
}, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (c *Client) DescribeAll() (*DescribeAllResponse, error) {
var result DescribeAllResponse
err := c.opRequest(operation{
Operation: OP_DESCRIBE_ALL,
}, &result)
return &result, err
}
func (c *Client) CreateAttribute(schema, table, attribute string) error {
return c.opRequest(operation{
Operation: OP_CREATE_ATTRIBUTE,
Schema: schema,
Table: table,
Attribute: attribute,
}, nil)
}
func (c *Client) DropAttribute(schema, table, attribute string) error {
return c.opRequest(operation{
Operation: OP_DROP_ATTRIBUTE,
Schema: schema,
Table: table,
Attribute: attribute,
}, nil)
}