github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/sqlx/builder/builder_alias.go (about)

     1  package builder
     2  
     3  import "context"
     4  
     5  type alias struct {
     6  	name string
     7  	SqlExpr
     8  }
     9  
    10  func Alias(e SqlExpr, name string) *alias {
    11  	return &alias{name: name, SqlExpr: e}
    12  }
    13  
    14  func (as *alias) IsNil() bool {
    15  	return as == nil || as.name == "" || IsNilExpr(as.SqlExpr)
    16  }
    17  
    18  func (as *alias) Ex(ctx context.Context) *Ex {
    19  	return Expr(
    20  		"? AS ?",
    21  		as.SqlExpr,
    22  		Expr(as.name),
    23  	).Ex(ContextWithToggleNeedAutoAlias(ctx, false))
    24  }