git.iko.soy/rowtype-yoga/purescript-yoga-postgres
on main help sign in
Battle-test yoga-postgres in om-playground: 35/35 tests against live Postgres 15
commite0ff941b8c057571d973b67bce2039e4d864f660 authorMark <mark.eibes@gmail.com> dateMon 16 Feb 2026, 14:07 (7 months ago) parente200281
3 files changed+15−9
src/Yoga/Postgres/Schema.purs+9−4 test/EdgeCases.purs+2−1 test/Schema.purs+4−4
src/Yoga/Postgres/Schema.purs+9−4
@@ -1090,8 +1090,8 @@ else instance
10901090class AggregateReturnTypeC :: Symbol -> Type -> Type -> Constraint
10911091class AggregateReturnTypeC funcName argType returnType | funcName argType -> returnType
10921092
1093−instance AggregateReturnTypeC "COUNT" argType Int
1094−else instance AggregateReturnTypeC "count" argType Int
1093+instance AggregateReturnTypeC "COUNT" argType BigInt
1094+else instance AggregateReturnTypeC "count" argType BigInt
10951095else instance AggregateReturnTypeC "COALESCE" argType argType
10961096else instance AggregateReturnTypeC "coalesce" argType argType
10971097else instance
@@ -3346,17 +3346,22 @@ instance
33463346 <> paramsToArray (Proxy :: Proxy tail) rec
33473347
33483348namedParamRegex :: Regex.Regex
3349−namedParamRegex = case Regex.regex "\\$[a-zA-Z_][a-zA-Z0-9_]*" Regex.global of
3349+namedParamRegex = case Regex.regex "\\$[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_]+)?" Regex.global of
33503350 Right r -> r
33513351 Left _ -> unsafeCoerce unit
33523352
3353+stripCast :: String -> String
3354+stripCast s = case SCU.indexOf (Pattern "::") s of
3355+ Nothing -> s
3356+ Just i -> SCU.take i s
3357+
33533358replaceNamedParams :: Int -> Array { name :: String, value :: Foreign } -> String -> { sql :: String, values :: Array PG.PGValue }
33543359replaceNamedParams offset entries sql = do
33553360 let indexed = entries # mapWithIndex \i e -> { idx: offset + i + 1, name: e.name, value: e.value }
33563361 let replacements = indexed # foldl (\m e -> Map.insert ("$" <> e.name) ("$" <> show e.idx) m) Map.empty
33573362 let
33583363 sql' = Regex.replace' namedParamRegex
3359− ( \match _ -> case Map.lookup match replacements of
3364+ ( \match _ -> case Map.lookup (stripCast match) replacements of
33603365 Nothing -> match
33613366 Just v -> v
33623367 )
test/EdgeCases.purs+2−1
@@ -3,6 +3,7 @@ module Test.Postgres.EdgeCases where
33import Prelude
44
55import Data.Maybe (Maybe)
6+import JS.BigInt (BigInt)
67import Prim.Boolean (True)
78import Type.Function (type (#))
89import Type.Proxy (Proxy(..))
@@ -34,7 +35,7 @@ postsTable = Proxy
3435-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3536
3637havingMergesWhereParams
37− :: Q _ (name :: String, cnt :: Int) (age :: Int, minCount :: Int) _
38+ :: Q _ (name :: String, cnt :: BigInt) (age :: Int, minCount :: Int) _
3839havingMergesWhereParams = from usersTable
3940 # select @"name, COUNT(*) AS cnt"
4041 # where_ @"age > $age"
test/Schema.purs+4−4
@@ -440,7 +440,7 @@ typedGroupBy
440440typedGroupBy = from usersTable # select @"name" # groupBy @"name"
441441
442442typedCountStar
443− :: Q _ (name :: String, cnt :: Int) () _
443+ :: Q _ (name :: String, cnt :: BigInt) () _
444444typedCountStar = from usersTable
445445 # select @"name, COUNT(*) AS cnt"
446446 # groupBy @"name"
@@ -464,14 +464,14 @@ typedMinMax = from usersTable
464464 # groupBy @"name"
465465
466466typedHaving
467− :: Q _ (name :: String, cnt :: Int) (minCount :: Int) _
467+ :: Q _ (name :: String, cnt :: BigInt) (minCount :: Int) _
468468typedHaving = from usersTable
469469 # select @"name, COUNT(*) AS cnt"
470470 # groupBy @"name"
471471 # having @"COUNT(*) > $minCount"
472472
473473typedFullAggregate
474− :: Q _ (name :: String, cnt :: Int) (min :: Int) _
474+ :: Q _ (name :: String, cnt :: BigInt) (min :: Int) _
475475typedFullAggregate = from usersTable
476476 # select @"name, COUNT(*) AS cnt"
477477 # groupBy @"name"
@@ -480,7 +480,7 @@ typedFullAggregate = from usersTable
480480 # limit @"10"
481481
482482typedWhereGroupByHaving
483− :: Q _ (name :: String, cnt :: Int) (age :: Int, minCount :: Int) _
483+ :: Q _ (name :: String, cnt :: BigInt) (age :: Int, minCount :: Int) _
484484typedWhereGroupByHaving = from usersTable
485485 # select @"name, COUNT(*) AS cnt"
486486 # where_ @"age > $age"