private/dbutil/pgutil: add UUIDArray helper
Change-Id: I469fa2381b7c1a731880a742787bb4842af9b902
This commit is contained in:
parent
1d28dc314c
commit
4a2c6f6208
@ -9,6 +9,7 @@ import (
|
||||
"github.com/jackc/pgtype"
|
||||
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/uuid"
|
||||
)
|
||||
|
||||
// The following XArray() helper methods exist alongside similar methods in the
|
||||
@ -134,3 +135,22 @@ func NodeIDArray(nodeIDs []storj.NodeID) *pgtype.ByteaArray {
|
||||
Status: pgtype.Present,
|
||||
}
|
||||
}
|
||||
|
||||
// UUIDArray returns an object usable by pg drivers for passing a []uuid.UUID
|
||||
// slice into a database as type BYTEA[].
|
||||
func UUIDArray(uuids []uuid.UUID) *pgtype.ByteaArray {
|
||||
if uuids == nil {
|
||||
return &pgtype.ByteaArray{Status: pgtype.Null}
|
||||
}
|
||||
pgtypeByteaArray := make([]pgtype.Bytea, len(uuids))
|
||||
for i, uuid := range uuids {
|
||||
uuidCopy := uuid
|
||||
pgtypeByteaArray[i].Bytes = uuidCopy[:]
|
||||
pgtypeByteaArray[i].Status = pgtype.Present
|
||||
}
|
||||
return &pgtype.ByteaArray{
|
||||
Elements: pgtypeByteaArray,
|
||||
Dimensions: []pgtype.ArrayDimension{{Length: int32(len(uuids)), LowerBound: 1}},
|
||||
Status: pgtype.Present,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user