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

WIP to add support for Geometry (POINT) type #197

Closed
wants to merge 6 commits into from

Conversation

siemensikkema
Copy link
Member

@siemensikkema siemensikkema commented Jul 5, 2018

Points can now be correctly stored and retrieved.

  • Geometry SQL Data type
  • Store point values
  • API docs
  • Tests
  • Support lineString (well known binary type 2)
  • Support polygon (3)
  • Support multiPoint (4)
  • Support multiLineString (5)
  • Support multiPolygon (6)
  • Support geometryCollection (7)

func convertToData() -> Data {
switch self {
case .point(let x, let y):
let bufferSize = MySQLGeometry.headerSize + 2 * MemoryLayout<Double>.size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MySQL spec requires these to be 8 bytes. I don't know about in Swift, but in C and C++ a double isn't guaranteed to be 8 bytes. Just to have higher precision than a float.

WKB uses 1-byte unsigned integers, 4-byte unsigned integers, and 8-byte double-precision numbers (IEEE 754 format). A byte is eight bits.

Copy link
Contributor

@BrettRToomey BrettRToomey Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C we'd typically use a static assert (compile time) to ensure that the double is the size we're expecting or update the algorithm to allow for a double to be another size

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell it is 8 bytes. The rest of the MySQL code assumes this as well. I think I will change it to a literal "16" with a comment though.

}

let _: UInt32 = try buffer.requireInteger()
let _: UInt8 = try buffer.requireInteger()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's possible, but you may want to assert that this is little-endian.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do


extension MySQLGeometry: ReflectionDecodable {
public static func reflectDecoded() throws -> (MySQLGeometry, MySQLGeometry) {
return (.point(x: 0, y: 0), .point(x: 0, y: 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the wonderful world of ReflectionDecodable, see https://github.com/vapor/core/blob/master/Sources/Core/CodableReflection/ReflectionDecodable.swift. However, it seems I don't actually need this one anymore. I believe I needed it earlier to exclude a property on my model with this type, the process of which required reflection.

@tanner0101 tanner0101 added the enhancement New feature or request label Jul 17, 2018
Copy link
Member

@tanner0101 tanner0101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this LGTM. Just needs some unit tests. :)

@siemensikkema
Copy link
Member Author

siemensikkema commented Jul 18, 2018 via email

@tanner0101
Copy link
Member

Moving to vapor/mysql-nio#42

@tanner0101 tanner0101 closed this Jul 22, 2020
@tanner0101 tanner0101 deleted the feature/geometry-support branch July 22, 2020 20:19
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

Successfully merging this pull request may close these issues.

None yet

3 participants