Slightly change readme example code

This commit is contained in:
Paul Brinkmeier 2024-07-03 11:22:18 +02:00
parent 97e5d9e61c
commit 6d3b1e660a

View File

@ -34,7 +34,7 @@ data User = User
instance Opium.FromRow User where instance Opium.FromRow User where
getUsers :: Connection -> IO (Either Opium.Error [User]) getUsers :: Connection -> IO (Either Opium.Error [User])
getUsers conn = Opium.fetch_ "SELECT * FROM user" conn getUsers = Opium.fetch_ "SELECT * FROM user"
``` ```
The `Opium.FromRow` instance is implemented generically for all product types ("records"). It looks up the field name in the query result and decodes the column value using `Opium.FromField`. The `Opium.FromRow` instance is implemented generically for all product types ("records"). It looks up the field name in the query result and decodes the column value using `Opium.FromField`.
@ -51,7 +51,7 @@ instance Opium.FromRow ScoreByAge where
getScoreByAge :: Connection -> IO ScoreByAge getScoreByAge :: Connection -> IO ScoreByAge
getScoreByAge conn = do getScoreByAge conn = do
let query = "SELECT regr_intercept(score, age) AS t, regr_slope(score, age) AS m FROM user" let query = "SELECT regr_intercept(score, age) AS t, regr_slope(score, age) AS m FROM user"
Right [x] <- Opium.fetch_ query conn Right (Identity x) <- Opium.fetch_ query conn
pure x pure x
``` ```