This commit is contained in:
SysLabIT 2020-07-04 19:14:07 -06:00 committed by GitHub
commit 69611b4892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"github.com/jcelliott/lumber"
@ -216,6 +217,40 @@ func readAll(files []os.FileInfo, dir string) ([][]byte, error) {
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
//}
files, err := ioutil.ReadDir(dir)
if 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
// specified by [path]
func (d *Driver) Delete(collection, resource string) error {