89 lines
1.5 KiB
Go
89 lines
1.5 KiB
Go
package repository
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/tenant/repository/generated"
|
|
)
|
|
|
|
func newQuerier(db generated.DBTX) generated.Querier {
|
|
return generated.New(db)
|
|
}
|
|
|
|
func nullableText(value pgtype.Text) *string {
|
|
if !value.Valid {
|
|
return nil
|
|
}
|
|
text := value.String
|
|
return &text
|
|
}
|
|
|
|
func nullableAnyText(value interface{}) *string {
|
|
switch typed := value.(type) {
|
|
case nil:
|
|
return nil
|
|
case string:
|
|
return &typed
|
|
case []byte:
|
|
text := string(typed)
|
|
return &text
|
|
case pgtype.Text:
|
|
return nullableText(typed)
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func nullableInt64(value pgtype.Int8) *int64 {
|
|
if !value.Valid {
|
|
return nil
|
|
}
|
|
number := value.Int64
|
|
return &number
|
|
}
|
|
|
|
func intFromInt4(value pgtype.Int4) int {
|
|
if !value.Valid {
|
|
return 0
|
|
}
|
|
return int(value.Int32)
|
|
}
|
|
|
|
func timeFromTimestamp(value pgtype.Timestamptz) time.Time {
|
|
if !value.Valid {
|
|
return time.Time{}
|
|
}
|
|
return value.Time
|
|
}
|
|
|
|
func optionalTime(value pgtype.Timestamptz) *time.Time {
|
|
if !value.Valid {
|
|
return nil
|
|
}
|
|
t := value.Time
|
|
return &t
|
|
}
|
|
|
|
func pgText(value *string) pgtype.Text {
|
|
if value == nil {
|
|
return pgtype.Text{}
|
|
}
|
|
return pgtype.Text{String: *value, Valid: true}
|
|
}
|
|
|
|
func pgInt8(value *int64) pgtype.Int8 {
|
|
if value == nil {
|
|
return pgtype.Int8{}
|
|
}
|
|
return pgtype.Int8{Int64: *value, Valid: true}
|
|
}
|
|
|
|
func pgTimestamp(value *time.Time) pgtype.Timestamptz {
|
|
if value == nil {
|
|
return pgtype.Timestamptz{}
|
|
}
|
|
return pgtype.Timestamptz{Time: *value, Valid: true}
|
|
}
|