MCPcopy
hub / github.com/go-gorm/gorm / Last

Method Last

finisher_api.go:158–171  ·  view source on GitHub ↗

Last finds the last record ordered by primary key, matching given conditions conds

(dest interface{}, conds ...interface{})

Source from the content-addressed store, hash-verified

156
157// Last finds the last record ordered by primary key, matching given conditions conds
158func (db *DB) Last(dest interface{}, conds ...interface{}) (tx *DB) {
159 tx = db.Limit(1).Order(clause.OrderByColumn{
160 Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey},
161 Desc: true,
162 })
163 if len(conds) > 0 {
164 if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 {
165 tx.Statement.AddClause(clause.Where{Exprs: exprs})
166 }
167 }
168 tx.Statement.RaiseErrorOnNotFound = true
169 tx.Statement.Dest = dest
170 return tx.callbacks.Query().Execute(tx)
171}
172
173// Find finds all records matching given conditions conds
174func (db *DB) Find(dest interface{}, conds ...interface{}) (tx *DB) {

Callers

nothing calls this directly

Calls 6

LimitMethod · 0.95
BuildConditionMethod · 0.80
AddClauseMethod · 0.80
ExecuteMethod · 0.80
QueryMethod · 0.80
OrderMethod · 0.65

Tested by

no test coverage detected