github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/istructsmem/internal/dynobuf/impl.go (about)

     1  /*
     2   * Copyright (c) 2021-present Sigma-Soft, Ltd.
     3   * @author: Nikolay Nikitin
     4   */
     5  
     6  package dynobuf
     7  
     8  import (
     9  	"github.com/untillpro/dynobuffers"
    10  	"github.com/voedger/voedger/pkg/appdef"
    11  )
    12  
    13  func newSchemes() *DynoBufSchemes {
    14  	cache := &DynoBufSchemes{
    15  		schemes: make(map[string]*dynobuffers.Scheme),
    16  	}
    17  	return cache
    18  }
    19  
    20  // Prepares schemes
    21  func (sch *DynoBufSchemes) Prepare(appDef appdef.IAppDef) {
    22  	appDef.Types(
    23  		func(t appdef.IType) {
    24  			if view, ok := t.(appdef.IView); ok {
    25  				sch.addView(view)
    26  				return
    27  			}
    28  			if fld, ok := t.(appdef.IFields); ok {
    29  				sch.add(t.QName().String(), fld)
    30  			}
    31  		})
    32  }
    33  
    34  // Returns structure scheme. Nil if not found
    35  //
    36  // This method can be used to get scheme for:
    37  //   - any structured type (doc or record),
    38  //   - view value
    39  func (sch DynoBufSchemes) Scheme(name appdef.QName) *dynobuffers.Scheme {
    40  	return sch.schemes[name.String()]
    41  }
    42  
    43  // Returns view partition key scheme. Nil if not found
    44  func (sch DynoBufSchemes) ViewPartKeyScheme(name appdef.QName) *dynobuffers.Scheme {
    45  	return sch.schemes[name.String()+viewPartKeySuffix]
    46  }
    47  
    48  // Returns view clustering columns scheme. Nil if not found
    49  func (sch DynoBufSchemes) ViewClustColsScheme(name appdef.QName) *dynobuffers.Scheme {
    50  	return sch.schemes[name.String()+viewClustColsSuffix]
    51  }
    52  
    53  // Adds scheme
    54  func (sch *DynoBufSchemes) add(name string, fields appdef.IFields) {
    55  	sch.schemes[name] = NewFieldsScheme(name, fields)
    56  }
    57  
    58  // Adds four view schemes:
    59  //   - view key,
    60  //   - partition key,
    61  //   - clustering columns and
    62  //   - view value
    63  func (sch *DynoBufSchemes) addView(view appdef.IView) {
    64  	name := view.QName().String()
    65  	sch.add(name+viewPartKeySuffix, view.Key().PartKey())
    66  	sch.add(name+viewClustColsSuffix, view.Key().ClustCols())
    67  	sch.add(name, view.Value())
    68  }