git.iko.soy/rowtype-yoga/purescript-yoga-postgres
on main help sign in
Integration tests: real queries for UUID, PGDate, PGTime, Point, TSVector against Postgres
commitd07f181beeb0bb26557c6b65afc2480aa388aff1 authorMark <mark.eibes@gmail.com> dateMon 16 Feb 2026, 00:42 (8 months ago) parent83fd46d
1 file changed+19−10
src/Yoga/Postgres/Schema.purs+19−10
src/Yoga/Postgres/Schema.purs+19−10
@@ -20,10 +20,13 @@ import Data.String.Regex (Regex) as Regex
2020import Data.String.Regex.Flags (global) as Regex
2121import Control.Monad.Except (except, runExcept)
2222import Data.Either (Either(..), note)
23+import Data.List.Types (NonEmptyList)
24+import Data.Traversable (traverse)
25+import Effect.Exception (error) as Exception
2326import Data.Map as Map
2427import Data.Symbol (class IsSymbol, reflectSymbol)
2528import Type.Function (type (#))
26−import Effect.Aff (Aff)
29+import Effect.Aff (Aff, throwError)
2730import Foreign (Foreign, ForeignError(..), unsafeToForeign)
2831import Prim.Boolean (True, False)
2932import Prim.Row (class Cons, class Lacks, class Union, class Nub) as Row
@@ -3346,7 +3349,9 @@ runQuery conn params (Q q) = do
33463349 let { sql, values } = replaceNamedParams (Array.length q.values) entries q.sql
33473350 let allValues = q.values <> values
33483351 result <- PG.query (PG.SQL sql) allValues conn
3349− pure (unsafeDecodeRows result.rows)
3352+ case decodeRows result.rows of
3353+ Left errs -> throwError (Exception.error ("Row decode failed: " <> show errs))
3354+ Right rows -> pure rows
33503355
33513356runQueryOne
33523357 :: forall tables result params paramsRL stage
@@ -3362,7 +3367,11 @@ runQueryOne conn params (Q q) = do
33623367 let { sql, values } = replaceNamedParams (Array.length q.values) entries q.sql
33633368 let allValues = q.values <> values
33643369 result <- PG.queryOne (PG.SQL sql) allValues conn
3365− pure (result <#> unsafeDecodeRow)
3370+ case result of
3371+ Nothing -> pure Nothing
3372+ Just row -> case decodeRow row of
3373+ Left errs -> throwError (Exception.error ("Row decode failed: " <> show errs))
3374+ Right a -> pure (Just a)
33663375
33673376runExecute
33683377 :: forall tables params paramsRL stage
@@ -3394,7 +3403,9 @@ runQueryTx txn params (Q q) = do
33943403 let { sql, values } = replaceNamedParams (Array.length q.values) entries q.sql
33953404 let allValues = q.values <> values
33963405 result <- PG.txQuery (PG.SQL sql) allValues txn
3397− pure (unsafeDecodeRows result.rows)
3406+ case decodeRows result.rows of
3407+ Left errs -> throwError (Exception.error ("Row decode failed: " <> show errs))
3408+ Right rows -> pure rows
33983409
33993410runExecuteTx
34003411 :: forall tables params paramsRL stage
@@ -3410,10 +3421,8 @@ runExecuteTx txn params (Q q) = do
34103421 let allValues = q.values <> values
34113422 PG.txExecute (PG.SQL sql) allValues txn
34123423
3413−unsafeDecodeRows :: forall a. ReadForeign a => Array Foreign -> Array a
3414−unsafeDecodeRows = map unsafeDecodeRow
3424+decodeRows :: forall a. ReadForeign a => Array Foreign -> Either (NonEmptyList ForeignError) (Array a)
3425+decodeRows = traverse (readImpl >>> runExcept)
34153426
3416−unsafeDecodeRow :: forall a. ReadForeign a => Foreign -> a
3417−unsafeDecodeRow f = case runExcept (readImpl f) of
3418− Left _ -> unsafeCoerce unit
3419− Right a -> a
3427+decodeRow :: forall a. ReadForeign a => Foreign -> Either (NonEmptyList ForeignError) a
3428+decodeRow = readImpl >>> runExcept