MCPcopy Create free account
hub / github.com/go-pg/pg / Last

Method Last

orm/query.go:827–838  ·  view source on GitHub ↗

Last sorts rows by primary key and selects the last row. It is a shortcut for: q.OrderExpr("id DESC").Limit(1)

()

Source from the content-addressed store, hash-verified

825//
826// q.OrderExpr("id DESC").Limit(1)
827func (q *Query) Last() error {
828 table := q.tableModel.Table()
829
830 if err := table.checkPKs(); err != nil {
831 return err
832 }
833
834 // TODO: fix for multi columns
835 b := appendColumns(nil, table.Alias, table.PKs)
836 b = append(b, " DESC"...)
837 return q.OrderExpr(internal.BytesToString(b)).Limit(1).Select()
838}
839
840// Select selects the model.
841func (q *Query) Select(values ...interface{}) error {

Callers 1

Calls 7

OrderExprMethod · 0.95
BytesToStringFunction · 0.92
appendColumnsFunction · 0.85
checkPKsMethod · 0.80
LimitMethod · 0.80
TableMethod · 0.65
SelectMethod · 0.45

Tested by 1