-
Notifications
You must be signed in to change notification settings - Fork 32
/
maker.go
60 lines (52 loc) · 2.13 KB
/
maker.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
// Copyright 2020 Source Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package base
import (
ds "github.com/ipfs/go-datastore"
"github.com/sourcenetwork/defradb/core"
)
var (
ROOT = "/db"
SYSTEM = "/db/system"
DATA = "/db/data"
BLOCK = "/db/block"
HEAD = "/db/head"
)
var (
// Commented because it's deadcode (unused according to linter).
// collectionSeqKey = "collection"
collectionNs = ds.NewKey("/collection")
schemaNs = ds.NewKey("/schema")
)
// MakeIndexPrefix generates a key prefix for the given collection/index descriptions
func MakeIndexPrefixKey(col *CollectionDescription, index *IndexDescription) core.Key {
return core.Key{Key: core.NewKey(DATA).ChildString(col.IDString()).ChildString(index.IDString())}
}
// MakeIndexKey generates a key for the target dockey, using the collection/index description
func MakeIndexKey(col *CollectionDescription, index *IndexDescription, key core.Key) core.Key {
return core.Key{Key: MakeIndexPrefixKey(col, index).Child(key.Key)}
}
// MakeCollectionSystemKey returns a formatted collection key for the system data store.
// it assumes the name of the collection is non-empty.
func MakeCollectionSystemKey(name string) core.Key {
return core.Key{Key: collectionNs.ChildString(name)}
}
// MakeSchemaSystemKey returns a formatted schema key for the system data store.
// it assumes the name of the schema is non-empty.
func MakeSchemaSystemKey(name string) core.Key {
return core.Key{Key: schemaNs.ChildString(name)}
}
// MakeIndexPrefixKeyRaw is the same as MakeIndexPrefixKey but it takes as inputs
// the raw datastore keys, instead of the collection and index objects respectively.
func MakeIndexPrefixKeyRaw(collectionID ds.Key, indexID ds.Key) core.Key {
return core.Key{Key: core.NewKey(DATA).
Child(collectionID).
Child(indexID)}
}