github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/config/config_models.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder"
     7  	"github.com/machinefi/w3bstream/pkg/enums"
     8  	"github.com/machinefi/w3bstream/pkg/models"
     9  	"github.com/machinefi/w3bstream/pkg/types"
    10  	"github.com/machinefi/w3bstream/pkg/types/wasm"
    11  )
    12  
    13  type CondArgs struct {
    14  	ConfigIDs []types.SFID
    15  	RelIDs    []types.SFID
    16  	Types     []enums.ConfigType
    17  }
    18  
    19  func (r *CondArgs) Condition() builder.SqlCondition {
    20  	var (
    21  		m = &models.Config{}
    22  		c []builder.SqlCondition
    23  	)
    24  
    25  	if len(r.ConfigIDs) > 0 {
    26  		c = append(c, m.ColConfigID().In(r.ConfigIDs))
    27  	}
    28  	if len(r.RelIDs) > 0 {
    29  		c = append(c, m.ColRelID().In(r.RelIDs))
    30  	}
    31  	if len(r.Types) > 0 {
    32  		c = append(c, m.ColType().In(r.Types))
    33  	}
    34  	return builder.And(c...)
    35  }
    36  
    37  type Detail struct {
    38  	RelID types.SFID
    39  	wasm.Configuration
    40  }
    41  
    42  func (d *Detail) String() string {
    43  	return fmt.Sprintf("[rel: %v][type: %v]", d.RelID, d.ConfigType())
    44  }
    45  
    46  func (d *Detail) Log(err error) string {
    47  	s := d.String()
    48  	if err == nil {
    49  		return s
    50  	}
    51  	return fmt.Sprintf("%s: %v", s, err)
    52  }