
Groundhog has support for PostgreSQL arrays and almost all operations on them. Check out the docs at http://hackage.haskell.org/package/groundhog-postgresql/docs/Database-Ground... Here is a tutorial for the library https://www.fpcomplete.com/user/lykahb/groundhog The array code looks like main = withPostgresqlConn connectionString . runDbConn $ do key <- insert $ MyData $ Array [1, 2, 3] results <- select $ arrayLength MyField 1 <. (5 :: Int) -- length of array dimension 1 is less than 5 liftIO $ print results On Fri, Dec 26, 2014 at 6:02 AM, Tom Ellis < tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
On Fri, Dec 26, 2014 at 02:36:07PM +1100, Riaan wrote:
So went back to HDBC. But now my queries are starting to get fairly long and I have been looking at libraries like Persistent with Esqualeto, HaskellDB and Groundhog to make my queries a little more composable and type safe.
Don't forget to look at Opaleye too :) It doesn't really have much support for arrays at the moment, but if you let me know what you want to do I'm happy to help you.
So to my question. Does anyone have experience with one of these
On Fri, Dec 26, 2014 at 10:52:46AM +0000, Tom Ellis wrote: libraries
in dealing with postgresql arrays
postgresql-simple has
instance (FromField a, Typeable a) => FromField (PGArray a)
Does that not do exactly what you want?
import Database.PostgreSQL.Simple (query_, ConnectInfo(..), connect, Only) import Database.PostgreSQL.Simple.Types (PGArray)
import Data.String (fromString)
connectInfo :: ConnectInfo connectInfo = ConnectInfo { connectHost = "localhost" , connectPort = 25433 , connectUser = "tom" , connectPassword = "tom" , connectDatabase = "opaleye_test" }
arrayQuery :: String arrayQuery = "select '{{1,2}, {3,4}}' :: integer[][]"
main :: IO () main = do conn <- connect connectInfo results <- query_ conn (fromString arrayQuery) :: IO [Only (PGArray (PGArray Int))] print results
-- Output -- -- ghci> main -- [Only {fromOnly = PGArray {fromPGArray = [PGArray {fromPGArray = [1,2]},PGArray {fromPGArray = [3,4]}]}}] _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Regards, Boris