Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Integer Support #62

Open
masterofinsanity opened this issue Aug 2, 2021 · 0 comments
Open

Extended Integer Support #62

masterofinsanity opened this issue Aug 2, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@masterofinsanity
Copy link
Sponsor

Is your feature request related to a problem? Please describe.
I've noticed that inserting an UInt64 with a value bigger than Int.max into a field using FluentMySQL does not work.
This is because FluentMySQL only makes use of the MySQLData init(int:) initializer.
(FluentMySQL also translates UInt64 to INT in sql but this is another issue).

Describe the solution you'd like
As PostgresNIO also includes separate initializers and conversion methods for the different integer types i would suggest to also implement these in mysql-nio.

Custom initializers for MySQLData:

struct MySQLData {
//...

    //Private generic initializers
    private init<T>(type: MySQLProtocol.DataType, value: T, isUnsigned: Bool) where T: FixedWidthInteger {
        self.format = .binary
        self.type = type
        self.buffer = .init(integer: value, endianness: .little)
        self.isUnsigned = isUnsigned
    }
    private init<T>(type: MySQLProtocol.DataType, value: T) where T: FixedWidthInteger, T: SignedInteger {
        self.init(type: type, value: value, isUnsigned: false)
    }
    private init<T>(type: MySQLProtocol.DataType, value: T) where T: FixedWidthInteger, T: UnsignedInteger {
        self.init(type: type, value: value, isUnsigned: true)
    }

    //public initializers with specified MySQL DataType
    public init(int8 int: Int8) {
        self.init(type: .tiny, value: int)
    }

    public init(uint64 int: UInt64) {
        self.init(type: .longlong, value: int)
    }
    //...
}

Separate MySQLDataConvertible-Conformance
-> Instead of one extension for FixedWidthInteger. NumericCast is no longer necessary.

extension UInt64: MySQLDataConvertible {
    public init?(mysqlData: MySQLData) {
        guard let int = mysqlData.uint64 else {
            return nil
        }
        self = int
    }

    public var mysqlData: MySQLData? {
        return .init(uint64: self)
    }
}
@masterofinsanity masterofinsanity added the enhancement New feature or request label Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant