API definition for model store (#249)

Basic API definitions for model store CRUD operations
This commit is contained in:
ashmrtn 2022-06-29 10:35:41 -07:00 committed by GitHub
parent 1c6f0994e4
commit ed3844b714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,67 @@
package kopia
import (
"context"
)
// ID of the manifest in kopia. This is not guaranteed to be stable.
type ID string
type modelType int
//go:generate stringer -type=modelType
const (
UnknownModel = modelType(iota)
BackupOpModel
RestoreOpModel
RestorePointModel
errStoreFlush = "flushing manifest store"
)
type ModelStore struct{}
// Put adds a model of the given type to the persistent model store. Any tags
// given to this function can later be used to help lookup the model. The
// returned ID can be used for subsequent Get, Update, or Delete calls.
func (ms *ModelStore) Put(
ctx context.Context,
t modelType,
tags map[string]string,
m any,
) (ID, error) {
return "", nil
}
// GetIDsForType returns all IDs for models that match the given type and have
// the given tags. Returned IDs can be used in subsequent calls to Get, Update,
// or Delete.
func (ms *ModelStore) GetIDsForType(
ctx context.Context,
t modelType,
tags map[string]string,
) ([]ID, error) {
return nil, nil
}
// Get deserializes the model with the given ID into data.
func (ms *ModelStore) Get(ctx context.Context, id ID, data any) error {
return nil
}
// Update adds the new version of the model to the model store and deletes the
// version of the model with oldID if the old and new IDs do not match. The new
// ID of the model is returned.
func (ms *ModelStore) Update(
ctx context.Context,
t modelType,
oldID ID,
tags map[string]string,
m any,
) (ID, error) {
return "", nil
}
// Delete deletes the model with the given ID from the model store.
func (ms *ModelStore) Delete(ctx context.Context, id ID) error {
return nil
}

View File

@ -0,0 +1,26 @@
// Code generated by "stringer -type=modelType"; DO NOT EDIT.
package kopia
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[UnknownModel-0]
_ = x[BackupOpModel-1]
_ = x[RestoreOpModel-2]
_ = x[RestorePointModel-3]
}
const _modelType_name = "UnknownModelBackupOpModelRestoreOpModelRestorePointModel"
var _modelType_index = [...]uint8{0, 12, 25, 39, 56}
func (i modelType) String() string {
if i < 0 || i >= modelType(len(_modelType_index)-1) {
return "modelType(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _modelType_name[_modelType_index[i]:_modelType_index[i+1]]
}