PerfectlySoft / Perfect-MySQL

A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.
https://www.perfect.org
Apache License 2.0
128 stars 61 forks source link

Relax strictness on decoding to Int from different integer widths #51

Closed Bo98 closed 5 years ago

Bo98 commented 5 years ago

This is mostly for when you are working with tables not created by Perfect-CRUD. Tables created with Perfect-CRUD are not affected by this pull request.

The scenario I am talking about is if another application created a database which, say, looked like this:

CREATE TABLE Example(
    id TINYINT PRIMARY KEY
);

and you had a Swift class that looked like this:

struct Example {
    let id: Int
}

Previously, this would error upon reading from the table as Perfect-MySQL required you to declare id as Int8. I have relaxed the restriction so that Int can be used on integer width used by the database. If you want stricter enforcement, you can still use the fixed-width Int8-Int64 types.

Why do this? There are many reasons:

There's many more reasons I can go into if you want to discuss it further.

In summary:

A test case is supplied.

Next Steps?

Bo98 commented 5 years ago

@kjessup What's your thoughts on adding UInt to Int decoding here as well (my last point above)? I can submit a pull request that does that.