Andrey
Andrey

Reputation: 2729

Fluent with MySQL (MariaDB) Geometry column type

I need to retrieve latitude/longitude from MariaDB database stored as POINT data type and unable to find a solution for this.

I tried to read value as a string:

@Field(key: "location")
var location: String?

But it's not working (no wonder). The error I experience is:

invalid field: location type: Optional error: typeMismatch(Swift.Optional<Swift.String>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Could not convert MySQL data to Optional: <MYSQL_TYPE_GEOMETRY>", underlyingError: nil))

Could please someone share with me any examples/conversion logic how this value could be processed?

Thank you very much.

Upvotes: 1

Views: 106

Answers (1)

Nick
Nick

Reputation: 5200

I don't think there is any support in fluent/mysql for POINT, currently. Without modifying the fluent sources, you could use a raw query to extract the x and y values as floats or the whole POINT value as a hex string and post-process. Alternatively, it doesn't look too onerous to add your own data-type, decoder and encoder.

Upvotes: 1

Related Questions