github.com/wanlay/gorm-dm8@v1.0.5/clauses/when_not_matched.go (about)

     1  package clauses
     2  
     3  import (
     4  	"gorm.io/gorm/clause"
     5  )
     6  
     7  type WhenNotMatched struct {
     8  	clause.Values
     9  	Where clause.Where
    10  }
    11  
    12  func (w WhenNotMatched) Name() string {
    13  	return "WHEN NOT MATCHED"
    14  }
    15  
    16  func (w WhenNotMatched) Build(builder clause.Builder) {
    17  	if len(w.Columns) > 0 {
    18  		if len(w.Values.Values) != 1 {
    19  			panic("cannot insert more than one rows due to DM SQL language restriction")
    20  		}
    21  
    22  		builder.WriteString(" THEN")
    23  		builder.WriteString(" INSERT ")
    24  		w.Values.Build(builder)
    25  
    26  		if len(w.Where.Exprs) > 0 {
    27  			builder.WriteString(w.Where.Name())
    28  			builder.WriteByte(' ')
    29  			w.Where.Build(builder)
    30  		}
    31  	}
    32  }
    33  
    34  func (w WhenNotMatched) MergeClause(clause *clause.Clause) {
    35  	clause.Name = w.Name()
    36  	clause.Expression = w
    37  }