Add getColumnTable function
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
module Database.PostgreSQL.OpiumSpec (spec) where
|
||||
|
||||
import Data.Proxy (Proxy (..))
|
||||
import Data.Text (Text)
|
||||
import Database.PostgreSQL.LibPQ (Connection)
|
||||
import GHC.Generics (Generic)
|
||||
@@ -31,6 +32,21 @@ isLeft _ = False
|
||||
|
||||
spec :: SpecWith Connection
|
||||
spec = do
|
||||
describe "getColumnTable" $ do
|
||||
it "Gets the column table for a result" $ \conn -> do
|
||||
Just result <- LibPQ.execParams conn "SELECT name, age FROM person" [] LibPQ.Text
|
||||
columnTable <- Opium.getColumnTable (Proxy :: Proxy Person) result
|
||||
columnTable `shouldBe` [0, 1]
|
||||
|
||||
it "Gets the numbers right for funky configurations" $ \conn -> do
|
||||
Just result0 <- LibPQ.execParams conn "SELECT age, name FROM person" [] LibPQ.Text
|
||||
columnTable0 <- Opium.getColumnTable @Person Proxy result0
|
||||
columnTable0 `shouldBe` [1, 0]
|
||||
|
||||
Just result1 <- LibPQ.execParams conn "SELECT 0 a, 1 b, 2 c, age, 4 d, name FROM person" [] LibPQ.Text
|
||||
columnTable1 <- Opium.getColumnTable @Person Proxy result1
|
||||
columnTable1 `shouldBe` [5, 3]
|
||||
|
||||
describe "fromRow" $ do
|
||||
it "decodes rows in a Result" $ \conn -> do
|
||||
Just result <- LibPQ.execParams conn "SELECT * FROM person" [] LibPQ.Text
|
||||
|
||||
Reference in New Issue
Block a user