...

Source file src/github.com/doug-martin/goqu/v9/exp/update_clauses.go

Documentation: github.com/doug-martin/goqu/v9/exp

     1  package exp
     2  
     3  type (
     4  	UpdateClauses interface {
     5  		HasTable() bool
     6  		clone() *updateClauses
     7  
     8  		CommonTables() []CommonTableExpression
     9  		CommonTablesAppend(cte CommonTableExpression) UpdateClauses
    10  
    11  		Table() Expression
    12  		SetTable(table Expression) UpdateClauses
    13  
    14  		SetValues() interface{}
    15  		HasSetValues() bool
    16  		SetSetValues(values interface{}) UpdateClauses
    17  
    18  		From() ColumnListExpression
    19  		HasFrom() bool
    20  		SetFrom(tables ColumnListExpression) UpdateClauses
    21  
    22  		Where() ExpressionList
    23  		ClearWhere() UpdateClauses
    24  		WhereAppend(expressions ...Expression) UpdateClauses
    25  
    26  		Order() ColumnListExpression
    27  		HasOrder() bool
    28  		ClearOrder() UpdateClauses
    29  		SetOrder(oes ...OrderedExpression) UpdateClauses
    30  		OrderAppend(...OrderedExpression) UpdateClauses
    31  		OrderPrepend(...OrderedExpression) UpdateClauses
    32  
    33  		Limit() interface{}
    34  		HasLimit() bool
    35  		ClearLimit() UpdateClauses
    36  		SetLimit(limit interface{}) UpdateClauses
    37  
    38  		Returning() ColumnListExpression
    39  		HasReturning() bool
    40  		SetReturning(cl ColumnListExpression) UpdateClauses
    41  	}
    42  	updateClauses struct {
    43  		commonTables []CommonTableExpression
    44  		table        Expression
    45  		setValues    interface{}
    46  		from         ColumnListExpression
    47  		where        ExpressionList
    48  		order        ColumnListExpression
    49  		limit        interface{}
    50  		returning    ColumnListExpression
    51  	}
    52  )
    53  
    54  func NewUpdateClauses() UpdateClauses {
    55  	return &updateClauses{}
    56  }
    57  
    58  func (uc *updateClauses) HasTable() bool {
    59  	return uc.table != nil
    60  }
    61  
    62  func (uc *updateClauses) clone() *updateClauses {
    63  	return &updateClauses{
    64  		commonTables: uc.commonTables,
    65  		table:        uc.table,
    66  		setValues:    uc.setValues,
    67  		from:         uc.from,
    68  		where:        uc.where,
    69  		order:        uc.order,
    70  		limit:        uc.limit,
    71  		returning:    uc.returning,
    72  	}
    73  }
    74  
    75  func (uc *updateClauses) CommonTables() []CommonTableExpression {
    76  	return uc.commonTables
    77  }
    78  
    79  func (uc *updateClauses) CommonTablesAppend(cte CommonTableExpression) UpdateClauses {
    80  	ret := uc.clone()
    81  	ret.commonTables = append(ret.commonTables, cte)
    82  	return ret
    83  }
    84  
    85  func (uc *updateClauses) Table() Expression {
    86  	return uc.table
    87  }
    88  
    89  func (uc *updateClauses) SetTable(table Expression) UpdateClauses {
    90  	ret := uc.clone()
    91  	ret.table = table
    92  	return ret
    93  }
    94  
    95  func (uc *updateClauses) SetValues() interface{} {
    96  	return uc.setValues
    97  }
    98  
    99  func (uc *updateClauses) HasSetValues() bool {
   100  	return uc.setValues != nil
   101  }
   102  
   103  func (uc *updateClauses) SetSetValues(values interface{}) UpdateClauses {
   104  	ret := uc.clone()
   105  	ret.setValues = values
   106  	return ret
   107  }
   108  
   109  func (uc *updateClauses) From() ColumnListExpression {
   110  	return uc.from
   111  }
   112  
   113  func (uc *updateClauses) HasFrom() bool {
   114  	return uc.from != nil && !uc.from.IsEmpty()
   115  }
   116  
   117  func (uc *updateClauses) SetFrom(from ColumnListExpression) UpdateClauses {
   118  	ret := uc.clone()
   119  	ret.from = from
   120  	return ret
   121  }
   122  
   123  func (uc *updateClauses) Where() ExpressionList {
   124  	return uc.where
   125  }
   126  
   127  func (uc *updateClauses) ClearWhere() UpdateClauses {
   128  	ret := uc.clone()
   129  	ret.where = nil
   130  	return ret
   131  }
   132  
   133  func (uc *updateClauses) WhereAppend(expressions ...Expression) UpdateClauses {
   134  	if len(expressions) == 0 {
   135  		return uc
   136  	}
   137  	ret := uc.clone()
   138  	if ret.where == nil {
   139  		ret.where = NewExpressionList(AndType, expressions...)
   140  	} else {
   141  		ret.where = ret.where.Append(expressions...)
   142  	}
   143  	return ret
   144  }
   145  
   146  func (uc *updateClauses) Order() ColumnListExpression {
   147  	return uc.order
   148  }
   149  
   150  func (uc *updateClauses) HasOrder() bool {
   151  	return uc.order != nil
   152  }
   153  
   154  func (uc *updateClauses) ClearOrder() UpdateClauses {
   155  	ret := uc.clone()
   156  	ret.order = nil
   157  	return ret
   158  }
   159  
   160  func (uc *updateClauses) SetOrder(oes ...OrderedExpression) UpdateClauses {
   161  	ret := uc.clone()
   162  	ret.order = NewOrderedColumnList(oes...)
   163  	return ret
   164  }
   165  
   166  func (uc *updateClauses) OrderAppend(oes ...OrderedExpression) UpdateClauses {
   167  	if uc.order == nil {
   168  		return uc.SetOrder(oes...)
   169  	}
   170  	ret := uc.clone()
   171  	ret.order = ret.order.Append(NewOrderedColumnList(oes...).Columns()...)
   172  	return ret
   173  }
   174  
   175  func (uc *updateClauses) OrderPrepend(oes ...OrderedExpression) UpdateClauses {
   176  	if uc.order == nil {
   177  		return uc.SetOrder(oes...)
   178  	}
   179  	ret := uc.clone()
   180  	ret.order = NewOrderedColumnList(oes...).Append(ret.order.Columns()...)
   181  	return ret
   182  }
   183  
   184  func (uc *updateClauses) Limit() interface{} {
   185  	return uc.limit
   186  }
   187  
   188  func (uc *updateClauses) HasLimit() bool {
   189  	return uc.limit != nil
   190  }
   191  
   192  func (uc *updateClauses) ClearLimit() UpdateClauses {
   193  	ret := uc.clone()
   194  	ret.limit = nil
   195  	return ret
   196  }
   197  
   198  func (uc *updateClauses) SetLimit(limit interface{}) UpdateClauses {
   199  	ret := uc.clone()
   200  	ret.limit = limit
   201  	return ret
   202  }
   203  
   204  func (uc *updateClauses) Returning() ColumnListExpression {
   205  	return uc.returning
   206  }
   207  
   208  func (uc *updateClauses) HasReturning() bool {
   209  	return uc.returning != nil && !uc.returning.IsEmpty()
   210  }
   211  
   212  func (uc *updateClauses) SetReturning(cl ColumnListExpression) UpdateClauses {
   213  	ret := uc.clone()
   214  	ret.returning = cl
   215  	return ret
   216  }
   217  

View as plain text