github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/state/impl_querycontext_storage.go (about)

     1  /*
     2   * Copyright (c) 2023-present unTill Pro, Ltd.
     3   */
     4  
     5  package state
     6  
     7  import (
     8  	"github.com/voedger/voedger/pkg/appdef"
     9  	"github.com/voedger/voedger/pkg/istructs"
    10  )
    11  
    12  type queryContextStorage struct {
    13  	argFunc  ArgFunc
    14  	wsidFunc WSIDFunc
    15  }
    16  
    17  func (s *queryContextStorage) NewKeyBuilder(_ appdef.QName, _ istructs.IStateKeyBuilder) istructs.IStateKeyBuilder {
    18  	return newKeyBuilder(QueryContext, appdef.NullQName)
    19  }
    20  func (s *queryContextStorage) Get(_ istructs.IStateKeyBuilder) (istructs.IStateValue, error) {
    21  	return &qryContextValue{
    22  		arg:  s.argFunc(),
    23  		wsid: s.wsidFunc(),
    24  	}, nil
    25  }
    26  
    27  type qryContextValue struct {
    28  	istructs.IStateValue
    29  	arg  istructs.IObject
    30  	wsid istructs.WSID
    31  }
    32  
    33  func (v *qryContextValue) AsInt64(name string) int64 {
    34  	if name == Field_Workspace {
    35  		return int64(v.wsid)
    36  	}
    37  	panic(errUndefined(name))
    38  }
    39  
    40  func (v *qryContextValue) AsValue(name string) istructs.IStateValue {
    41  	if name == Field_ArgumentObject {
    42  		return &objectValue{
    43  			object: v.arg,
    44  		}
    45  	}
    46  	panic(errUndefined(name))
    47  }