List ID of records from a collection
This commit is contained in:
parent
4116320640
commit
c32ca9162c
30
scribble.go
30
scribble.go
@ -8,6 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/jcelliott/lumber"
|
"github.com/jcelliott/lumber"
|
||||||
@ -216,6 +217,35 @@ func readAll(files []os.FileInfo, dir string) ([][]byte, error) {
|
|||||||
return records, nil
|
return records, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List ID of records from a collection; this is returned as a slice of strings.
|
||||||
|
func (d *Driver) List(collection string) ([]string, error) {
|
||||||
|
|
||||||
|
// ensure there is a collection to read
|
||||||
|
if collection == "" {
|
||||||
|
return nil, ErrMissingCollection
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
dir := filepath.Join(d.dir, collection)
|
||||||
|
|
||||||
|
// check to see if collection (directory) exists
|
||||||
|
if _, err := stat(dir); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// the IDs of collection
|
||||||
|
var recordsIDs []string
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
name := file.Name()
|
||||||
|
if strings.HasSuffix(name, ".json") {
|
||||||
|
recordsIDs = append(recordsIDs, name[:len(name)-5])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return recordsIDs, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Delete locks that database and then attempts to remove the collection/resource
|
// Delete locks that database and then attempts to remove the collection/resource
|
||||||
// specified by [path]
|
// specified by [path]
|
||||||
func (d *Driver) Delete(collection, resource string) error {
|
func (d *Driver) Delete(collection, resource string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user