git.iko.soy/rowtype-yoga/purescript-yoga-postgres
on main help sign in
Add lowercase SQL keyword instances to FlushWhereWord
commit5135b612122d9bbb399f90be1e93e59781ebb856 authorMark <mark.eibes@gmail.com> dateSat 14 Feb 2026, 00:14 (8 months ago) parent443f054
3 files changed+169−115
spago.lock+115−62 spago.yaml−1 src/Yoga/Postgres/Client.purs+54−52
spago.lock+115−62
@@ -53,12 +53,69 @@
5353 {
5454 "yoga-json": ">=5.2.0 <6.0.0"
5555 },
56− {
57− "yoga-om": ">=1.2.2 <2.0.0"
58− },
5956 {
6057 "yoga-sql-types": ">=0.1.0 <0.2.0"
6158 }
59+ ],
60+ "build_plan": [
61+ "aff",
62+ "arrays",
63+ "bifunctors",
64+ "catenable-lists",
65+ "const",
66+ "contravariant",
67+ "control",
68+ "datetime",
69+ "distributive",
70+ "effect",
71+ "either",
72+ "enums",
73+ "exceptions",
74+ "exists",
75+ "foldable-traversable",
76+ "foreign",
77+ "foreign-object",
78+ "free",
79+ "functions",
80+ "functors",
81+ "gen",
82+ "heterogeneous",
83+ "identity",
84+ "integers",
85+ "invariant",
86+ "js-bigints",
87+ "js-date",
88+ "js-promise",
89+ "js-promise-aff",
90+ "lazy",
91+ "lists",
92+ "maybe",
93+ "newtype",
94+ "nonempty",
95+ "nullable",
96+ "numbers",
97+ "ordered-collections",
98+ "orders",
99+ "parallel",
100+ "partial",
101+ "prelude",
102+ "profunctor",
103+ "record",
104+ "refs",
105+ "safe-coerce",
106+ "st",
107+ "strings",
108+ "tailrec",
109+ "transformers",
110+ "tuples",
111+ "type-equality",
112+ "typelevel-prelude",
113+ "unfoldable",
114+ "unsafe-coerce",
115+ "variant",
116+ "yoga-json",
117+ "yoga-sql-types",
118+ "yoga-tree"
62119 ]
63120 },
64121 "test": {
@@ -78,6 +135,61 @@
78135 {
79136 "yoga-test-docker": ">=0.1.0 <1.0.0"
80137 }
138+ ],
139+ "build_plan": [
140+ "aff",
141+ "ansi",
142+ "arrays",
143+ "avar",
144+ "bifunctors",
145+ "catenable-lists",
146+ "console",
147+ "const",
148+ "contravariant",
149+ "control",
150+ "datetime",
151+ "distributive",
152+ "effect",
153+ "either",
154+ "enums",
155+ "exceptions",
156+ "exists",
157+ "foldable-traversable",
158+ "fork",
159+ "free",
160+ "functions",
161+ "functors",
162+ "gen",
163+ "identity",
164+ "integers",
165+ "invariant",
166+ "lazy",
167+ "lists",
168+ "maybe",
169+ "mmorph",
170+ "newtype",
171+ "nonempty",
172+ "now",
173+ "numbers",
174+ "ordered-collections",
175+ "orders",
176+ "parallel",
177+ "partial",
178+ "pipes",
179+ "prelude",
180+ "profunctor",
181+ "refs",
182+ "safe-coerce",
183+ "spec",
184+ "st",
185+ "strings",
186+ "tailrec",
187+ "transformers",
188+ "tuples",
189+ "type-equality",
190+ "unfoldable",
191+ "unsafe-coerce",
192+ "yoga-test-docker"
81193 ]
82194 }
83195 }
@@ -753,19 +865,6 @@
753865 "unsafe-coerce"
754866 ]
755867 },
756− "record-studio": {
757− "type": "registry",
758− "version": "1.0.4",
759− "integrity": "sha256-CRnFvSXpDDzio+buibUxFU9zPZDd7/lzrYC1Ya3FuIw=",
760− "dependencies": [
761− "heterogeneous",
762− "lists",
763− "prelude",
764− "record",
765− "typelevel-prelude",
766− "unsafe-coerce"
767− ]
768− },
769868 "refs": {
770869 "type": "registry",
771870 "version": "6.0.0",
@@ -914,23 +1013,6 @@
9141013 "type-equality"
9151014 ]
9161015 },
917− "uncurried-transformers": {
918− "type": "registry",
919− "version": "1.1.0",
920− "integrity": "sha256-AqqBMzVLzozVoDorE3QcVVRDkLd7O3624mRHCDnPhaI=",
921− "dependencies": [
922− "control",
923− "effect",
924− "either",
925− "functions",
926− "identity",
927− "prelude",
928− "safe-coerce",
929− "tailrec",
930− "transformers",
931− "tuples"
932− ]
933− },
9341016 "unfoldable": {
9351017 "type": "registry",
9361018 "version": "6.0.0",
@@ -1004,35 +1086,6 @@
10041086 "yoga-tree"
10051087 ]
10061088 },
1007− "yoga-om": {
1008− "type": "registry",
1009− "version": "1.2.2",
1010− "integrity": "sha256-uDV3/o8mUOTIgSEQFqIATPyladzL8BcjURvfS901hgI=",
1011− "dependencies": [
1012− "aff",
1013− "avar",
1014− "console",
1015− "control",
1016− "datetime",
1017− "effect",
1018− "either",
1019− "exceptions",
1020− "functions",
1021− "maybe",
1022− "newtype",
1023− "parallel",
1024− "prelude",
1025− "record",
1026− "record-studio",
1027− "tailrec",
1028− "transformers",
1029− "tuples",
1030− "typelevel-prelude",
1031− "uncurried-transformers",
1032− "unsafe-coerce",
1033− "variant"
1034− ]
1035− },
10361089 "yoga-sql-types": {
10371090 "type": "registry",
10381091 "version": "0.1.0",
spago.yaml−1
@@ -25,7 +25,6 @@ package:
2525 - prelude: ">=6.0.2 <7.0.0"
2626 - unsafe-coerce: ">=6.0.0 <7.0.0"
2727 - yoga-json: ">=5.2.0 <6.0.0"
28− - yoga-om: ">=1.2.2 <2.0.0"
2928 - yoga-sql-types: ">=0.1.0 <0.2.0"
3029 test:
3130 main: Test.Postgres.Main
src/Yoga/Postgres/Client.purs+54−52
@@ -5,6 +5,7 @@ import Prelude
55import Data.Array (intercalate, mapWithIndex)
66import Data.Maybe (Maybe)
77import Data.Symbol (class IsSymbol, reflectSymbol)
8+import Effect.Aff (Aff)
89import Prim.Boolean (True, False)
910import Prim.Row (class Cons, class Lacks, class Union) as Row
1011import Prim.RowList as RL
@@ -13,7 +14,6 @@ import Prim.TypeError (class Fail, Text)
1314import Type.Proxy (Proxy(..))
1415import Type.RowList (class ListToRow)
1516import Yoga.JSON (class ReadForeign)
16−import Yoga.Om (Om, ask)
1717import Yoga.Postgres as PG
1818import Yoga.Postgres.Schema
1919 ( class ColumnCountRL, class ColumnNamesRL, class ExtractType
@@ -26,12 +26,6 @@ import Yoga.Postgres.Schema
2626 , unsafeDecodeRow, unsafeDecodeRows
2727 )
2828
29−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
30−-- Context type for Om
31−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
32−
33−type PgCtx r = (pgConnection :: PG.Connection | r)
34−
3529-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3630-- Type extraction from tables
3731-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -162,20 +156,21 @@ instance
162156-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
163157
164158findAll
165− :: forall name cols row ctx errs
159+ :: forall name cols row
166160 . IsSymbol name
167161 => TableRow (Table name cols) row
168162 => ReadForeign { | row }
169163 => Proxy (Table name cols)
170− -> Om { | PgCtx ctx } errs (Array { | row })
171−findAll _ = do
172− { pgConnection } <- ask
173− PG.query (PG.SQL sql) [] pgConnection # liftAff <#> \r -> unsafeDecodeRows r.rows
164+ -> PG.Connection
165+ -> Aff (Array { | row })
166+findAll _ conn = do
167+ result <- PG.query (PG.SQL sql) [] conn
168+ pure (unsafeDecodeRows result.rows)
174169 where
175170 sql = "SELECT * FROM " <> reflectSymbol (Proxy :: Proxy name)
176171
177172findById
178− :: forall name cols row pkCol pkType ctx errs
173+ :: forall name cols row pkCol pkType
179174 . IsSymbol name
180175 => IsSymbol pkCol
181176 => TableRow (Table name cols) row
@@ -183,18 +178,19 @@ findById
183178 => FieldToPGValue pkType
184179 => ReadForeign { | row }
185180 => Proxy (Table name cols)
181+ -> PG.Connection
186182 -> pkType
187− -> Om { | PgCtx ctx } errs (Maybe { | row })
188−findById _ pk = do
189− { pgConnection } <- ask
190− PG.queryOne (PG.SQL sql) [ fieldToPGValue pk ] pgConnection # liftAff <#> \r -> r <#> unsafeDecodeRow
183+ -> Aff (Maybe { | row })
184+findById _ conn pk = do
185+ result <- PG.queryOne (PG.SQL sql) [ fieldToPGValue pk ] conn
186+ pure (result <#> unsafeDecodeRow)
191187 where
192188 sql = "SELECT * FROM " <> reflectSymbol (Proxy :: Proxy name)
193189 <> " WHERE " <> reflectSymbol (Proxy :: Proxy pkCol) <> " = $1"
194190
195191create
196192 :: forall name cols colsRL insertableRL insertable requiredRL required
197− optionalProvided missing userRow userRowRL row ctx errs
193+ optionalProvided missing userRow userRowRL row
198194 . IsSymbol name
199195 => RowToList cols colsRL
200196 => InsertableColumnsRL colsRL insertableRL
@@ -209,11 +205,12 @@ create
209205 => TableRow (Table name cols) row
210206 => ReadForeign { | row }
211207 => Proxy (Table name cols)
208+ -> PG.Connection
212209 -> { | userRow }
213− -> Om { | PgCtx ctx } errs (Maybe { | row })
214−create _ rec = do
215− { pgConnection } <- ask
216− PG.queryOne (PG.SQL sql) values pgConnection # liftAff <#> \r -> r <#> unsafeDecodeRow
210+ -> Aff (Maybe { | row })
211+create _ conn rec = do
212+ result <- PG.queryOne (PG.SQL sql) values conn
213+ pure (result <#> unsafeDecodeRow)
217214 where
218215 colNames = columnNamesRL (Proxy :: Proxy userRowRL)
219216 placeholders = colNames # mapWithIndex \i _ -> "$" <> show (i + 1)
@@ -224,7 +221,7 @@ create _ rec = do
224221 values = recordValuesRL (Proxy :: Proxy userRowRL) rec
225222
226223updateById
227− :: forall name cols row pkCol pkType setRow setRL ctx errs
224+ :: forall name cols row pkCol pkType setRow setRL
228225 . IsSymbol name
229226 => IsSymbol pkCol
230227 => TableRow (Table name cols) row
@@ -237,12 +234,13 @@ updateById
237234 => FieldToPGValue pkType
238235 => ReadForeign { | row }
239236 => Proxy (Table name cols)
237+ -> PG.Connection
240238 -> pkType
241239 -> { | setRow }
242− -> Om { | PgCtx ctx } errs (Maybe { | row })
243−updateById _ pk rec = do
244− { pgConnection } <- ask
245− PG.queryOne (PG.SQL sql) values pgConnection # liftAff <#> \r -> r <#> unsafeDecodeRow
240+ -> Aff (Maybe { | row })
241+updateById _ conn pk rec = do
242+ result <- PG.queryOne (PG.SQL sql) values conn
243+ pure (result <#> unsafeDecodeRow)
246244 where
247245 setClauses = setClauseRL (Proxy :: Proxy setRL) 1
248246 setCount = columnCountRL (Proxy :: Proxy setRL)
@@ -253,17 +251,17 @@ updateById _ pk rec = do
253251 values = recordValuesRL (Proxy :: Proxy setRL) rec <> [ fieldToPGValue pk ]
254252
255253deleteById
256− :: forall name cols pkCol pkType ctx errs
254+ :: forall name cols pkCol pkType
257255 . IsSymbol name
258256 => IsSymbol pkCol
259257 => FindPrimaryKey (Table name cols) pkCol pkType
260258 => FieldToPGValue pkType
261259 => Proxy (Table name cols)
260+ -> PG.Connection
262261 -> pkType
263− -> Om { | PgCtx ctx } errs Int
264−deleteById _ pk = do
265− { pgConnection } <- ask
266− PG.execute (PG.SQL sql) [ fieldToPGValue pk ] pgConnection # liftAff
262+ -> Aff Int
263+deleteById _ conn pk =
264+ PG.execute (PG.SQL sql) [ fieldToPGValue pk ] conn
267265 where
268266 sql = "DELETE FROM " <> reflectSymbol (Proxy :: Proxy name)
269267 <> " WHERE " <> reflectSymbol (Proxy :: Proxy pkCol) <> " = $1"
@@ -274,7 +272,7 @@ deleteById _ pk = do
274272
275273findWith
276274 :: forall childName childCols parentName parentCols
277− childRow parentRow localCol parentCol rest result ctx errs
275+ childRow parentRow localCol parentCol rest result
278276 . IsSymbol childName
279277 => IsSymbol parentName
280278 => IsSymbol localCol
@@ -287,10 +285,11 @@ findWith
287285 => ReadForeign { | result }
288286 => Proxy (Table childName childCols)
289287 -> Proxy (Table parentName parentCols)
290− -> Om { | PgCtx ctx } errs (Array { | result })
291−findWith _ _ = do
292− { pgConnection } <- ask
293− PG.query (PG.SQL sql) [] pgConnection # liftAff <#> \r -> unsafeDecodeRows r.rows
288+ -> PG.Connection
289+ -> Aff (Array { | result })
290+findWith _ _ conn = do
291+ result <- PG.query (PG.SQL sql) [] conn
292+ pure (unsafeDecodeRows result.rows)
294293 where
295294 childTbl = reflectSymbol (Proxy :: Proxy childName)
296295 parentTbl = reflectSymbol (Proxy :: Proxy parentName)
@@ -303,7 +302,7 @@ findWith _ _ = do
303302
304303findByIdWith
305304 :: forall childName childCols parentName parentCols
306− childRow parentRow localCol parentCol pkCol pkType rest result ctx errs
305+ childRow parentRow localCol parentCol pkCol pkType rest result
307306 . IsSymbol childName
308307 => IsSymbol parentName
309308 => IsSymbol localCol
@@ -319,11 +318,12 @@ findByIdWith
319318 => ReadForeign { | result }
320319 => Proxy (Table childName childCols)
321320 -> Proxy (Table parentName parentCols)
321+ -> PG.Connection
322322 -> pkType
323− -> Om { | PgCtx ctx } errs (Maybe { | result })
324−findByIdWith _ _ pk = do
325− { pgConnection } <- ask
326− PG.queryOne (PG.SQL sql) [ fieldToPGValue pk ] pgConnection # liftAff <#> \r -> r <#> unsafeDecodeRow
323+ -> Aff (Maybe { | result })
324+findByIdWith _ _ conn pk = do
325+ result <- PG.queryOne (PG.SQL sql) [ fieldToPGValue pk ] conn
326+ pure (result <#> unsafeDecodeRow)
327327 where
328328 childTbl = reflectSymbol (Proxy :: Proxy childName)
329329 parentTbl = reflectSymbol (Proxy :: Proxy parentName)
@@ -342,7 +342,7 @@ findByIdWith _ _ pk = do
342342
343343findIncluding
344344 :: forall @label parentName parentCols childName childCols
345− parentRow childRow localCol parentCol result ctx errs
345+ parentRow childRow localCol parentCol result
346346 . IsSymbol label
347347 => IsSymbol parentName
348348 => IsSymbol childName
@@ -356,10 +356,11 @@ findIncluding
356356 => ReadForeign { | result }
357357 => Proxy (Table parentName parentCols)
358358 -> Proxy (Table childName childCols)
359− -> Om { | PgCtx ctx } errs (Array { | result })
360−findIncluding _ _ = do
361− { pgConnection } <- ask
362− PG.query (PG.SQL sql) [] pgConnection # liftAff <#> \r -> unsafeDecodeRows r.rows
359+ -> PG.Connection
360+ -> Aff (Array { | result })
361+findIncluding _ _ conn = do
362+ result <- PG.query (PG.SQL sql) [] conn
363+ pure (unsafeDecodeRows result.rows)
363364 where
364365 parentTbl = reflectSymbol (Proxy :: Proxy parentName)
365366 childTbl = reflectSymbol (Proxy :: Proxy childName)
@@ -373,7 +374,7 @@ findIncluding _ _ = do
373374
374375findByIdIncluding
375376 :: forall @label parentName parentCols childName childCols
376− parentRow childRow localCol parentCol pkCol pkType result ctx errs
377+ parentRow childRow localCol parentCol pkCol pkType result
377378 . IsSymbol label
378379 => IsSymbol parentName
379380 => IsSymbol childName
@@ -390,11 +391,12 @@ findByIdIncluding
390391 => ReadForeign { | result }
391392 => Proxy (Table parentName parentCols)
392393 -> Proxy (Table childName childCols)
394+ -> PG.Connection
393395 -> pkType
394− -> Om { | PgCtx ctx } errs (Maybe { | result })
395−findByIdIncluding _ _ pk = do
396− { pgConnection } <- ask
397− PG.queryOne (PG.SQL sql) [ fieldToPGValue pk ] pgConnection # liftAff <#> \r -> r <#> unsafeDecodeRow
396+ -> Aff (Maybe { | result })
397+findByIdIncluding _ _ conn pk = do
398+ result <- PG.queryOne (PG.SQL sql) [ fieldToPGValue pk ] conn
399+ pure (result <#> unsafeDecodeRow)
398400 where
399401 parentTbl = reflectSymbol (Proxy :: Proxy parentName)
400402 childTbl = reflectSymbol (Proxy :: Proxy childName)