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

Function Scan

scan.go:126–369  ·  view source on GitHub ↗

Scan scan rows into db statement

(rows Rows, db *DB, mode ScanMode)

Source from the content-addressed store, hash-verified

124
125// Scan scan rows into db statement
126func Scan(rows Rows, db *DB, mode ScanMode) {
127 var (
128 columns, _ = rows.Columns()
129 values = make([]interface{}, len(columns))
130 initialized = mode&ScanInitialized != 0
131 update = mode&ScanUpdate != 0
132 onConflictDonothing = mode&ScanOnConflictDoNothing != 0
133 )
134
135 if len(db.Statement.ColumnMapping) > 0 {
136 for i, column := range columns {
137 v, ok := db.Statement.ColumnMapping[column]
138 if ok {
139 columns[i] = v
140 }
141 }
142 }
143
144 db.RowsAffected = 0
145
146 switch dest := db.Statement.Dest.(type) {
147 case map[string]interface{}, *map[string]interface{}:
148 if initialized || rows.Next() {
149 columnTypes, _ := rows.ColumnTypes()
150 prepareValues(values, db, columnTypes, columns)
151
152 db.RowsAffected++
153 db.AddError(rows.Scan(values...))
154
155 mapValue, ok := dest.(map[string]interface{})
156 if !ok {
157 if v, ok := dest.(*map[string]interface{}); ok {
158 if *v == nil {
159 *v = map[string]interface{}{}
160 }
161 mapValue = *v
162 }
163 }
164 scanIntoMap(mapValue, values, columns)
165 }
166 case *[]map[string]interface{}:
167 columnTypes, _ := rows.ColumnTypes()
168 for initialized || rows.Next() {
169 prepareValues(values, db, columnTypes, columns)
170
171 initialized = false
172 db.RowsAffected++
173 db.AddError(rows.Scan(values...))
174
175 mapValue := map[string]interface{}{}
176 scanIntoMap(mapValue, values, columns)
177 *dest = append(*dest, mapValue)
178 }
179 case *int, *int8, *int16, *int32, *int64,
180 *uint, *uint8, *uint16, *uint32, *uint64, *uintptr,
181 *float32, *float64,
182 *bool, *string, *time.Time,
183 *sql.NullInt32, *sql.NullInt64, *sql.NullFloat64,

Callers 5

QueryFunction · 0.92
UpdateFunction · 0.92
DeleteFunction · 0.92
CreateFunction · 0.92
ScanRowsMethod · 0.85

Calls 15

ParseFunction · 0.92
SplitNestedRelationNameFunction · 0.92
JoinNestedRelationNamesFunction · 0.92
prepareValuesFunction · 0.85
scanIntoMapFunction · 0.85
NextMethod · 0.80
LookUpFieldMethod · 0.80
LenMethod · 0.80
CapMethod · 0.80
MakeSliceMethod · 0.80
scanIntoStructMethod · 0.80
AppendMethod · 0.80

Tested by

no test coverage detected