diff options
author | uvok cheetah | 2023-12-09 17:52:46 +0000 |
---|---|---|
committer | uvok cheetah | 2023-12-09 17:55:24 +0000 |
commit | e5f8c0aab8e2bec4f52aeb22abe7b89eb3b01754 (patch) | |
tree | 6dab92d67e103e95261ec26d36992f5b65fa64e3 /persistence/sqlite/sqliteRepository.go | |
parent | 21c1bf9b63cd0ff01db000b13b46edd40ba6fec9 (diff) |
sql: Extract "scan function"
Diffstat (limited to 'persistence/sqlite/sqliteRepository.go')
-rw-r--r-- | persistence/sqlite/sqliteRepository.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/persistence/sqlite/sqliteRepository.go b/persistence/sqlite/sqliteRepository.go index 9e0e3f5..76ac46f 100644 --- a/persistence/sqlite/sqliteRepository.go +++ b/persistence/sqlite/sqliteRepository.go @@ -46,6 +46,14 @@ func (repo *sqliteRepository) SaveRegistration(registration *registration.Regist return err } +func rowToRegistration(scanner interface{ Scan(dest ...any) error }) (*registration.Registration, error) { + var reg registration.Registration + err := scanner.Scan(®.RegId, ®.FirstName, ®.LastName, ®.Email, ®.Company, ®.TrainingCode, ®.Date, ®.PrivacyPolicyAccepted) + if err != nil { + return nil, err + } + return ®, nil +} func (repo *sqliteRepository) GetUnconfirmedRegistrations() ([]*registration.Registration, error) { db, err := repo.checkInit() @@ -66,12 +74,11 @@ func (repo *sqliteRepository) GetUnconfirmedRegistrations() ([]*registration.Reg regArray := make([]*registration.Registration, 0) for res.Next() { - reg := registration.Registration{} - err = res.Scan(®.RegId, ®.FirstName, ®.LastName, ®.Email, ®.Company, ®.TrainingCode, ®.Date, ®.PrivacyPolicyAccepted) + reg, err := rowToRegistration(res) if err != nil { log.Printf("Error scanning: %v", err) } - regArray = append(regArray, ®) + regArray = append(regArray, reg) } return regArray, nil } |