summaryrefslogtreecommitdiff
path: root/persistence
diff options
context:
space:
mode:
authoruvok cheetah2023-12-09 17:52:46 +0000
committeruvok cheetah2023-12-09 17:55:24 +0000
commite5f8c0aab8e2bec4f52aeb22abe7b89eb3b01754 (patch)
tree6dab92d67e103e95261ec26d36992f5b65fa64e3 /persistence
parent21c1bf9b63cd0ff01db000b13b46edd40ba6fec9 (diff)
sql: Extract "scan function"
Diffstat (limited to 'persistence')
-rw-r--r--persistence/sqlite/sqliteRepository.go13
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(&reg.RegId, &reg.FirstName, &reg.LastName, &reg.Email, &reg.Company, &reg.TrainingCode, &reg.Date, &reg.PrivacyPolicyAccepted)
+ if err != nil {
+ return nil, err
+ }
+ return &reg, 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(&reg.RegId, &reg.FirstName, &reg.LastName, &reg.Email, &reg.Company, &reg.TrainingCode, &reg.Date, &reg.PrivacyPolicyAccepted)
+ reg, err := rowToRegistration(res)
if err != nil {
log.Printf("Error scanning: %v", err)
}
- regArray = append(regArray, &reg)
+ regArray = append(regArray, reg)
}
return regArray, nil
}