implement dbhandler package and new test file
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package models
|
||||
|
||||
type Event struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Date string `json:"date"`
|
||||
Attendees []Person `json:"attendees"`
|
||||
Count int `json:"count"`
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Date string `gorm:"column:date" json:"date"`
|
||||
Attendees Persons `gorm:"type:json" json:"attendees"`
|
||||
Count int `gorm:"column:count" json:"count"`
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
package models
|
||||
|
||||
type Member struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
FirstName string `json:"firstName,omitempty"`
|
||||
LastName string `json:"lastName,omitempty"`
|
||||
Birthday string `json:"birthday,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Zip string `json:"zip,omitempty"`
|
||||
Town string `json:"town,omitempty"`
|
||||
Phone string `json:"phone,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
FirstVisit string `json:"firstVisit,omitempty"`
|
||||
LastVisit string `json:"lastVisit,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
ResponsiblePerson string `json:"responsiblePerson,omitempty"`
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
FirstName string `gorm:"column:firstName" json:"firstName,omitempty"`
|
||||
FirstNameHash string `gorm:"column:firstNameHash" json:"-"`
|
||||
LastName string `gorm:"column:lastName" json:"lastName,omitempty"`
|
||||
LastNameHash string `gorm:"column:lastNameHash" json:"-"`
|
||||
Birthday string `gorm:"column:birthday" json:"birthday,omitempty"`
|
||||
BirthdayHash string `gorm:"column:birthdayHash" json:"-"`
|
||||
Address string `gorm:"column:address" json:"address,omitempty"`
|
||||
Zip string `gorm:"column:zip" json:"zip,omitempty"`
|
||||
Town string `gorm:"column:town" json:"town,omitempty"`
|
||||
Phone string `gorm:"column:phone" json:"phone,omitempty"`
|
||||
Email string `gorm:"column:email" json:"email,omitempty"`
|
||||
FirstVisit string `gorm:"column:firstVisit" json:"firstVisit,omitempty"`
|
||||
LastVisit string `gorm:"column:lastVisit" json:"lastVisit,omitempty"`
|
||||
Group string `gorm:"column:group" json:"group,omitempty"`
|
||||
ResponsiblePerson string `gorm:"column:responsiblePerson" json:"responsiblePerson,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,7 +1,29 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Persons []Person
|
||||
|
||||
type Person struct {
|
||||
Id int `json:"id,omitEmpty"`
|
||||
FirstName string `json:"firstName"`
|
||||
LastName string `json:"lastName"`
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
FirstName string `gorm:"column:firstName" json:"firstName"`
|
||||
LastName string `gorm:"column:lastName" json:"lastName"`
|
||||
}
|
||||
|
||||
// --- Implement driver.Valuer (for saving to DB)
|
||||
func (r Persons) Value() (driver.Value, error) {
|
||||
return json.Marshal(r)
|
||||
}
|
||||
|
||||
// --- Implement sql.Scanner (for reading from DB)
|
||||
func (r *Persons) Scan(value any) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to unmarshal Settings: %v", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user