feat: add StringKSUID and BinaryKSUID types

Replace the UUID wrapper with storage-specific KSUID types that share
GraphQL string transit but use distinct SQL Scan/Value encodings.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-29 17:47:41 -07:00
parent 984b52d198
commit a303e025b2
6 changed files with 330 additions and 66 deletions
+37
View File
@@ -0,0 +1,37 @@
package dbx
import (
"encoding/json"
"fmt"
"io"
"github.com/segmentio/ksuid"
)
type ksuidGQLTransport struct {
KSUIDStr string `json:"ksuid_str"`
}
func unmarshalKSUIDFromGQL(value any, unmarshal func([]byte) error) error {
str, ok := value.(string)
if !ok {
return fmt.Errorf("GraphQL failed to unmarshal KSUID value: %v", value)
}
return unmarshal([]byte(str))
}
func marshalKSUIDToGQL(w io.Writer, id ksuid.KSUID) {
transport := ksuidGQLTransport{KSUIDStr: id.String()}
data, err := json.Marshal(transport)
if err != nil {
panic(fmt.Errorf("GraphQL failed to JSON-marshal KSUID value: %s", err))
}
if _, err := w.Write(data); err != nil {
panic(fmt.Errorf("GraphQL failed to write KSUID value: %s", string(data)))
}
}
const (
ksuidBinaryLength = 20
ksuidStringLength = 27
)