vapor / mysql-nio

🐬 Non-blocking, event-driven Swift client for MySQL.
MIT License
87 stars 28 forks source link

Could not convert MySQL data to String: <MYSQL_TYPE_JSON> #82

Closed pardeike closed 1 year ago

pardeike commented 1 year ago

Hi,

I have a table with a column in json format:

CREATE TABLE "document" (
  ...
  "payload_json" json DEFAULT NULL,
  ...
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_sv_0900_ai_ci;

My model is defined as

public struct Document: Codable, Hashable {
    //...
    public let payloadJson: String?
    //...
    public init() {
        //...
        payloadJson = ""
        //...
    }
}

when I try to decode the row with

try row.sql().decode(model: Document.self, keyDecodingStrategy: .convertFromSnakeCase)

I get the following error:

typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [], debugDescription: "Could not convert MySQL data to String: <MYSQL_TYPE_JSON>", underlyingError: nil))

Using MySQLWorkbench, I looked up the contents of the row and its value viewer shows me:

{"id": "952DA533-E953-4A3D-B84C-D375616E4107", "dela": {}, "target": "9777288B-CF99-441D-9341-A276CB3E17A0", "operation": {"delete": {}}}

Stepping through the MySQLNIO code I find it strange that this part of the code does not make use of this case.

Am I missing something here? Every other aspect of the library works really well for me.

Cheers

pardeike commented 1 year ago

Very weird. I started working on a fork but then went back to the original mysql-nio and the problem vanished