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

Method Scan

finisher_api.go:537–565  ·  view source on GitHub ↗

Scan scans selected value to the struct dest

(dest interface{})

Source from the content-addressed store, hash-verified

535
536// Scan scans selected value to the struct dest
537func (db *DB) Scan(dest interface{}) (tx *DB) {
538 config := *db.Config
539 currentLogger, newLogger := config.Logger, logger.Recorder.New()
540 config.Logger = newLogger
541
542 tx = db.getInstance()
543 tx.Config = &config
544
545 if rows, err := tx.Rows(); err == nil {
546 defer func() {
547 if err := rows.Close(); err != nil {
548 _ = tx.AddError(err)
549 }
550 }()
551
552 if rows.Next() {
553 tx.ScanRows(rows, dest)
554 } else {
555 tx.RowsAffected = 0
556 tx.AddError(rows.Err())
557 }
558 }
559
560 currentLogger.Trace(tx.Statement.Context, newLogger.BeginAt, func() (string, int64) {
561 return newLogger.SQL, tx.RowsAffected
562 }, tx.Error)
563 tx.Logger = currentLogger
564 return
565}
566
567// Pluck queries a single column from a model, returning in the slice dest. E.g.:
568//

Callers

nothing calls this directly

Calls 9

getInstanceMethod · 0.95
NextMethod · 0.80
ScanRowsMethod · 0.80
ErrMethod · 0.80
NewMethod · 0.65
RowsMethod · 0.65
CloseMethod · 0.65
AddErrorMethod · 0.65
TraceMethod · 0.65

Tested by

no test coverage detected