When using a model with a Decimal property, queries for those rows fail since the decimal value cannot be parsed.
Steps to reproduce
Create a model with a decimal property, e.g.
final class Product: Model {
static let schema = "Products"
@ID(custom: .id)
var id: Int?
@Field(key: "price")
var price: Decimal
init() { }
}
Create a MySQL table "Products" with a field "price" as Decimal(12,2)
Create a row in Products with a price like 19.99
Implement a typical get REST method in Vapor that returns a Product by ID.
When testing the GET method, the query will fail
Expected behavior
The GET method should return the Product with its price
Actual behavior
The query fails because the decimal value cannot be parsed from the MySQLData object.
Environment
Fluent-Kit version: 1.0.2
OS version: macOS 10.15.5
MySQL Server: 5.7.29
Proposed solution
The MySQLData returned in our scenario is of type MYSQL_TYPE_NEWDECIMAL. The current implementation for decimal parsing however uses the "string" property of MySQLData, which cannot deal with it.
When using a model with a Decimal property, queries for those rows fail since the decimal value cannot be parsed.
Steps to reproduce
Create a model with a decimal property, e.g.
Create a MySQL table "Products" with a field "price" as Decimal(12,2)
Create a row in Products with a price like 19.99
Implement a typical get REST method in Vapor that returns a Product by ID.
When testing the GET method, the query will fail
Expected behavior
The GET method should return the Product with its price
Actual behavior
The query fails because the decimal value cannot be parsed from the MySQLData object.
Environment
Proposed solution
The MySQLData returned in our scenario is of type MYSQL_TYPE_NEWDECIMAL. The current implementation for decimal parsing however uses the "string" property of MySQLData, which cannot deal with it.
I implemented a decimal property method for MySQLData and updated the tests for it: https://github.com/vapor/mysql-nio/pull/35