git.iko.soy/rowtype-yoga/purescript-yoga-postgres
on main help sign in
commit44673e3d93b1ca5c603f39767d83f78034131da0 authorMark <mark.eibes@gmail.com> dateFri 13 Feb 2026, 14:17 (8 months ago) parent545833b
2 files changed+21−2
src/Yoga/Postgres/Schema.purs+18 test/Schema.purs+3−2
src/Yoga/Postgres/Schema.purs+18
@@ -33,6 +33,12 @@ data None
3333data Default :: Symbol -> Type
3434data Default a
3535
36+data DefaultInt :: Int -> Type
37+data DefaultInt a
38+
39+data DefaultBool :: Boolean -> Type
40+data DefaultBool a
41+
3642-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3743-- Nullability: inferred from Maybe
3844-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -89,6 +95,14 @@ instance RenderConstraint None where
8995instance Reflectable sym String => RenderConstraint (Default sym) where
9096 renderConstraint _ = "DEFAULT " <> reflectType (Proxy :: Proxy sym)
9197
98+instance Reflectable val Int => RenderConstraint (DefaultInt val) where
99+ renderConstraint _ = "DEFAULT " <> show (reflectType (Proxy :: Proxy val))
100+
101+instance Reflectable val Boolean => RenderConstraint (DefaultBool val) where
102+ renderConstraint _ =
103+ if reflectType (Proxy :: Proxy val) then "DEFAULT true"
104+ else "DEFAULT false"
105+
92106instance (RenderConstraint a, RenderConstraint b) => RenderConstraint (a /\ b) where
93107 renderConstraint _ = do
94108 let a = renderConstraint (Proxy :: Proxy a)
@@ -151,6 +165,10 @@ instance IsAutoGenerated AutoIncrement where
151165 isAutoGenerated _ = true
152166else instance IsAutoGenerated (Default a) where
153167 isAutoGenerated _ = true
168+else instance IsAutoGenerated (DefaultInt a) where
169+ isAutoGenerated _ = true
170+else instance IsAutoGenerated (DefaultBool a) where
171+ isAutoGenerated _ = true
154172else instance (IsAutoGenerated a, IsAutoGenerated b) => IsAutoGenerated (a /\ b) where
155173 isAutoGenerated _ = isAutoGenerated (Proxy :: Proxy a) || isAutoGenerated (Proxy :: Proxy b)
156174else instance IsAutoGenerated a where
test/Schema.purs+3−2
@@ -5,6 +5,7 @@ import Prelude
55import Data.Maybe (Maybe)
66import Data.String (contains, Pattern(..))
77import Data.Tuple.Nested (type (/\))
8+import Prim.Boolean (True)
89import Test.Spec (Spec, describe, it)
910import Test.Spec.Assertions (shouldEqual, shouldSatisfy)
1011import Yoga.Postgres.Schema
@@ -54,9 +55,9 @@ selectWhereSQL = selectWhereSQLFor @UsersTable @(id :: Int)
5455
5556type ConfigTable = Table "config"
5657 ( id :: Column Int (PrimaryKey /\ AutoIncrement)
57− , active :: Column Boolean (Default "true")
58+ , active :: Column Boolean (DefaultBool True)
5859 , role :: Column String (Default "'user'")
59− , score :: Column Int (Default "0")
60+ , score :: Column Int (DefaultInt 0)
6061 )
6162
6263configDDL :: String