Files
query-orchestration/internal/database/parseuuid.go
T

41 lines
700 B
Go
Raw Normal View History

2025-01-06 15:31:39 +00:00
package database
import (
2025-01-10 11:12:03 +00:00
"log"
2025-01-06 15:31:39 +00:00
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
func MustToDBUUIDArray(ids []uuid.UUID) []pgtype.UUID {
dbIDs := make([]pgtype.UUID, len(ids))
for index, id := range ids {
dbIDs[index] = MustToDBUUID(id)
}
return dbIDs
}
func MustToDBUUID(id uuid.UUID) pgtype.UUID {
var dbID pgtype.UUID
2025-01-10 11:12:03 +00:00
err := dbID.Scan(id.String())
if err != nil {
log.Panic(err)
}
2025-01-06 15:31:39 +00:00
return dbID
}
func MustToUUID(id pgtype.UUID) uuid.UUID {
return uuid.Must(uuid.FromBytes(id.Bytes[:]))
}
func MustToUUIDArray(dbIDs []pgtype.UUID) []uuid.UUID {
ids := make([]uuid.UUID, len(dbIDs))
for index, id := range dbIDs {
ids[index] = MustToUUID(id)
}
return ids
}