git.iko.soy/rowtype-yoga/purescript-yoga-postgres
on main help sign in
Use PGUUID wrapping Data.UUID.UUID, depend on purescript-uuid fork
commite0cad80cedac367619e31db8c2b60b214812b23f authorMark <mark.eibes@gmail.com> dateSun 15 Feb 2026, 23:52 (8 months ago) parent260844b
4 files changed+35−14
spago.lock+17−1 spago.yaml+5−1 src/Yoga/Postgres/Schema.purs+10−9 test/Schema.purs+3−3
spago.lock+17−1
@@ -50,6 +50,9 @@
5050 {
5151 "unsafe-coerce": ">=6.0.0 <7.0.0"
5252 },
53+ {
54+ "uuid": "*"
55+ },
5356 {
5457 "yoga-json": ">=5.2.0 <6.0.0"
5558 },
@@ -79,7 +82,11 @@
7982 }
8083 }
8184 },
82− "extra_packages": {}
85+ "extra_packages": {
86+ "uuid": {
87+ "path": "../purescript-uuid"
88+ }
89+ }
8390 },
8491 "packages": {
8592 "aff": {
@@ -916,6 +923,15 @@
916923 "integrity": "sha256-0L1QsaY20OILjfU5TV72d3U/tSjhmL9hJ32WMp857Lk=",
917924 "dependencies": []
918925 },
926+ "uuid": {
927+ "type": "local",
928+ "path": "../purescript-uuid",
929+ "dependencies": [
930+ "effect",
931+ "maybe",
932+ "prelude"
933+ ]
934+ },
919935 "variant": {
920936 "type": "registry",
921937 "version": "8.0.0",
spago.yaml+5−1
@@ -1,4 +1,7 @@
1−workspace: {}
1+workspace:
2+ extraPackages:
3+ uuid:
4+ path: ../purescript-uuid
25
36package:
47 name: yoga-postgres
@@ -24,6 +27,7 @@ package:
2427 - ordered-collections: ">=3.2.0 <4.0.0"
2528 - prelude: ">=6.0.2 <7.0.0"
2629 - unsafe-coerce: ">=6.0.0 <7.0.0"
30+ - uuid: "*"
2731 - yoga-json: ">=5.2.0 <6.0.0"
2832 - yoga-sql-types: ">=0.1.0 <0.2.0"
2933 test:
src/Yoga/Postgres/Schema.purs+10−9
@@ -9,6 +9,7 @@ import Data.JSDate as JSDate
99import Data.Maybe (Maybe(..))
1010import Data.Newtype (class Newtype)
1111import Data.Nullable (toNullable)
12+import Data.UUID (UUID)
1213import JS.BigInt (BigInt)
1314import Unsafe.Coerce (unsafeCoerce)
1415import Data.Reflectable (class Reflectable, reflectType)
@@ -82,20 +83,20 @@ instance ReadForeign Jsonb where
8283 readImpl = pure <<< Jsonb
8384
8485-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
85−-- UUID type for Postgres
86+-- PGUUID: newtype over Data.UUID.UUID for Postgres integration
8687-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
8788
88−newtype UUID = UUID String
89+newtype PGUUID = PGUUID UUID
8990
90−derive instance Newtype UUID _
91−derive newtype instance Eq UUID
92−derive newtype instance Ord UUID
93−derive newtype instance Show UUID
91+derive instance Newtype PGUUID _
92+derive newtype instance Eq PGUUID
93+derive newtype instance Ord PGUUID
94+derive newtype instance Show PGUUID
9495
95−instance ReadForeign UUID where
96+instance ReadForeign PGUUID where
9697 readImpl f = do
9798 s :: String <- readImpl f
98− pure (UUID s)
99+ pure (unsafeCoerce s)
99100
100101-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
101102-- Nullability: inferred from Maybe
@@ -150,7 +151,7 @@ instance PGTypeName DateTime where
150151instance PGTypeName BigInt where
151152 pgTypeName _ = "BIGINT"
152153
153−instance PGTypeName UUID where
154+instance PGTypeName PGUUID where
154155 pgTypeName _ = "UUID"
155156
156157instance PGTypeName Jsonb where
test/Schema.purs+3−3
@@ -648,7 +648,7 @@ typedCoalesceSelect = from usersTable
648648-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
649649
650650type SessionsTable = Table "sessions"
651− ( id :: UUID # PrimaryKey # DefaultExpr "gen_random_uuid()"
651+ ( id :: PGUUID # PrimaryKey # DefaultExpr "gen_random_uuid()"
652652 , user_id :: Int # ForeignKey "users" References "id"
653653 , token :: String # Unique
654654 , created_at :: DateTime # DefaultExpr "now()"
@@ -664,11 +664,11 @@ sessionsInsertSQL :: String
664664sessionsInsertSQL = insertSQLFor @SessionsTable
665665
666666typedSessionSelect
667− :: Q _ (id :: UUID, token :: String) () _
667+ :: Q _ (id :: PGUUID, token :: String) () _
668668typedSessionSelect = from sessionsTable # select @"id, token"
669669
670670typedSessionWhere
671− :: Q _ (id :: UUID, token :: String, user_id :: Int, created_at :: DateTime) (userId :: Int) _
671+ :: Q _ (id :: PGUUID, token :: String, user_id :: Int, created_at :: DateTime) (userId :: Int) _
672672typedSessionWhere = from sessionsTable # selectAll # where_ @"user_id = $userId"
673673
674674typedSessionInsert