You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/pkg/types/pgx.go

19 lines
506 B

// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package types
import (
"github.com/jackc/pgx/v5/pgtype"
)
// PgxArray returns an object usable by pg drivers for passing a []T slice
// into a database as type T[].
func PgxArray[T any](elements []T) pgtype.Array[T] {
return pgtype.Array[T]{
Elements: elements,
Dims: []pgtype.ArrayDimension{{Length: int32(len(elements)), LowerBound: 1}},
}
}