create keys package to unify types of index/field/view/shard keys

In developing QueryContext, I found it more expressive to have defined
types for index/field/view/shard keys. Then I wanted to refer to those
names from elsewhere. This package has no dependencies so anything
can import it and we can all agree on these types. Later I want to
migrate everything else to use these names.
This commit is contained in:
Seebs 2023-01-11 11:54:54 -06:00
parent 8b36486c54
commit 672ebb6306
2 changed files with 67 additions and 0 deletions

19
keys/doc.go Normal file
View file

@ -0,0 +1,19 @@
// Copyright 2023 Molecula Corp (DBA FeatureBase). All rights reserved.
package keys
/*
Package keys provides data types and structures that represent the logical
structure of a featurebase database. This package is separate from the
main package so it can be imported by other things which are also imported
by the main package. That may some day become unnecessary.
Featurebase's design sorts data into indexes (comparable to SQL tables),
fields (comparable to SQL columns), views (no real comparison in SQL),
and shards. The data denoted by {index, field, view, shard} is called a
"fragment", and is itself a bitmap of 2^64 logical bits.
Individual backend data storage may not correspond to this layout. The
keys package provides data types representing how high-level Featurebase
models and uses these data types, and does not address the question of how
to make that make sense for a given storage backend.
*/

48
keys/keys.go Normal file
View file

@ -0,0 +1,48 @@
// Copyright 2023 Molecula Corp (DBA FeatureBase). All rights reserved.
package keys
// Index represents the name of a Featurebase index.
type Index string
// Field represents the name of a Featurebase field. It
// is only meaningful within the context of a parent index.
type Field string
// View represents the name of a Featurebase view. It is
// only meaningful within the context of a parent field.
type View string
// Shard represents the numeric shard ID of a shard. A shard
// is specific to an index, but *not* specific to a field or
// view.
type Shard uint64
// Fragment represents the full identifier of a Featurebase
// fragment.
type Fragment struct {
Index
Field
View
Shard
}
// Shards represents an unsorted list of shards.
type Shards map[Shard]struct{}
// ViewContents represents the set of shards a given view contains.
type ViewContents Shards
// helper function to protect us against the day when we need to track
// more than this inside a ViewContents.
func (v ViewContents) Shards() Shards {
return Shards(v)
}
// FieldContents represents the ViewContents for the views in a given field.
type FieldContents map[View]ViewContents
// IndexContents represents the FieldContents for the fields in a given index.
type IndexContents map[Field]FieldContents
// DBContents represents the IndexContents for the indexes in a DB.
type DBContents map[Index]IndexContents