github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/store/prolly/shim/shim.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 shim
    16  
    17  import (
    18  	"github.com/dolthub/dolt/go/libraries/doltcore/schema"
    19  	"github.com/dolthub/dolt/go/store/prolly"
    20  	"github.com/dolthub/dolt/go/store/prolly/tree"
    21  	"github.com/dolthub/dolt/go/store/types"
    22  )
    23  
    24  func NodeFromValue(v types.Value) (tree.Node, error) {
    25  	return tree.NodeFromBytes(v.(types.SerialMessage))
    26  }
    27  
    28  func ValueFromMap(m prolly.Map) types.Value {
    29  	return tree.ValueFromNode(m.Node())
    30  }
    31  
    32  func ValueFromArtifactMap(m prolly.ArtifactMap) types.Value {
    33  	return tree.ValueFromNode(m.Node())
    34  }
    35  
    36  func MapFromValue(v types.Value, sch schema.Schema, ns tree.NodeStore) (prolly.Map, error) {
    37  	root, err := NodeFromValue(v)
    38  	if err != nil {
    39  		return prolly.Map{}, err
    40  	}
    41  	kd := sch.GetKeyDescriptor()
    42  	vd := sch.GetValueDescriptor()
    43  	return prolly.NewMap(root, ns, kd, vd), nil
    44  }