esqueleto-postgis
postgis bindings for esqueleto.
https://github.com/jappeace/esqueleto-postgis#readme
| Stackage Nightly 2026-02-20: | 3.0.0 |
| Latest on Hackage: | 3.0.0 |
esqueleto-postgis-3.0.0@sha256:21c2ed29b8ec54712497760c455603952f6a192cef50065846597e00cd4a2bd6,3212Module documentation for 3.0.0
- Database
Show me the place where space is not.
Implement (partial) postgis functionality for esqueleto. https://postgis.net/
uses wkt-geom to get a persistent instance, then maps that to a custom datatype ‘PostgisGeometry’ which is valid for roundtripping.
Then the esqueleto combinators are defined around this datatype.
Tutorial
most linux distributions support this out of the box. nixos needs some special care:
services.postgresql = {
enable = true;
package = (pkgs.postgresql_12.withPackages (p: [ p.postgis ]));
};
For mac you’ve to install postgis.
brew install postgis
Make sure to enable to postgis extension on your database (it’s activated per database):
CREATE EXTENSION postgis;
you can specify some posgis geometry, use the point to nidicate dimensions, pointxy = 2 dimensions pointxyz = 3, pointxyzm = 4. The library forces you to work in the same dimensions.
You can specify a table with the custom datatype, which will have geometry as sql type:
share
[mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistUpperCase|
Unit sql=unit
geom (PostgisGeometry PointXY)
deriving Eq Show
|]
then you can simply query on tat datatype:
test = testCase ("it finds the one unit with st_contains") $ do
result <- runDB $ do
_ <- insert $
Unit
{ unitGeom = Polygon $ makePolygon (PointXY 0 0) (PointXY 0 2) (PointXY 2 2) $ Seq.fromList [(PointXY 2 0)]
}
selectOne $ do
unit <- from $ table @Unit
where_ $ unit ^. UnitGeom `st_contains` (val $ Point (PointXY 1 1))
pure countRows
-- expectation, the result should be 1
unValue <$> result @?= (Just (1 :: Int)),
Contributing
contributions are welcome. There are still many bindings missing!
Hacking
Tools
Enter the nix shell.
nix develop
You can checkout the makefile to see what’s available:
cat makefile
Running
make run
Fast filewatch which runs tests
make ghcid
Changes
Change log for esqueleto-postgis project
Version 3.0.0
- add spatial type, split up postgis from geoemetry. this will allow us to deal with curveture of earth and other weird SRID’s: consider:
converge=# SELECT ST_Distance(
ST_MakePoint(-118.24, 34.05)::geometry, -- LA
ST_MakePoint(-74.00, 40.71)::geometry -- NYC
) as distance_in_km;
distance_in_km
-------------------
44.73849796316367
(1 row)
converge=# SELECT ST_Distance(
ST_MakePoint(-118.24, 34.05)::geography,
ST_MakePoint(-74.00, 40.71)::geography
) / 1000 as distance_in_km;
distance_in_km
--------------------
3944.7358246490203
(1 row)
The change is mostly backward compatible, but I deleted some instances I didn’t want to solve. Furthermore the postgis type is arguably a bit more complicated now.
I did have some minor breakage in the test suite on st_unions:
- pure $ st_unions (val (Polygon $ makePolygon (PointXY 0 0) (PointXY 0 2) (PointXY 2 2) $ Seq.fromList [(PointXY 2 0)])) $
+ pure $ st_unions @'Geometry (val (Polygon $ makePolygon (PointXY 0 0) (PointXY 0 2) (PointXY 2 2) $ Seq.fromList [(PointXY 2 0)])) $
You may need to tell the compiler weather to use geometry or geography. But then it’ll happen correct within the database as well.
We don’t allow mixing of the two.
Version 2.2.0
- add st_dwithin to find stuf within a range
Version 2.1.0
- add st_unions
Version 2.0.1
- drop haskell works hedghog dependency
Version 2.0.0
- Hide irrelevant modules
- delete hex module, use base16 hex approach instead.
- Much better docs that explain what’s going on.
Version 1.2.0
- re-export point, less annoying to use.
- adopt wkt-geom package and put it in as a submodule,
original library doesn’t appear to be maintained.
this way we’re a step closer to stackage.
- got rid of the internal convention, it goes against pvp. If we want some specialized usage package I should split off a core package instead. For now I don’t care I don’t think I’m not changing those functions anyway.
- also ported over the test suite
- swap out bytestring-base16 for base16, which appears maintained.
Version 1.1.0
- Add st_union
- add getPoitns to escape the postgis geometry more easily.
- bump bounds
Version 1.0.1
- fix insane bounds by cabal genbounds. I think this was caused due to running it from the flake which takes a bunch of outdated packages from stackage.
Version 1.0.0
- add st_contains
- add st_intersects
- add st_point
- add custom datatype to map to persistent.
- bunch of roundtrip tests and sanity tests for added functions
Version 0.0.0
import template.