mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:11:49 +00:00
[doc] Add docs for basestore map scanner (#48281)
## Description [Old docs are here](https://docs.sourcegraph.com/dev/background-information/basestore#using-basestore-helpers-for-scanning) [New docs are here](https://docs.sourcegraph.com/@milan_basestore_docs/dev/background-information/basestore#using-basestore-helpers-for-scanning) New docs can be seen here: ## Test plan since it's just docs changes, eyeballing 👀
This commit is contained in:
parent
03ff546503
commit
476ce7d826
@ -198,6 +198,18 @@ func (s *MyStore) ItsHorsegraphTime(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Scan map[string]int32
|
||||
horseNameToID, err := scanHorseNameToID(s.Query(ctx, sqlf.Sprintf("SELECT id, name FROM horses"))) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Scan map[string]horse
|
||||
horseMap, err := scanMapHorses(s.Query(ctx, sqlf.Sprintf("SELECT id, age, name, nicknames, passportName FROM horses")))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// scanHorses can scan a row of `horse`s into `[]*horse`
|
||||
@ -212,6 +224,18 @@ func scanHorse(s dbutil.Scanner) (*horse, error) {
|
||||
return &h, nil
|
||||
}
|
||||
|
||||
var scanHorseNameToID = basestore.NewMapScanner(func(s dbutil.Scanner) (string, int32, error) {
|
||||
var id int32
|
||||
var name string
|
||||
err := s.Scan(&id, &name)
|
||||
return name, id, err
|
||||
})
|
||||
|
||||
var scanMapHorses = basestore.NewMapScanner(func(s dbutil.Scanner) (string, *horse, error) {
|
||||
h, err := scanHorse(s)
|
||||
return h.name, h, err
|
||||
})
|
||||
|
||||
type horse struct {
|
||||
id int32
|
||||
age int32
|
||||
|
||||
Loading…
Reference in New Issue
Block a user