Skip to content

Commit

Permalink
Fix the query.
Browse files Browse the repository at this point in the history
  • Loading branch information
psibi committed Sep 27, 2016
1 parent f7f1579 commit 4fd2100
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion snippets/Find-Nearby-Locations.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ data GeoLocation = GeoLocation
longitude :: Double
} deriving (Show, Eq, Ord)

-- Note that lat, lon inside the query refers to the column name
findNearbyMarkers :: (MonadIO m) => GeoLocation -> ReaderT SqlBackend m [(Single String, Single Double)]
findNearbyMarkers (GeoLocation lat lon) = rawSql "SELECT name, ( 3959 * acos( cos( radians(37) ) * cos( radians( ? ) ) * cos( radians( ? ) - radians(-122) ) + sin( radians(37) ) * sin( radians( ? ) ) ) ) AS distance FROM markers" [PersistDouble lat, PersistDouble lon, PersistDouble lat]
findNearbyMarkers (GeoLocation lat lon) = rawSql "SELECT name, ( 3959 * acos( cos( radians(?) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(?) ) + sin( radians(?) ) * sin( radians( lat ) ) ) ) AS distance FROM markers" [PersistDouble lat, PersistDouble lon, PersistDouble lat]

main :: IO ()
main = runStderrLoggingT $ withPostgresqlPool connStr 10 $ liftSqlPersistMPool $ do
Expand Down

0 comments on commit 4fd2100

Please sign in to comment.