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

     1  package wasmlog
     2  
     3  import (
     4  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder"
     5  	"github.com/machinefi/w3bstream/pkg/models"
     6  	"github.com/machinefi/w3bstream/pkg/types"
     7  )
     8  
     9  type CondArgs struct {
    10  	InstanceID types.SFID `name:"-"`
    11  	Srcs       []string   `in:"query" name:"srcs,omitempty"`
    12  	SrcLike    string     `in:"query" name:"src,omitempty"`
    13  	LSrcLike   string     `in:"query" name:"lSrc,omitempty"`
    14  }
    15  
    16  func (r *CondArgs) Condition() builder.SqlCondition {
    17  	var (
    18  		m = &models.WasmLog{}
    19  		c []builder.SqlCondition
    20  	)
    21  	if r.InstanceID != 0 {
    22  		c = append(c, m.ColInstanceID().Eq(r.InstanceID))
    23  	}
    24  	if len(r.Srcs) > 0 {
    25  		c = append(c, m.ColSrc().In(r.Srcs))
    26  	}
    27  	if r.SrcLike != "" {
    28  		c = append(c, m.ColSrc().Like(r.SrcLike))
    29  	}
    30  	if r.LSrcLike != "" {
    31  		c = append(c, m.ColSrc().LLike(r.LSrcLike))
    32  	}
    33  	return builder.And(c...)
    34  }