github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/sys/sqlquery/impl_wlog.go (about)

     1  /*
     2   * Copyright (c) 2022-present unTill Pro, Ltd.
     3   */
     4  
     5  package sqlquery
     6  
     7  import (
     8  	"context"
     9  	"encoding/json"
    10  	"fmt"
    11  
    12  	"github.com/voedger/voedger/pkg/appdef"
    13  	"github.com/voedger/voedger/pkg/istructs"
    14  )
    15  
    16  func readWlog(ctx context.Context, wsid istructs.WSID, offset istructs.Offset, count int, appStructs istructs.IAppStructs, f *filter, callback istructs.ExecQueryCallback,
    17  	appDef appdef.IAppDef) error {
    18  	if !f.acceptAll {
    19  		for field := range f.fields {
    20  			if !wlogDef[field] {
    21  				return fmt.Errorf("field '%s' not found in def", field)
    22  			}
    23  		}
    24  	}
    25  	return appStructs.Events().ReadWLog(ctx, wsid, offset, count, func(wlogOffset istructs.Offset, event istructs.IWLogEvent) (err error) {
    26  		data := make(map[string]interface{})
    27  
    28  		if f.filter("WlogOffset") {
    29  			data["WlogOffset"] = wlogOffset
    30  		}
    31  
    32  		renderDbEvent(data, f, event, appDef, offset)
    33  
    34  		bb, err := json.Marshal(data)
    35  		if err != nil {
    36  			return err
    37  		}
    38  
    39  		return callback(&result{value: string(bb)})
    40  	})
    41  }