Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE ScopedTypeVariables #-}
- {-# LANGUAGE ConstraintKinds #-}
- {-# LANGUAGE FlexibleInstances #-}
- module Example.Example15 where
- import Control.Exception.Safe (SomeException, catch)
- -- my library
- import DataBase.MySQLX.NodeSession
- import DataBase.MySQLX.ResultSet
- import DataBase.MySQLX.Statement
- import qualified Data.ByteString.Lazy as BL
- import qualified Data.Sequence as Seq
- import Data.Maybe
- import Data.Geometry.Geos.Geometry
- import Data.Geometry.Geos.Serialize
- import Data.Geometry.Geos.Types
- {-
- create table points_tbl (`id` int unsigned not null auto_increment, `location` Point not null, primary key(`id`));
- insert into points_tbl (location) values (point(1,1));
- mysql-sql> select st_astext(location) from points_tbl;
- +---------------------+
- | st_astext(location) |
- +---------------------+
- | POINT(1 1) |
- +---------------------+
- 1 row in set (0.01 sec)
- -}
- data Geo = Geo {
- p :: Geometry Point
- } deriving Show
- geo:: RowFrom Geo
- geo= Geo <$> colVal
- getColGeoPoint :: Row -> Int -> Geometry Point
- getColGeoPoint row idx = getColGeoPoint' $ Seq.index row idx
- getColGeoPoint' :: BL.ByteString -> Geometry Point
- getColGeoPoint' x = ensurePoint $ fromJust $ readWkb (BL.toStrict $ BL.drop 4 $ getColByteString' x)
- getColGeoPoint'' :: BL.ByteString -> Geometry Point
- getColGeoPoint'' x = ensurePoint $ fromJust $ readWkb (BL.toStrict $ getColByteString' x)
- instance ColumnValuable (Geometry Point) where toColVal' = getColGeoPoint'
- example15 :: IO ()
- example15 = do
- nodeSess <- openNodeSession $ defaultNodeSesssionInfo {database = "x_protocol_test", user = "root", password="root", port=8000}
- catch ( do
- result <- executeRawSql "select location from points_tbl" nodeSess
- print $ rowFrom geo $ head result
- ) (\(e::SomeException) -> print e)
- closeNodeSession nodeSess
- {-
- *Example.Example15> example15
- Geo {p = PointGeometry (Point (Coordinate2 1.0 1.0)) Nothing}
- *Example.Example15>
- -}
Add Comment
Please, Sign In to add comment