b16e9f0bd1
Plan 0 (workspaces): add workspaces + workspace_memberships schema, extend JWT/Actor/claims with primary_workspace_id, seed default workspace per tenant, thread workspace_id through tenant monitoring quota. Plan A (desktop skeleton): new Electron app (apps/desktop-client) with main/ preload/renderer, shared Vue component package (packages/ui-shared), and server surface — desktop client registration + token rotation + heartbeat, SSE task event stream, desktop accounts/tasks/content handlers, publish job endpoint, and supporting repositories, services, sqlc queries, and migrations. Hard cutover per plan: remove browser-extension monitoring callback endpoints, stub legacy media API in admin-web, and delete monitoring_callback_handler.go.
128 lines
2.2 KiB
Go
128 lines
2.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"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}
|
|
}
|
|
|
|
func pgUUID(value uuid.UUID) pgtype.UUID {
|
|
return pgtype.UUID{Bytes: value, Valid: true}
|
|
}
|
|
|
|
func uuidFromPG(value pgtype.UUID) uuid.UUID {
|
|
if !value.Valid {
|
|
return uuid.Nil
|
|
}
|
|
return uuid.UUID(value.Bytes)
|
|
}
|
|
|
|
func nullableUUID(value pgtype.UUID) *uuid.UUID {
|
|
if !value.Valid {
|
|
return nil
|
|
}
|
|
parsed := uuid.UUID(value.Bytes)
|
|
return &parsed
|
|
}
|
|
|
|
func marshalJSON(value any) ([]byte, error) {
|
|
if value == nil {
|
|
return nil, nil
|
|
}
|
|
return json.Marshal(value)
|
|
}
|
|
|
|
func unmarshalStringSlice(data []byte) ([]string, error) {
|
|
if len(data) == 0 {
|
|
return nil, nil
|
|
}
|
|
var items []string
|
|
if err := json.Unmarshal(data, &items); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|