esqueleto-postgis 4.0.1 → 4.0.2
raw patch · 4 files changed
+32/−7 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Database.Esqueleto.Postgis: st_point :: forall (spatialType :: SpatialType). SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXY))
+ Database.Esqueleto.Postgis: st_point :: forall (spatialType :: SpatialType). HasPgType spatialType => SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXY))
- Database.Esqueleto.Postgis: st_point_xyz :: forall (spatialType :: SpatialType). SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZ))
+ Database.Esqueleto.Postgis: st_point_xyz :: forall (spatialType :: SpatialType). HasPgType spatialType => SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZ))
- Database.Esqueleto.Postgis: st_point_xyzm :: forall (spatialType :: SpatialType). SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZM))
+ Database.Esqueleto.Postgis: st_point_xyzm :: forall (spatialType :: SpatialType). HasPgType spatialType => SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZM))
Files
- Changelog.md +5/−0
- esqueleto-postgis.cabal +1/−1
- src/Database/Esqueleto/Postgis.hs +12/−6
- test/Test.hs +14/−0
Changelog.md view
@@ -1,5 +1,10 @@ # Change log for esqueleto-postgis project +## Version 4.0.2 ++ fix bug where st_point and friends did not respect spatialType.+ solved it by always casting them to whatever the user specified.+ Added tests for this as well.+ ## Version 4.0.1 + Add notes on topology, may save some people a lot of time. + Remove flake, use npins
esqueleto-postgis.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: esqueleto-postgis-version: 4.0.1+version: 4.0.2 homepage: https://github.com/jappeace/esqueleto-postgis#readme bug-reports: https://github.com/jappeace/esqueleto-postgis/issues author: Jappie Klooster
src/Database/Esqueleto/Postgis.hs view
@@ -429,12 +429,18 @@ point_v :: HasPgType spatialType => Double -> Double -> SqlExpr (Value (Postgis spatialType PointXY)) point_v = fmap val . point -st_point :: SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXY))-st_point a b = unsafeSqlFunction "ST_POINT" (a, b)+st_point :: forall spatialType . HasPgType spatialType => SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXY))+st_point a b = unsafeSqlCastAs castAs $ unsafeSqlFunction "ST_POINT" (a, b)+ where+ castAs = pgType $ Proxy @spatialType -st_point_xyz :: SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZ))-st_point_xyz a b c = unsafeSqlFunction "ST_POINT" (a, b, c) -st_point_xyzm :: SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZM))-st_point_xyzm a b c m = unsafeSqlFunction "ST_POINT" (a, b, c, m)+st_point_xyz :: forall spatialType . HasPgType spatialType => SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZ))+st_point_xyz a b c = unsafeSqlCastAs castAs $ unsafeSqlFunction "ST_POINT" (a, b, c)+ where+ castAs = pgType $ Proxy @spatialType +st_point_xyzm :: forall spatialType . HasPgType spatialType => SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZM))+st_point_xyzm a b c m = unsafeSqlCastAs castAs $ unsafeSqlFunction "ST_POINT" (a, b, c, m)+ where+ castAs = pgType $ Proxy @spatialType
test/Test.hs view
@@ -264,6 +264,20 @@ (point_v (-118.24) 34.05) -- LA (point_v (-74.00) 40.71) -- NYC unValue <$> result @?= (Just 3_944_735.82464902), -- correct! (in m)+ testCase ("st_distance@geom can distance PG and then get out some Haskell, doing it wrong with geometry") $ do+ result <- runDB $ do+ selectOne $+ pure $ st_distance @'Geometry+ (st_point (val (-118.24)) (val 34.05)) -- LA+ (st_point (val (-74.00)) (val 40.71)) -- NYC+ unValue <$> result @?= (Just 44.73849796316367), -- not 44km, but geometry does that+ testCase ("st_distance@geography can distance PG and then get out some Haskell, doing it wrong with geometry") $ do+ result <- runDB $ do+ selectOne $+ pure $ st_distance @'Geography+ (st_point (val (-118.24)) (val 34.05)) -- LA+ (st_point (val (-74.00)) (val 40.71)) -- NYC+ unValue <$> result @?= (Just 3_944_735.82464902), -- correct! (in m) testCase ("see if we can get just the units in the polygons") $ do result <- runDB $ do _ <-