I am writing a service wherein I students from a UUID with PostgreSQL. I chose pgx (https://github.com/jackc/pgx) as a driver. I've debugged my program entirely and it seems that nothing is called after I call row.Scan
. My connection is working and I am able to interact with the database (tested with inserts). The connection URI has a user with all permissions granted so that is not an issue. Here is my function definition:
func (r *StudentPgRepo) GetStudentById(uuid *uuid.UUID) (*aggregate.Student, error) {
row := r.pool.QueryRow(context.Background(), "SELECT * FROM students WHERE student_id = $1", uuid.String())
student := new(aggregate.Student)
if err := row.Scan(
&student.Id, &student.FName, &student.LName, &student.PwHash, &student.Created,
&student.Updated, &student.P1.FName, &student.P1.LName, &student.P1.Email,
&student.P2.FName, &student.P2.LName, &student.P2.Email, &student.ParentDetails,
&student.Timezone, &student.Country, &student.State, &student.City, &student.Age,
&student.Gender, &student.Race, &student.NewStudent, &student.MealAssistance,
); err != nil {
if err == pgx.ErrNoRows {
return nil, ErrStudentNotFound
}
return nil, err
}
return student, nil
}
Please let me know if there are any other details I should provide. Thank you.
Here is my function call:
if err != nil {
panic(err)
}
defer dbpool.Close()
r, err := student.NewStudentPgRepo(dbpool)
if err != nil {
panic(err)
}
uid := uuid.New()
_, err = r.GetStudentById(&uid)
if err != nil {
panic(err)
}