Skip to content

Retrieved binary is converted to a string #78

Closed
@AlexErrant

Description

@AlexErrant

AFAICT, this library does not support retrieving binary as binary.

I added some code inspired by custom type casting function:

function inflate(field, value) {
  console.log("field.type", field.type)
  console.log("value", value)
  console.log("value type", typeof value)
  return cast(field, value)
}

When I do so, here is some representative output of some UUIDs:

field.type BINARY
value ø0sô¼A¤ÿçÐsô
value type string
field.type BINARY
value AD3ADFB038724973
value type string
field.type BINARY
value type string

Yes, the third value is missing - it is seemingly unprintable and silently killed that console.log. This isn't surprising because not all binary is valid utf-8.

Some code, if you want gory details.
create table Media_User
(
    mediaId binary(16)  not null,
    userId  varchar(21) not null,
    primary key (mediaId, userId)
)
    collate = utf8mb4_unicode_ci;

INSERT INTO Media_User (mediaId, userId) VALUES (0x11f830737ff4bc41a4ffe792d073f41f, 'ff')
INSERT INTO Media_User (mediaId, userId) VALUES (0x41443341444642303338373234393733, 'ff')
INSERT INTO Media_User (mediaId, userId) VALUES (0x737295711B1121479411906BBD2F7A34, 'ff')
    import { connect, cast } from "@planetscale/database"

    const config = {
      cast: inflate,
      url: somethngSecret,
    }

    const conn = connect(config)
    const results = await conn.execute("select mediaId from planetScaleDb.Media_User")
    console.log("------------------")
    console.log(results.rows[0])
    console.log(results.rows[1])
    console.log(results.rows[2])

This occurs for me on cloudflare workers (and miniflare).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions