paulmach / orb

Types and utilities for working with 2d geometry in Golang
MIT License
910 stars 103 forks source link

Why have wkb.Scanner() and wkb.Value() functions? #25

Closed Robbie-Perry closed 5 years ago

Robbie-Perry commented 5 years ago

I've noticed that the different geometric types don't have Scan() and Value() directly implemented on them, but rather they are implemented by their wrappers.

This is fine if you are able to first call wkb.Scanner() and wkb.Value() before calling the database functions. However, if you are using an orm-type library that automatically calls Scan() and Value() behind the scenes, such as gorm, then this library won't work.

I'm proposing keeping the scanner and valuer wrappers for those who need them, but also implementing Scan() and Value() directly onto each type, for those who don't have the luxury of wrapping their fields prior.

paulmach commented 5 years ago

I left it out for a few reasons:

  1. keep the "core" package small. To add those methods the files encoding/wkb would need to be moved to the root to avoid a circular dependancy.
  2. I'm pretty sure that Postgres requires an ST_AsBinary in the query. Mysql you don't. When I checked, I couldn't figure how to wrap the column names in a function with the orms in golang.

So that's why they're not there. Are you using mysql? Did gorm add the ability to wrap functions in a column name?

Robbie-Perry commented 5 years ago

Makes sense. I'm using Postgres. Gorm doesn't allow the automatic function wrap, so I needed to create my own types and Scan()/Value() functions anyways. I ended up just getting the hex value, converting to/from binary, and adding/removing the bytes representing the projection.

t2wu commented 4 years ago

@Robbie-Perry Can you give me a hint on how to do it?