-
Notifications
You must be signed in to change notification settings - Fork 8
/
db.go
78 lines (60 loc) · 1.8 KB
/
db.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
76
77
78
// Copyright 2014 Gyepi Sam. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package redux
type Record struct {
Key string
Value []byte
}
// DB allows allows for multiple implementations of the redo database.
type DB interface {
IsNull() bool
// Put stores value under key
Put(key string, value []byte) error
// Get returns the value stored under key and a boolean indicating
// whether the returned value was actually found in the database.
Get(key string) ([]byte, bool, error)
// Delete removes the value stored under key.
// If key does not exist, the operation is a noop.
Delete(key string) error
// GetKeys returns a list of keys which have the specified key as a prefix.
GetKeys(prefix string) ([]string, error)
// GetValues returns a list of values whose keys matching the specified key prefix.
GetValues(prefix string) ([][]byte, error)
// GetRecords returns a list of records (keys and data) matchign the specified key prefix.
GetRecords(prefix string) ([]Record, error)
Close() error
}
func WithDB(arg string, f func(DB) error) error {
db, err := FileDbOpen(arg)
if err != nil {
return err
}
defer db.Close()
return f(db)
}
// Delete removes a target's database records
func (f *File) DeleteRecords() error {
// procedure delete-file-record(file)
if err := f.NotifyDependents(IFCREATE); err != nil {
return err
}
if err := f.DeleteAllDependencies(); err != nil {
return err
}
if err := f.DeleteAllPrerequisites(); err != nil {
return err
}
if err := f.DeleteMetadata(); err != nil {
return err
}
if err := f.DeleteMustRebuild(); err != nil {
return err
}
return nil
}
func (f *File) Delete(key string) error {
err := f.db.Delete(key)
f.Debug("@Delete: %s -> %s\n", key, err)
return err
}