mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
chore(db): remove obsolete text.go, text_test.go and uuid.go
These files were superseded by internal/db/utils.go.
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
package db
|
||||
|
||||
import "github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
// TextToString returns the string value of pgtype.Text, or "" when invalid.
|
||||
func TextToString(value pgtype.Text) string {
|
||||
if !value.Valid {
|
||||
return ""
|
||||
}
|
||||
return value.String
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func TestTextToString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value pgtype.Text
|
||||
want string
|
||||
}{
|
||||
{"valid", pgtype.Text{String: "hello", Valid: true}, "hello"},
|
||||
{"invalid", pgtype.Text{}, ""},
|
||||
{"valid empty", pgtype.Text{String: "", Valid: true}, ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := TextToString(tt.value); got != tt.want {
|
||||
t.Errorf("TextToString() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
// ParseUUID converts a string UUID to pgtype.UUID.
|
||||
func ParseUUID(id string) (pgtype.UUID, error) {
|
||||
parsed, err := uuid.Parse(strings.TrimSpace(id))
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, fmt.Errorf("invalid UUID: %w", err)
|
||||
}
|
||||
var pgID pgtype.UUID
|
||||
pgID.Valid = true
|
||||
copy(pgID.Bytes[:], parsed[:])
|
||||
return pgID, nil
|
||||
}
|
||||
|
||||
// TimeFromPg converts a pgtype.Timestamptz to time.Time.
|
||||
func TimeFromPg(value pgtype.Timestamptz) time.Time {
|
||||
if value.Valid {
|
||||
return value.Time
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
Reference in New Issue
Block a user