From e5f8c0aab8e2bec4f52aeb22abe7b89eb3b01754 Mon Sep 17 00:00:00 2001 From: uvok cheetah Date: Sat, 9 Dec 2023 17:52:46 +0000 Subject: sql: Extract "scan function" --- persistence/sqlite/sqliteRepository.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'persistence') 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 } -- cgit v1.2.3