Pluck queries a single column from a model, returning in the slice dest. E.g.: var ages []int64 db.Model(&users).Pluck("age", &ages)
(column string, dest interface{})
| 569 | // var ages []int64 |
| 570 | // db.Model(&users).Pluck("age", &ages) |
| 571 | func (db *DB) Pluck(column string, dest interface{}) (tx *DB) { |
| 572 | tx = db.getInstance() |
| 573 | if tx.Statement.Model != nil { |
| 574 | if tx.Statement.Parse(tx.Statement.Model) == nil { |
| 575 | if f := tx.Statement.Schema.LookUpField(column); f != nil { |
| 576 | column = f.DBName |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | if len(tx.Statement.Selects) != 1 { |
| 582 | fields := strings.FieldsFunc(column, utils.IsInvalidDBNameChar) |
| 583 | tx.Statement.AddClauseIfNotExists(clause.Select{ |
| 584 | Distinct: tx.Statement.Distinct, |
| 585 | Columns: []clause.Column{{Name: column, Raw: len(fields) != 1}}, |
| 586 | }) |
| 587 | } |
| 588 | tx.Statement.Dest = dest |
| 589 | return tx.callbacks.Query().Execute(tx) |
| 590 | } |
| 591 | |
| 592 | func (db *DB) ScanRows(rows *sql.Rows, dest interface{}) error { |
| 593 | tx := db.getInstance() |