gorm icon indicating copy to clipboard operation
gorm copied to clipboard

the output of .Debug() for UUID binary(16)

Open HZSHZSHZS opened this issue 2 years ago • 2 comments

Your Question

I use MySql binary(16) to store UUID generated from google uuid pkg. When under '.Debug()' mode, like db.Debug().Create()... on the output of SQL statement, some uuid will be output as '', but some uuid will be output as '%5ČA\ufffd@"\ufffd4\ufffd q! \ufffd' which is invalid UTF-8.

Expected answer

HZSHZSHZS avatar Feb 02 '23 02:02 HZSHZSHZS

I cannot reproduce your situation. Could you plz provide your code?

I tried to reproduce (but use sqlite) and the UUID is output correctly.

package main

import (
	"github.com/google/uuid"
	"github.com/tzq0301/gorms"
)

type User struct {
	ID uuid.UUID
}

func main() {
	db, _ := gorms.InMemorySqliteWithInitSQL(`
CREATE TABLE users (
  	id BINARY(16)
);
`)

	id, _ := uuid.NewUUID()

	db.Debug().Create(&User{ID: id})
}

// Output in console:
// [0.180ms] [rows:1] INSERT INTO `users` (`id`) VALUES ("f6b07a8a-a79e-11ed-80ca-acde48001122")

tzq0301 avatar Feb 08 '23 10:02 tzq0301

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

github-actions[bot] avatar Feb 04 '24 02:02 github-actions[bot]