Logo
Explore Help
Sign In
tandem/campingmontagut
tandem/campingmontagut
2
0
Fork 0
You've already forked campingmontagut
Code Issues Pull Requests Packages Projects Releases Wiki Activity
campingmontagut/pkg/database/zeronull.go

26 lines
440 B
Go
Raw Normal View History

Change draft_payment return type to row of payment This way i can use the function in the from clause of the query that i already had to do to get the totals formatted with to_price. In this case, i believe it is better to leave out Go’s function because it would force me to perform two queries. Instead of binding a nullable string pointer with the payment’s slug, i wanted to use pgtype’s zeronull.Text type, but it can not work in this case because it encodes the value as a text, while the parameters is uuid. I can not use zero.UUID, because it is a [16]byte array, while i have it in a string. Thus, had to create my own ZeroNullUUID type that use a string as a base but encodes it as a UUID.
2024-02-13 19:51:39 +01:00
package database
import (
"github.com/jackc/pgtype"
"dev.tandem.ws/tandem/camper/pkg/uuid"
)
type ZeroNullUUID string
func (src ZeroNullUUID) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
if src == "" {
return nil, nil
}
bytes, err := uuid.Parse(string(src))
if err != nil {
return nil, err
}
nullable := pgtype.UUID{
Bytes: bytes,
Status: pgtype.Present,
}
return nullable.EncodeBinary(ci, buf)
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 52ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API