encodeUUID encodes a UUID value as 16 raw bytes (PostgreSQL binary UUID format). DuckDB Go driver returns UUID as []byte (16 bytes).
(v interface{})
| 527 | // encodeUUID encodes a UUID value as 16 raw bytes (PostgreSQL binary UUID format). |
| 528 | // DuckDB Go driver returns UUID as []byte (16 bytes). |
| 529 | func encodeUUID(v interface{}) []byte { |
| 530 | switch val := v.(type) { |
| 531 | case []byte: |
| 532 | if len(val) == 16 { |
| 533 | return val |
| 534 | } |
| 535 | return nil |
| 536 | case string: |
| 537 | s := strings.ReplaceAll(val, "-", "") |
| 538 | if len(s) != 32 { |
| 539 | return nil |
| 540 | } |
| 541 | data, err := hex.DecodeString(s) |
| 542 | if err != nil { |
| 543 | return nil |
| 544 | } |
| 545 | return data |
| 546 | default: |
| 547 | // Try Stringer interface (e.g., duckdb.UUID) |
| 548 | if stringer, ok := v.(fmt.Stringer); ok { |
| 549 | return encodeUUID(stringer.String()) |
| 550 | } |
| 551 | return nil |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | // decodeUUID decodes 16 raw bytes into a UUID string "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx". |
| 556 | func decodeUUID(data []byte) (string, error) { |