-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcompatibility.go
More file actions
55 lines (52 loc) · 1.48 KB
/
compatibility.go
File metadata and controls
55 lines (52 loc) · 1.48 KB
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
/**
* compatibility.go provides some wrapping methods for backward complatible
* with v1 of dataset. These are likely to go away at some point.
*/
package dataset
import (
"fmt"
"path"
"strings"
)
// DocPath method provides access to a PTStore's document path. If the
// collection is not a PTStore then an empty path and error is returned
// with an error message.
// NOTE: the path returned is a full path including the JSON document
// stored.
//
// ```
//
// c, err := dataset.Open(cName, "")
// // ... handle error ...
// key := "2488"
// s, err := c.DocPath(key)
// // ... handle error ...
// fmt.Printf("full path to JSON document %q is %q\n", key, s)
//
// ```
func (c *Collection) DocPath(key string) (string, error) {
if c.StoreType == PTSTORE && c.PTStore != nil {
s, err := c.PTStore.DocPath(strings.ToLower(key))
if err != nil {
return "", err
}
return path.Join(s, key+".json"), nil
}
return "", fmt.Errorf("%q does not support document paths", c.StoreType)
}
// CreateObjectsJSON takes a list of keys and creates a default object
// for each key as quickly as possible. This is useful in vary narrow
// situation like quickly creating test data. Use with caution.
//
// NOTE: if object already exist creation is skipped without
// reporting an error.
func (c *Collection) CreateObjectsJSON(keyList []string, src []byte) error {
for _, key := range keyList {
if c.HasKey(key) == false {
if err := c.CreateJSON(key, src); err != nil {
return err
}
}
}
return nil
}