Attendance Query Documentation
This code provides functions for querying and manipulating attendance log data in the database. It uses the PocketBase DAO for database interactions and includes functions for retrieving, inserting, and updating attendance log records.
Functions
GetDeviceAttendanceLogsByDate
func GetDeviceAttendanceLogsByDate(dao *daos.Dao, deviceID string, startDate, endDate time.Time) ([]*entity.AttendanceLogTable, error)
Retrieves attendance logs for a specific device within a date range.
dao: The PocketBase DAO.deviceID: The ID of the device.startDate: The start date of the range.endDate: The end date of the range.- Returns: A slice of
AttendanceLogTablepointers containing the attendance logs, or an error if the operation fails.
GetAttendanceLogsByIDs
func GetAttendanceLogsByIDs(dao *daos.Dao, ids []string) ([]*entity.AttendanceLogTable, error)
Retrieves attendance logs by their IDs.
dao: The PocketBase DAO.ids: A slice of attendance log IDs.- Returns: A slice of
AttendanceLogTablepointers containing the attendance logs, or an error if the operation fails.
BulkInsertAttendanceLogs
func BulkInsertAttendanceLogs(dao *daos.Dao, items []*entity.AttendanceLogTable) error
Inserts multiple attendance logs into the database.
dao: The PocketBase DAO.items: A slice ofAttendanceLogTablepointers containing the attendance logs to be inserted.- Returns: An error if the operation fails.
GetUserAttendanceLogsByDateRange
func GetUserAttendanceLogsByDateRange(dao *daos.Dao, userProfileID string, startDate, endDate time.Time) ([]*entity.AttendanceLogTable, error)
Retrieves attendance logs for a specific user within a date range.
dao: The PocketBase DAO.userProfileID: The ID of the user profile.startDate: The start date of the range.endDate: The end date of the range.- Returns: A slice of
AttendanceLogTablepointers containing the attendance logs, 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 (
"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 Device Attendance Logs by Date
package main
import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
"time"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
// Retrieve attendance logs for a device within a date range
deviceID := "device123"
startDate := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2023, 1, 31, 23, 59, 59, 0, time.UTC)
logs, err := queries.GetDeviceAttendanceLogsByDate(dao, deviceID, startDate, endDate)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Device Attendance Logs:", logs)
}
Retrieving Attendance Logs by IDs
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 attendance logs by IDs
ids := []string{"log123", "log456"}
logs, err := queries.GetAttendanceLogsByIDs(dao, ids)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Attendance Logs by IDs:", logs)
}
Bulk Inserting Attendance Logs
package main
import (
"fio-backend/entity"
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
"time"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
// Create attendance logs to insert
logs := []*entity.AttendanceLogTable{
{
UserProfileID: "user123",
DeviceID: "device123",
UserDeviceName: "John Doe",
DevicePin: "123456",
Timestamp: time.Now().Format(time.RFC3339),
TimestampOriginal: time.Now().Format(time.RFC3339),
Method: "Fingerprint",
},
{
UserProfileID: "user456",
DeviceID: "device456",
UserDeviceName: "Jane Doe",
DevicePin: "654321",
Timestamp: time.Now().Format(time.RFC3339),
TimestampOriginal: time.Now().Format(time.RFC3339),
Method: "Card",
},
}
// Bulk insert attendance logs
err := queries.BulkInsertAttendanceLogs(dao, logs)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Attendance Logs Inserted Successfully")
}
Retrieving User Attendance Logs by Date Range
package main
import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
"time"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
// Retrieve attendance logs for a user within a date range
userProfileID := "user123"
startDate := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2023, 1, 31, 23, 59, 59, 0, time.UTC)
logs, err := queries.GetUserAttendanceLogsByDateRange(dao, userProfileID, startDate, endDate)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("User Attendance Logs by Date Range:", logs)
}
This documentation provides an overview of the attendance query functions, their parameters, and example usage. By following the examples, you can retrieve, insert, and update attendance log records in the database.