import (
"context"
"github.com/paulmach/orb"
"github.com/si3nloong/sqlike/v2/actions"
"github.com/si3nloong/sqlike/v2/sql/expr"
)
var o struct {
Dist1 float64
Dist2 float64
Text string
}
if err := client.Database("sqlike")
Table("Locations").
FindOne(
context.Background(),
actions.FindOne().
Select(
expr.As(expr.ST_Distance(expr.Column("Point"), orb.Point{20, 10}), "dist"),
expr.ST_Distance(
expr.ST_GeomFromText(orb.Point{1, 3}, 4326),
expr.ST_GeomFromText(orb.Point{4, 18}, 4326),
),
expr.ST_AsText(expr.Column("Point")),
).
Where(
expr.Equal("ID", 1),
expr.ST_Equals(orb.Point{20, 10}, orb.Point{20, 10}),
).
OrderBy(
expr.Desc("dist"),
),
).Scan(&o.Dist1, &o.Dist2, &o.Text); err != nil {
panic(err)
}