User Education Query Documentation
This code provides functions for querying and manipulating user education data in the database. It uses the PocketBase DAO for database interactions and includes functions for retrieving, inserting, and updating user education records.
Functions
GetUserLastEducation
func GetUserLastEducation(dao *daos.Dao, userProfileID string) (*entity.UserEducationTable, error)
Retrieves the last education record of a user profile by their ID.
dao: The PocketBase DAO.userProfileID: The ID of the user profile.- Returns: A pointer to a
UserEducationTablestruct containing the last education data, or an error if the operation fails.
InsertUserEducation
func InsertUserEducation(dao *daos.Dao, req *entity.UserEducationTable) (*models.Record, error)
Inserts a new user education record into the database.
dao: The PocketBase DAO.req: A pointer to aUserEducationTablestruct containing the user education data to be inserted.- Returns: A pointer to a
models.Recordcontaining the inserted record, or an error if the operation fails.
UpdateUserLastEducation
func UpdateUserLastEducation(dao *daos.Dao, userProfileID string, req *entity.UserEducationTable) (*models.Record, error)
Updates the last education record of a user profile.
dao: The PocketBase DAO.userProfileID: The ID of the user profile.req: A pointer to aUserEducationTablestruct containing the updated education data.- Returns: A pointer to a
models.Recordcontaining the updated record, or an error if the operation fails.
Example Usage
Initializing the DAO
Before using the functions, you need to initialize the PocketBase DAO.
package main
import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
}
Retrieving the Last Education Record of a User
package main
import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
// Retrieve the last education record of a user
userProfileID := "user123"
lastEducation, err := queries.GetUserLastEducation(dao, userProfileID)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Last Education Record:", lastEducation)
}
Inserting a New User Education Record
package main
import (
"fio-backend/entity"
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
// Create a new user education record
newUserEducation := &entity.UserEducationTable{
UserProfileID: "user123",
EducationLevel: "Bachelor's Degree",
EntryDate: "2015-09-01",
GraduationDate: "2019-06-01",
ScoreNum: 3.8,
ScoreAlphabet: "A",
SchoolName: "University of Example",
Major: "Computer Science",
IsLast: true,
}
// Insert the new user education record
record, err := queries.InsertUserEducation(dao, newUserEducation)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Inserted User Education Record:", record)
}
Updating the Last Education Record of a User
package main
import (
"fio-backend/entity"
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
// Create an updated user education record
updatedEducation := &entity.UserEducationTable{
UserProfileID: "user123",
EducationLevel: "Master's Degree",
EntryDate: "2020-09-01",
GraduationDate: "2022-06-01",
ScoreNum: 4.0,
ScoreAlphabet: "A",
SchoolName: "University of Example",
Major: "Computer Science",
IsLast: true,
}
// Update the last education record of the user
userProfileID := "user123"
record, err := queries.UpdateUserLastEducation(dao, userProfileID, updatedEducation)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Updated User Education Record:", record)
}
This documentation provides an overview of the user education query functions, their parameters, and example usage. By following the examples, you can retrieve, insert, and update user education records in the database.