planetscale/database-js

UUIDs Get Returned Incorrectly

RedSpid3r opened this issue · 2 comments

I have a column (id_new) on a dev branch to test using UUID7 for PKs. When doing a SELECT query the UUIDs seem to be being returned incorrectly.

Example Table

Column Name	Datatype		Collation		PK
id		INT			utf8mb4_0900_ai_ci	Yes
id_new		CHAR(36)		utf8mb4_bin
domain		VARCHAR(255)		utf8mb4_0900_ai_ci

I updated the column for this record like so:

import { uuidv7 } from "uuidv7";
const domainId = uuidv7();

await c.env.CONNECTION.transaction(async tx => {
	await tx.execute("UPDATE domains SET id_new = ? WHERE domain = ?", [domainId, 'domain.com')
})

When viewed via MySQL Workbench app, id_new shows as 018e1630-ca36-7188-94f9-7120cb925faf

However, when running a SELECT query and returning the results it shows as the following:

"rows": [
            {
                "HEX(id_new)": "30313865313633302D636133362D373138382D393466392D373132306362393235666166"
            }
        ]

My SELECT statement

SELECT HEX(id_new) FROM domains WHERE domain = 'domain.com'

Just to add here, I suspect in this case, it is related to the collation utf8mb4_bin, but want to see what the API response is for this type. Something is definitely wrong here.