Add quick start section to readme

This commit is contained in:
2023-09-16 19:52:35 +02:00
parent d54cf6ea7f
commit 423f28f0a2
3 changed files with 67 additions and 3 deletions
+12
View File
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
@@ -38,6 +39,13 @@ data ManyFields = ManyFields
instance Opium.FromRow ManyFields where
data ScoreByAge = ScoreByAge
{ m :: Double
, t :: Double
} deriving (Eq, Generic, Show)
instance Opium.FromRow ScoreByAge where
isLeft :: Either a b -> Bool
isLeft (Left _) = True
isLeft _ = False
@@ -125,3 +133,7 @@ spec = do
it "Fails for the wrong column type" $ \conn -> do
rows <- Opium.fetch_ @Person conn "SELECT 'quby' AS name, 'indeterminate' AS age"
rows `shouldBe` Left (Opium.ErrorInvalidOid "age" $ LibPQ.Oid 25)
it "Works for the readme regression example" $ \conn -> do
rows <- Opium.fetch_ @ScoreByAge conn "SELECT regr_intercept(score, age) AS t, regr_slope(score, age) AS m FROM person"
rows `shouldSatisfy` \case { (Right [ScoreByAge _ _]) -> True; _ -> False }