github.com/ystia/yorc/v4@v4.3.0/storage/store/store.go (about)

     1  // Copyright 2019 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package store
    16  
    17  import (
    18  	"context"
    19  	"time"
    20  )
    21  
    22  // Store is an abstraction for different key-value store implementations.
    23  // A store must be able to store, retrieve and delete key-value pairs,
    24  // with the key being a string and the value being any Go interface{}.
    25  // inspired by https://github.com/philippgille/gokv
    26  type Store interface {
    27  	// Set stores the given value for the given key.
    28  	// The implementation automatically marshalls the value.
    29  	// The marshalling format depends on the implementation. It can be JSON, gob etc.
    30  	// The key must not be "" and the value must not be nil.
    31  	Set(ctx context.Context, k string, v interface{}) error
    32  	// set a collection of key-values
    33  	// The implementation automatically marshalls the value.
    34  	// The marshalling format depends on the implementation. It can be JSON, gob etc.
    35  	// It's the implementation concern to define storage mode (ie concurrently or serial)
    36  	// ctx is the context provided for eventually cancelling a storage action
    37  	SetCollection(ctx context.Context, keyValues []KeyValueIn) error
    38  	// Get retrieves the value for the given key.
    39  	// The implementation automatically unmarshalls the value.
    40  	// The unmarshalling source depends on the implementation. It can be JSON, gob etc.
    41  	// The automatic unmarshalling requires a pointer to an object of the correct type
    42  	// being passed as parameter.
    43  	// If no value is found it returns (false, nil).
    44  	// The key must not be "" and the pointer must not be nil.
    45  	Get(k string, v interface{}) (bool, error)
    46  	// Exist returns true if the key exists in the store
    47  	// If no value is found it returns (false, nil).
    48  	// The key must not be "" and the pointer must not be nil.
    49  	Exist(k string) (bool, error)
    50  	// Keys returns all the sub-keys of a specified one.
    51  	// The key must not be "".
    52  	// If no sub-key is found, it returns an empty slice.
    53  	// This is not recursive
    54  	Keys(k string) ([]string, error)
    55  	// Delete deletes the stored value for the given key.
    56  	// Deleting a non-existing key-value pair does NOT lead to an error.
    57  	// The key must not be "".
    58  	// If recursive is true, all sub-keys are deleted too.
    59  	Delete(ctx context.Context, k string, recursive bool) error
    60  	// GetLastModifyIndex returns the last index that modified the key k
    61  	GetLastModifyIndex(k string) (uint64, error)
    62  	// List allows to lookup all sub-keys recursively under the defined key k and provided associated values.
    63  	// The key must not be "" and v must not be nil.
    64  	// waitIndex is used to enable a blocking query (waitIndex != 0) which wait until the timeout or a new index > waitIndex
    65  	// if waitIndex is > 0, default timeout is 5 minutes. Max timeout allowed is 10 minutes
    66  	// ctx can be useful to cancel a blocking query
    67  	// The values are retrieved in a KeyValueOut collection.
    68  	// It allows to return values in raw format without decode and in decoded generic format (map[string]interface{}
    69  	// The lastIndex is returned to perform new blocking query.
    70  	List(ctx context.Context, k string, waitIndex uint64, timeout time.Duration) ([]KeyValueOut, uint64, error)
    71  }