forked from go-kivik/couchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
32 lines (26 loc) · 907 Bytes
/
client.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
package couchdb
import (
"context"
"github.com/flimzy/kivik"
"github.com/flimzy/kivik/errors"
)
func (c *client) AllDBs(ctx context.Context, _ map[string]interface{}) ([]string, error) {
var allDBs []string
_, err := c.DoJSON(ctx, kivik.MethodGet, "/_all_dbs", nil, &allDBs)
return allDBs, err
}
func (c *client) DBExists(ctx context.Context, dbName string, _ map[string]interface{}) (bool, error) {
_, err := c.DoError(ctx, kivik.MethodHead, dbName, nil)
if errors.StatusCode(err) == kivik.StatusNotFound {
return false, nil
}
return err == nil, err
}
func (c *client) CreateDB(ctx context.Context, dbName string, _ map[string]interface{}) error {
_, err := c.DoError(ctx, kivik.MethodPut, dbName, nil)
return err
}
func (c *client) DestroyDB(ctx context.Context, dbName string, _ map[string]interface{}) error {
_, err := c.DoError(ctx, kivik.MethodDelete, dbName, nil)
return err
}