github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/datas/workingset.go (about) 1 // Copyright 2021 Dolthub, Inc. 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 datas 16 17 import ( 18 "context" 19 20 "github.com/dolthub/dolt/go/store/nomdl" 21 "github.com/dolthub/dolt/go/store/types" 22 ) 23 24 const ( 25 WorkspaceMetaField = "meta" 26 WorkingSetRefField = "ref" 27 WorkingSetName = "WorkingSet" 28 ) 29 30 type WorkingSetMeta struct { 31 Meta types.Struct 32 } 33 34 var workingSetTemplate = types.MakeStructTemplate(WorkingSetName, []string{WorkingSetRefField}) 35 36 // ref is a Ref<Value>, any Value 37 var valueWorkingSetType = nomdl.MustParseType(`Struct WorkingSet { 38 ref: Ref<Value>, 39 }`) 40 41 // NewWorkingSet creates a new working set object. 42 // A working set is a value that has been persisted but is not necessarily referenced by a Commit. As the name implies, 43 // it's storage for data changes that have not yet been incorporated into the commit graph but need durable storage. 44 // 45 // A working set struct has the following type: 46 // 47 // ``` 48 // struct WorkingSet { 49 // meta: M, 50 // ref: R, 51 // } 52 // ``` 53 // where M is a struct type and R is a ref type. 54 func NewWorkingSet(_ context.Context, valueRef types.Ref) (types.Struct, error) { 55 return workingSetTemplate.NewStruct(valueRef.Format(), []types.Value{valueRef}) 56 } 57 58 func IsWorkingSet(v types.Value) (bool, error) { 59 if s, ok := v.(types.Struct); !ok { 60 return false, nil 61 } else { 62 return types.IsValueSubtypeOf(s.Format(), v, valueWorkingSetType) 63 } 64 }