I have created a struct to store spatial types and I have created a scan function to help query rows in my database. I am having issues inserting this type.
I can insert data using the following sql;
INSERT INTO 'table' ('spot') VALUES (GeomFromText('POINT(10 10)'));
If I use Value interface in database/sql/driver;
type Value interface{}
Value is a value that drivers must be able to handle. It is either nil or an instance of one of these types:
int64
float64
bool
[]byte
string [*] everywhere except from Rows.Next.
time.Time
And use this code;
func (p Point) Value() (driver.Value, error) {
return "GeomFromText('" + p.ToWKT() + "')", nil
}
I end up with the following sql statement going to the database;
INSERT INTO 'table' ('spot') VALUES ('GeomFromText('POINT(10 10)')');
The issue being that the function GeomFromText is in quotes. Is there a way to avoid this scenario? I am using gorm and trying to keep raw sql queries to a minimum.
The mysql type being used on the database end is a point.
limit
orMy Column
orthis-thing
– DrewGeomFromText
in the query and have yourPoint
Value
method returnp.ToWKT()
? – jmaloneydb.Exec("INSERT INTO 'table' ('spot') VALUES (GeomFromText($1))", p.ToWKT())
will work however I am trying to avoid using raw sql queries usch as that. I know that the reason my code is failing is becausefunc (p Point) Value()
is returning a string and my MySQL function is being placed in quotes. Is there a way of using this interface and have only part of the string placed in quotes? – devfubar