on dev help sign in
work thru some more
7076866Eitan Chatav
squeal-postgresql/squeal-postgresql.cabal+1−1
@@ -26,7 +26,7 @@ library
26 Squeal.PostgreSQL.Definition
26 Squeal.PostgreSQL.Definition
27 Squeal.PostgreSQL.Expression
27 Squeal.PostgreSQL.Expression
28 Squeal.PostgreSQL.Manipulation
28 Squeal.PostgreSQL.Manipulation
29− Squeal.PostgreSQL.Migration
29+ -- Squeal.PostgreSQL.Migration
30 Squeal.PostgreSQL.Pool
30 Squeal.PostgreSQL.Pool
31 Squeal.PostgreSQL.PQ
31 Squeal.PostgreSQL.PQ
32 Squeal.PostgreSQL.Render
32 Squeal.PostgreSQL.Render
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+86−86
@@ -11,7 +11,7 @@ a `Definition` and `MonadPQ` for executing a `Manipulation` or `Query`,
11and a `PQ` type with instances for them.
11and a `PQ` type with instances for them.
12
12
13Using Squeal in your application will come down to defining
13Using Squeal in your application will come down to defining
14−the @schema@ of your database and including @PQ schema schema@ in your
14+the @db@ of your database and including @PQ db db@ in your
15application's monad transformer stack, giving it an instance of `MonadPQ`.
15application's monad transformer stack, giving it an instance of `MonadPQ`.
16
16
17This module also provides functions for retrieving rows from the `LibPQ.Result`
17This module also provides functions for retrieving rows from the `LibPQ.Result`
@@ -130,22 +130,22 @@ Note that, for now, squeal doesn't offer any protection from connecting
130with the wrong schema!
130with the wrong schema!
131-}
131-}
132connectdb
132connectdb
133− :: forall schema io
133+ :: forall db io
134 . MonadBase IO io
134 . MonadBase IO io
135 => ByteString -- ^ conninfo
135 => ByteString -- ^ conninfo
136− -> io (K LibPQ.Connection schema)
136+ -> io (K LibPQ.Connection db)
137connectdb = fmap K . liftBase . LibPQ.connectdb
137connectdb = fmap K . liftBase . LibPQ.connectdb
138
138
139-- | Closes the connection to the server.
139-- | Closes the connection to the server.
140−finish :: MonadBase IO io => K LibPQ.Connection schema -> io ()
140+finish :: MonadBase IO io => K LibPQ.Connection db -> io ()
141finish = liftBase . LibPQ.finish . unK
141finish = liftBase . LibPQ.finish . unK
142
142
143-- | Do `connectdb` and `finish` before and after a computation.
143-- | Do `connectdb` and `finish` before and after a computation.
144withConnection
144withConnection
145− :: forall schema0 schema1 io x
145+ :: forall db0 db1 io x
146 . MonadBaseControl IO io
146 . MonadBaseControl IO io
147 => ByteString
147 => ByteString
148− -> PQ schema0 schema1 io x
148+ -> PQ db0 db1 io x
149 -> io x
149 -> io x
150withConnection connString action = do
150withConnection connString action = do
151 K x <- bracket (connectdb connString) finish (unPQ action)
151 K x <- bracket (connectdb connString) finish (unPQ action)
@@ -153,20 +153,20 @@ withConnection connString action = do
153
153
154-- | Safely `lowerConnection` to a smaller schema.
154-- | Safely `lowerConnection` to a smaller schema.
155lowerConnection
155lowerConnection
156− :: K LibPQ.Connection (table ': schema)
156+ :: K LibPQ.Connection (schema ': db)
157− -> K LibPQ.Connection schema
157+ -> K LibPQ.Connection db
158lowerConnection (K conn) = K conn
158lowerConnection (K conn) = K conn
159
159
160-- | We keep track of the schema via an Atkey indexed state monad transformer,
160-- | We keep track of the schema via an Atkey indexed state monad transformer,
161-- `PQ`.
161-- `PQ`.
162newtype PQ
162newtype PQ
163− (schema0 :: SchemaType)
163+ (db0 :: DBType)
164− (schema1 :: SchemaType)
164+ (db1 :: DBType)
165 (m :: Type -> Type)
165 (m :: Type -> Type)
166 (x :: Type) =
166 (x :: Type) =
167− PQ { unPQ :: K LibPQ.Connection schema0 -> m (K x schema1) }
167+ PQ { unPQ :: K LibPQ.Connection db0 -> m (K x db1) }
168
168
169−instance Monad m => Functor (PQ schema0 schema1 m) where
169+instance Monad m => Functor (PQ db0 db1 m) where
170 fmap f (PQ pq) = PQ $ \ conn -> do
170 fmap f (PQ pq) = PQ $ \ conn -> do
171 K x <- pq conn
171 K x <- pq conn
172 return $ K (f x)
172 return $ K (f x)
@@ -174,9 +174,9 @@ instance Monad m => Functor (PQ schema0 schema1 m) where
174-- | Run a `PQ` and keep the result and the `Connection`.
174-- | Run a `PQ` and keep the result and the `Connection`.
175runPQ
175runPQ
176 :: Functor m
176 :: Functor m
177− => PQ schema0 schema1 m x
177+ => PQ db0 db1 m x
178− -> K LibPQ.Connection schema0
178+ -> K LibPQ.Connection db0
179− -> m (x, K LibPQ.Connection schema1)
179+ -> m (x, K LibPQ.Connection db1)
180runPQ (PQ pq) conn = (\ x -> (unK x, K (unK conn))) <$> pq conn
180runPQ (PQ pq) conn = (\ x -> (unK x, K (unK conn))) <$> pq conn
181 -- K x <- pq conn
181 -- K x <- pq conn
182 -- return (x, K (unK conn))
182 -- return (x, K (unK conn))
@@ -184,16 +184,16 @@ runPQ (PQ pq) conn = (\ x -> (unK x, K (unK conn))) <$> pq conn
184-- | Execute a `PQ` and discard the result but keep the `Connection`.
184-- | Execute a `PQ` and discard the result but keep the `Connection`.
185execPQ
185execPQ
186 :: Functor m
186 :: Functor m
187− => PQ schema0 schema1 m x
187+ => PQ db0 db1 m x
188− -> K LibPQ.Connection schema0
188+ -> K LibPQ.Connection db0
189− -> m (K LibPQ.Connection schema1)
189+ -> m (K LibPQ.Connection db1)
190execPQ (PQ pq) conn = mapKK (\ _ -> unK conn) <$> pq conn
190execPQ (PQ pq) conn = mapKK (\ _ -> unK conn) <$> pq conn
191
191
192-- | Evaluate a `PQ` and discard the `Connection` but keep the result.
192-- | Evaluate a `PQ` and discard the `Connection` but keep the result.
193evalPQ
193evalPQ
194 :: Functor m
194 :: Functor m
195− => PQ schema0 schema1 m x
195+ => PQ db0 db1 m x
196− -> K LibPQ.Connection schema0
196+ -> K LibPQ.Connection db0
197 -> m x
197 -> m x
198evalPQ (PQ pq) conn = unK <$> pq conn
198evalPQ (PQ pq) conn = unK <$> pq conn
199
199
@@ -208,53 +208,53 @@ class IndexedMonadTransPQ pq where
208 -- | indexed analog of `<*>`
208 -- | indexed analog of `<*>`
209 pqAp
209 pqAp
210 :: Monad m
210 :: Monad m
211− => pq schema0 schema1 m (x -> y)
211+ => pq db0 db1 m (x -> y)
212− -> pq schema1 schema2 m x
212+ -> pq db1 db2 m x
213− -> pq schema0 schema2 m y
213+ -> pq db0 db2 m y
214
214
215 -- | indexed analog of `join`
215 -- | indexed analog of `join`
216 pqJoin
216 pqJoin
217 :: Monad m
217 :: Monad m
218− => pq schema0 schema1 m (pq schema1 schema2 m y)
218+ => pq db0 db1 m (pq db1 db2 m y)
219− -> pq schema0 schema2 m y
219+ -> pq db0 db2 m y
220 pqJoin pq = pq & pqBind id
220 pqJoin pq = pq & pqBind id
221
221
222 -- | indexed analog of `=<<`
222 -- | indexed analog of `=<<`
223 pqBind
223 pqBind
224 :: Monad m
224 :: Monad m
225− => (x -> pq schema1 schema2 m y)
225+ => (x -> pq db1 db2 m y)
226− -> pq schema0 schema1 m x
226+ -> pq db0 db1 m x
227− -> pq schema0 schema2 m y
227+ -> pq db0 db2 m y
228
228
229 -- | indexed analog of flipped `>>`
229 -- | indexed analog of flipped `>>`
230 pqThen
230 pqThen
231 :: Monad m
231 :: Monad m
232− => pq schema1 schema2 m y
232+ => pq db1 db2 m y
233− -> pq schema0 schema1 m x
233+ -> pq db0 db1 m x
234− -> pq schema0 schema2 m y
234+ -> pq db0 db2 m y
235 pqThen pq2 pq1 = pq1 & pqBind (\ _ -> pq2)
235 pqThen pq2 pq1 = pq1 & pqBind (\ _ -> pq2)
236
236
237 -- | indexed analog of `<=<`
237 -- | indexed analog of `<=<`
238 pqAndThen
238 pqAndThen
239 :: Monad m
239 :: Monad m
240− => (y -> pq schema1 schema2 m z)
240+ => (y -> pq db1 db2 m z)
241− -> (x -> pq schema0 schema1 m y)
241+ -> (x -> pq db0 db1 m y)
242− -> x -> pq schema0 schema2 m z
242+ -> x -> pq db0 db2 m z
243 pqAndThen g f x = pqBind g (f x)
243 pqAndThen g f x = pqBind g (f x)
244
244
245 -- | Safely embed a computation in a larger schema.
245 -- | Safely embed a computation in a larger schema.
246 pqEmbed
246 pqEmbed
247 :: Monad m
247 :: Monad m
248− => pq schema0 schema1 m x
248+ => pq db0 db1 m x
249− -> pq (table ': schema0) (table : schema1) m x
249+ -> pq (table ': db0) (table : db1) m x
250
250
251 -- | Run a `Definition` with `LibPQ.exec`, we expect that libpq obeys the law
251 -- | Run a `Definition` with `LibPQ.exec`, we expect that libpq obeys the law
252 --
252 --
253 -- @define statement1 & pqThen (define statement2) = define (statement1 >>> statement2)@
253 -- @define statement1 & pqThen (define statement2) = define (statement1 >>> statement2)@
254 define
254 define
255 :: MonadBase IO io
255 :: MonadBase IO io
256− => Definition schema0 schema1
256+ => Definition db0 db1
257− -> pq schema0 schema1 io (K LibPQ.Result '[])
257+ -> pq db0 db1 io (K LibPQ.Result '[])
258
258
259instance IndexedMonadTransPQ PQ where
259instance IndexedMonadTransPQ PQ where
260
260
@@ -312,66 +312,66 @@ To define an instance, you can minimally define only `manipulateParams`,
312a default instance.
312a default instance.
313
313
314-}
314-}
315−class Monad pq => MonadPQ schema pq | pq -> schema where
315+class Monad pq => MonadPQ db pq | pq -> db where
316 manipulateParams
316 manipulateParams
317 :: ToParams x params
317 :: ToParams x params
318− => Manipulation schema params ys
318+ => Manipulation db params ys
319 -- ^ `insertRows`, `update` or `deleteFrom`
319 -- ^ `insertRows`, `update` or `deleteFrom`
320 -> x -> pq (K LibPQ.Result ys)
320 -> x -> pq (K LibPQ.Result ys)
321 default manipulateParams
321 default manipulateParams
322− :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
322+ :: (MonadTrans t, MonadPQ db pq1, pq ~ t pq1)
323 => ToParams x params
323 => ToParams x params
324− => Manipulation schema params ys
324+ => Manipulation db params ys
325 -- ^ `insertRows`, `update` or `deleteFrom`
325 -- ^ `insertRows`, `update` or `deleteFrom`
326 -> x -> pq (K LibPQ.Result ys)
326 -> x -> pq (K LibPQ.Result ys)
327 manipulateParams manipulation params = lift $
327 manipulateParams manipulation params = lift $
328 manipulateParams manipulation params
328 manipulateParams manipulation params
329
329
330− manipulate :: Manipulation schema '[] ys -> pq (K LibPQ.Result ys)
330+ manipulate :: Manipulation db '[] ys -> pq (K LibPQ.Result ys)
331 manipulate statement = manipulateParams statement ()
331 manipulate statement = manipulateParams statement ()
332
332
333 runQueryParams
333 runQueryParams
334 :: ToParams x params
334 :: ToParams x params
335− => Query schema params ys
335+ => Query db params ys
336 -- ^ `select` and friends
336 -- ^ `select` and friends
337 -> x -> pq (K LibPQ.Result ys)
337 -> x -> pq (K LibPQ.Result ys)
338 runQueryParams = manipulateParams . queryStatement
338 runQueryParams = manipulateParams . queryStatement
339
339
340 runQuery
340 runQuery
341− :: Query schema '[] ys
341+ :: Query db '[] ys
342 -- ^ `select` and friends
342 -- ^ `select` and friends
343 -> pq (K LibPQ.Result ys)
343 -> pq (K LibPQ.Result ys)
344 runQuery q = runQueryParams q ()
344 runQuery q = runQueryParams q ()
345
345
346 traversePrepared
346 traversePrepared
347 :: (ToParams x params, Traversable list)
347 :: (ToParams x params, Traversable list)
348− => Manipulation schema params ys
348+ => Manipulation db params ys
349 -- ^ `insertRows`, `update`, or `deleteFrom`, and friends
349 -- ^ `insertRows`, `update`, or `deleteFrom`, and friends
350 -> list x -> pq (list (K LibPQ.Result ys))
350 -> list x -> pq (list (K LibPQ.Result ys))
351 default traversePrepared
351 default traversePrepared
352− :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
352+ :: (MonadTrans t, MonadPQ db pq1, pq ~ t pq1)
353 => (ToParams x params, Traversable list)
353 => (ToParams x params, Traversable list)
354− => Manipulation schema params ys -> list x -> pq (list (K LibPQ.Result ys))
354+ => Manipulation db params ys -> list x -> pq (list (K LibPQ.Result ys))
355 traversePrepared manipulation params = lift $
355 traversePrepared manipulation params = lift $
356 traversePrepared manipulation params
356 traversePrepared manipulation params
357
357
358 forPrepared
358 forPrepared
359 :: (ToParams x params, Traversable list)
359 :: (ToParams x params, Traversable list)
360 => list x
360 => list x
361− -> Manipulation schema params ys
361+ -> Manipulation db params ys
362 -- ^ `insertRows`, `update` or `deleteFrom`
362 -- ^ `insertRows`, `update` or `deleteFrom`
363 -> pq (list (K LibPQ.Result ys))
363 -> pq (list (K LibPQ.Result ys))
364 forPrepared = flip traversePrepared
364 forPrepared = flip traversePrepared
365
365
366 traversePrepared_
366 traversePrepared_
367 :: (ToParams x params, Foldable list)
367 :: (ToParams x params, Foldable list)
368− => Manipulation schema params '[]
368+ => Manipulation db params '[]
369 -- ^ `insertRows`, `update` or `deleteFrom`
369 -- ^ `insertRows`, `update` or `deleteFrom`
370 -> list x -> pq ()
370 -> list x -> pq ()
371 default traversePrepared_
371 default traversePrepared_
372− :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
372+ :: (MonadTrans t, MonadPQ db pq1, pq ~ t pq1)
373 => (ToParams x params, Foldable list)
373 => (ToParams x params, Foldable list)
374− => Manipulation schema params '[]
374+ => Manipulation db params '[]
375 -- ^ `insertRows`, `update` or `deleteFrom`
375 -- ^ `insertRows`, `update` or `deleteFrom`
376 -> list x -> pq ()
376 -> list x -> pq ()
377 traversePrepared_ manipulation params = lift $
377 traversePrepared_ manipulation params = lift $
@@ -380,22 +380,22 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
380 forPrepared_
380 forPrepared_
381 :: (ToParams x params, Foldable list)
381 :: (ToParams x params, Foldable list)
382 => list x
382 => list x
383− -> Manipulation schema params '[]
383+ -> Manipulation db params '[]
384 -- ^ `insertRows`, `update` or `deleteFrom`
384 -- ^ `insertRows`, `update` or `deleteFrom`
385 -> pq ()
385 -> pq ()
386 forPrepared_ = flip traversePrepared_
386 forPrepared_ = flip traversePrepared_
387
387
388 liftPQ :: (LibPQ.Connection -> IO a) -> pq a
388 liftPQ :: (LibPQ.Connection -> IO a) -> pq a
389 default liftPQ
389 default liftPQ
390− :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
390+ :: (MonadTrans t, MonadPQ db pq1, pq ~ t pq1)
391 => (LibPQ.Connection -> IO a) -> pq a
391 => (LibPQ.Connection -> IO a) -> pq a
392 liftPQ = lift . liftPQ
392 liftPQ = lift . liftPQ
393
393
394−instance (MonadBase IO io, schema0 ~ schema, schema1 ~ schema)
394+instance (MonadBase IO io, db0 ~ db, db1 ~ db)
395− => MonadPQ schema (PQ schema0 schema1 io) where
395+ => MonadPQ db (PQ db0 db1 io) where
396
396
397 manipulateParams
397 manipulateParams
398− (UnsafeManipulation q :: Manipulation schema ps ys) (params :: x) =
398+ (UnsafeManipulation q :: Manipulation db ps ys) (params :: x) =
399 PQ $ \ (K conn) -> do
399 PQ $ \ (K conn) -> do
400 let
400 let
401 toParam' encoding =
401 toParam' encoding =
@@ -411,7 +411,7 @@ instance (MonadBase IO io, schema0 ~ schema, schema1 ~ schema)
411 return $ K (K result)
411 return $ K (K result)
412
412
413 traversePrepared
413 traversePrepared
414− (UnsafeManipulation q :: Manipulation schema xs ys) (list :: list x) =
414+ (UnsafeManipulation q :: Manipulation db xs ys) (list :: list x) =
415 PQ $ \ (K conn) -> liftBase $ do
415 PQ $ \ (K conn) -> liftBase $ do
416 let temp = "temporary_statement"
416 let temp = "temporary_statement"
417 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
417 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
@@ -438,7 +438,7 @@ instance (MonadBase IO io, schema0 ~ schema, schema1 ~ schema)
438 return (K results)
438 return (K results)
439
439
440 traversePrepared_
440 traversePrepared_
441− (UnsafeManipulation q :: Manipulation schema xs '[]) (list :: list x) =
441+ (UnsafeManipulation q :: Manipulation db xs '[]) (list :: list x) =
442 PQ $ \ (K conn) -> liftBase $ do
442 PQ $ \ (K conn) -> liftBase $ do
443 let temp = "temporary_statement"
443 let temp = "temporary_statement"
444 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
444 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
@@ -466,56 +466,56 @@ instance (MonadBase IO io, schema0 ~ schema, schema1 ~ schema)
466 y <- liftBase $ pq conn
466 y <- liftBase $ pq conn
467 return (K y)
467 return (K y)
468
468
469−instance MonadPQ schema m => MonadPQ schema (IdentityT m)
469+instance MonadPQ db m => MonadPQ db (IdentityT m)
470−instance MonadPQ schema m => MonadPQ schema (ReaderT r m)
470+instance MonadPQ db m => MonadPQ db (ReaderT r m)
471−instance MonadPQ schema m => MonadPQ schema (Strict.StateT s m)
471+instance MonadPQ db m => MonadPQ db (Strict.StateT s m)
472−instance MonadPQ schema m => MonadPQ schema (Lazy.StateT s m)
472+instance MonadPQ db m => MonadPQ db (Lazy.StateT s m)
473−instance (Monoid w, MonadPQ schema m) => MonadPQ schema (Strict.WriterT w m)
473+instance (Monoid w, MonadPQ db m) => MonadPQ db (Strict.WriterT w m)
474−instance (Monoid w, MonadPQ schema m) => MonadPQ schema (Lazy.WriterT w m)
474+instance (Monoid w, MonadPQ db m) => MonadPQ db (Lazy.WriterT w m)
475−instance MonadPQ schema m => MonadPQ schema (MaybeT m)
475+instance MonadPQ db m => MonadPQ db (MaybeT m)
476−instance MonadPQ schema m => MonadPQ schema (ExceptT e m)
476+instance MonadPQ db m => MonadPQ db (ExceptT e m)
477−instance (Monoid w, MonadPQ schema m) => MonadPQ schema (Strict.RWST r w s m)
477+instance (Monoid w, MonadPQ db m) => MonadPQ db (Strict.RWST r w s m)
478−instance (Monoid w, MonadPQ schema m) => MonadPQ schema (Lazy.RWST r w s m)
478+instance (Monoid w, MonadPQ db m) => MonadPQ db (Lazy.RWST r w s m)
479−instance MonadPQ schema m => MonadPQ schema (ContT r m)
479+instance MonadPQ db m => MonadPQ db (ContT r m)
480−
480+
481−instance (Monad m, schema0 ~ schema1)
481+instance (Monad m, db0 ~ db1)
482− => Applicative (PQ schema0 schema1 m) where
482+ => Applicative (PQ db0 db1 m) where
483 pure x = PQ $ \ _conn -> pure (K x)
483 pure x = PQ $ \ _conn -> pure (K x)
484 (<*>) = pqAp
484 (<*>) = pqAp
485
485
486−instance (Monad m, schema0 ~ schema1)
486+instance (Monad m, db0 ~ db1)
487− => Monad (PQ schema0 schema1 m) where
487+ => Monad (PQ db0 db1 m) where
488 return = pure
488 return = pure
489 (>>=) = flip pqBind
489 (>>=) = flip pqBind
490
490
491−instance schema0 ~ schema1 => MFunctor (PQ schema0 schema1) where
491+instance db0 ~ db1 => MFunctor (PQ db0 db1) where
492 hoist f (PQ pq) = PQ (f . pq)
492 hoist f (PQ pq) = PQ (f . pq)
493
493
494−instance schema0 ~ schema1 => MonadTrans (PQ schema0 schema1) where
494+instance db0 ~ db1 => MonadTrans (PQ db0 db1) where
495 lift m = PQ $ \ _conn -> do
495 lift m = PQ $ \ _conn -> do
496 x <- m
496 x <- m
497 return (K x)
497 return (K x)
498
498
499−instance schema0 ~ schema1 => MMonad (PQ schema0 schema1) where
499+instance db0 ~ db1 => MMonad (PQ db0 db1) where
500 embed f (PQ pq) = PQ $ \ conn -> do
500 embed f (PQ pq) = PQ $ \ conn -> do
501 evalPQ (f (pq conn)) conn
501 evalPQ (f (pq conn)) conn
502
502
503−instance (MonadBase b m, schema0 ~ schema1)
503+instance (MonadBase b m, db0 ~ db1)
504− => MonadBase b (PQ schema0 schema1 m) where
504+ => MonadBase b (PQ db0 db1 m) where
505 liftBase = lift . liftBase
505 liftBase = lift . liftBase
506
506
507-- | A snapshot of the state of a `PQ` computation.
507-- | A snapshot of the state of a `PQ` computation.
508−type PQRun schema =
508+type PQRun db =
509− forall m x. Monad m => PQ schema schema m x -> m (K x schema)
509+ forall m x. Monad m => PQ db db m x -> m (K x db)
510
510
511-- | Helper function in defining `MonadBaseControl` instance for `PQ`.
511-- | Helper function in defining `MonadBaseControl` instance for `PQ`.
512−pqliftWith :: Functor m => (PQRun schema -> m a) -> PQ schema schema m a
512+pqliftWith :: Functor m => (PQRun db -> m a) -> PQ db db m a
513pqliftWith f = PQ $ \ conn ->
513pqliftWith f = PQ $ \ conn ->
514 fmap K (f $ \ pq -> unPQ pq conn)
514 fmap K (f $ \ pq -> unPQ pq conn)
515
515
516−instance (MonadBaseControl b m, schema0 ~ schema1)
516+instance (MonadBaseControl b m, db0 ~ db1)
517− => MonadBaseControl b (PQ schema0 schema1 m) where
517+ => MonadBaseControl b (PQ db0 db1 m) where
518− type StM (PQ schema0 schema1 m) x = StM m (K x schema0)
518+ type StM (PQ db0 db1 m) x = StM m (K x db0)
519 liftBaseWith f =
519 liftBaseWith f =
520 pqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
520 pqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
521 restoreM = PQ . const . restoreM
521 restoreM = PQ . const . restoreM
squeal-postgresql/src/Squeal/PostgreSQL/Pool.hs+18−18
@@ -41,7 +41,7 @@ import Generics.SOP (K(..))
41import Squeal.PostgreSQL.PQ
41import Squeal.PostgreSQL.PQ
42import Squeal.PostgreSQL.Schema
42import Squeal.PostgreSQL.Schema
43
43
44−{- | `PoolPQ` @schema@ should be a drop-in replacement for `PQ` @schema schema@.
44+{- | `PoolPQ` @db@ should be a drop-in replacement for `PQ` @db db@.
45
45
46Typical use case would be to create your pool using `createConnectionPool` and run anything that requires the pool connection with it.
46Typical use case would be to create your pool using `createConnectionPool` and run anything that requires the pool connection with it.
47
47
@@ -63,8 +63,8 @@ Here's a simplified example:
63> liftIO $ runPoolPQ (insertOne) pool
63> liftIO $ runPoolPQ (insertOne) pool
64
64
65-}
65-}
66−newtype PoolPQ (schema :: SchemaType) m x =
66+newtype PoolPQ (db :: DBType) m x =
67− PoolPQ { runPoolPQ :: Pool (K Connection schema) -> m x }
67+ PoolPQ { runPoolPQ :: Pool (K Connection db) -> m x }
68 deriving Functor
68 deriving Functor
69
69
70-- | Create a striped pool of connections.
70-- | Create a striped pool of connections.
@@ -86,12 +86,12 @@ createConnectionPool
86 -> Int
86 -> Int
87 -- ^ Maximum number of connections to keep open per stripe. The smallest acceptable value is 1.
87 -- ^ Maximum number of connections to keep open per stripe. The smallest acceptable value is 1.
88 -- Requests for connections will block if this limit is reached on a single stripe, even if other stripes have idle connections available.
88 -- Requests for connections will block if this limit is reached on a single stripe, even if other stripes have idle connections available.
89− -> io (Pool (K Connection schema))
89+ -> io (Pool (K Connection db))
90createConnectionPool conninfo stripes idle maxResrc = liftBase $
90createConnectionPool conninfo stripes idle maxResrc = liftBase $
91 createPool (connectdb conninfo) finish stripes idle maxResrc
91 createPool (connectdb conninfo) finish stripes idle maxResrc
92
92
93-- | `Applicative` instance for `PoolPQ`.
93-- | `Applicative` instance for `PoolPQ`.
94−instance Monad m => Applicative (PoolPQ schema m) where
94+instance Monad m => Applicative (PoolPQ db m) where
95 pure x = PoolPQ $ \ _ -> pure x
95 pure x = PoolPQ $ \ _ -> pure x
96 PoolPQ f <*> PoolPQ x = PoolPQ $ \ pool -> do
96 PoolPQ f <*> PoolPQ x = PoolPQ $ \ pool -> do
97 f' <- f pool
97 f' <- f pool
@@ -99,55 +99,55 @@ instance Monad m => Applicative (PoolPQ schema m) where
99 return $ f' x'
99 return $ f' x'
100
100
101-- | `Monad` instance for `PoolPQ`.
101-- | `Monad` instance for `PoolPQ`.
102−instance Monad m => Monad (PoolPQ schema m) where
102+instance Monad m => Monad (PoolPQ db m) where
103 return = pure
103 return = pure
104 PoolPQ x >>= f = PoolPQ $ \ pool -> do
104 PoolPQ x >>= f = PoolPQ $ \ pool -> do
105 x' <- x pool
105 x' <- x pool
106 runPoolPQ (f x') pool
106 runPoolPQ (f x') pool
107
107
108-- | `MonadTrans` instance for `PoolPQ`.
108-- | `MonadTrans` instance for `PoolPQ`.
109−instance MonadTrans (PoolPQ schema) where
109+instance MonadTrans (PoolPQ db) where
110 lift m = PoolPQ $ \ _pool -> m
110 lift m = PoolPQ $ \ _pool -> m
111
111
112-- | `MonadBase` instance for `PoolPQ`.
112-- | `MonadBase` instance for `PoolPQ`.
113−instance MonadBase b m => MonadBase b (PoolPQ schema m) where
113+instance MonadBase b m => MonadBase b (PoolPQ db m) where
114 liftBase = lift . liftBase
114 liftBase = lift . liftBase
115
115
116-- | `MonadPQ` instance for `PoolPQ`.
116-- | `MonadPQ` instance for `PoolPQ`.
117−instance MonadBaseControl IO io => MonadPQ schema (PoolPQ schema io) where
117+instance MonadBaseControl IO io => MonadPQ db (PoolPQ db io) where
118 manipulateParams manipulation params = PoolPQ $ \ pool -> do
118 manipulateParams manipulation params = PoolPQ $ \ pool -> do
119 withResource pool $ \ conn -> do
119 withResource pool $ \ conn -> do
120− (K result :: K (K Result ys) schema) <- flip unPQ conn $
120+ (K result :: K (K Result ys) db) <- flip unPQ conn $
121 manipulateParams manipulation params
121 manipulateParams manipulation params
122 return result
122 return result
123 traversePrepared manipulation params = PoolPQ $ \ pool ->
123 traversePrepared manipulation params = PoolPQ $ \ pool ->
124 withResource pool $ \ conn -> do
124 withResource pool $ \ conn -> do
125− (K result :: K (list (K Result ys)) schema) <- flip unPQ conn $
125+ (K result :: K (list (K Result ys)) db) <- flip unPQ conn $
126 traversePrepared manipulation params
126 traversePrepared manipulation params
127 return result
127 return result
128 traversePrepared_ manipulation params = PoolPQ $ \ pool -> do
128 traversePrepared_ manipulation params = PoolPQ $ \ pool -> do
129 withResource pool $ \ conn -> do
129 withResource pool $ \ conn -> do
130− (_ :: K () schema) <- flip unPQ conn $
130+ (_ :: K () db) <- flip unPQ conn $
131 traversePrepared_ manipulation params
131 traversePrepared_ manipulation params
132 return ()
132 return ()
133 liftPQ m = PoolPQ $ \ pool ->
133 liftPQ m = PoolPQ $ \ pool ->
134 withResource pool $ \ conn -> do
134 withResource pool $ \ conn -> do
135− (K result :: K result schema) <- flip unPQ conn $
135+ (K result :: K result db) <- flip unPQ conn $
136 liftPQ m
136 liftPQ m
137 return result
137 return result
138
138
139-- | A snapshot of the state of a `PoolPQ` computation.
139-- | A snapshot of the state of a `PoolPQ` computation.
140−type PoolPQRun schema =
140+type PoolPQRun db =
141− forall m x. Monad m => PoolPQ schema m x -> m x
141+ forall m x. Monad m => PoolPQ db m x -> m x
142
142
143-- | Helper function in defining `MonadBaseControl` instance for `PoolPQ`.
143-- | Helper function in defining `MonadBaseControl` instance for `PoolPQ`.
144−poolpqliftWith :: Functor m => (PoolPQRun schema -> m a) -> PoolPQ schema m a
144+poolpqliftWith :: Functor m => (PoolPQRun db -> m a) -> PoolPQ db m a
145poolpqliftWith f = PoolPQ $ \ pool ->
145poolpqliftWith f = PoolPQ $ \ pool ->
146 (f $ \ pq -> runPoolPQ pq pool)
146 (f $ \ pq -> runPoolPQ pq pool)
147
147
148-- | `MonadBaseControl` instance for `PoolPQ`.
148-- | `MonadBaseControl` instance for `PoolPQ`.
149−instance MonadBaseControl b m => MonadBaseControl b (PoolPQ schema m) where
149+instance MonadBaseControl b m => MonadBaseControl b (PoolPQ db m) where
150− type StM (PoolPQ schema m) x = StM m x
150+ type StM (PoolPQ db m) x = StM m x
151 liftBaseWith f =
151 liftBaseWith f =
152 poolpqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
152 poolpqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
153 restoreM = PoolPQ . const . restoreM
153 restoreM = PoolPQ . const . restoreM
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+11−11
@@ -853,31 +853,31 @@ FROM clauses
853A `FromClause` can be a table name, or a derived table such
853A `FromClause` can be a table name, or a derived table such
854as a subquery, a @JOIN@ construct, or complex combinations of these.
854as a subquery, a @JOIN@ construct, or complex combinations of these.
855-}
855-}
856−newtype FromClause schema params from
856+newtype FromClause db params from
857 = UnsafeFromClause { renderFromClause :: ByteString }
857 = UnsafeFromClause { renderFromClause :: ByteString }
858 deriving (GHC.Generic,Show,Eq,Ord,NFData)
858 deriving (GHC.Generic,Show,Eq,Ord,NFData)
859
859
860-- | A real `table` is a table from the schema.
860-- | A real `table` is a table from the schema.
861table
861table
862− :: Has tab schema ('Table table)
862+ :: HasQualified sch tab db schema ('Table table)
863− => Aliased Alias (alias ::: tab)
863+ => Aliased (QualifiedAlias sch) (alias ::: tab)
864− -> FromClause schema params '[alias ::: TableToRow table]
864+ -> FromClause db params '[alias ::: TableToRow table]
865table (tab `As` alias) = UnsafeFromClause $
865table (tab `As` alias) = UnsafeFromClause $
866− renderAlias tab <+> "AS" <+> renderAlias alias
866+ renderQualifiedAlias tab <+> "AS" <+> renderAlias alias
867
867
868-- | `subquery` derives a table from a `Query`.
868-- | `subquery` derives a table from a `Query`.
869subquery
869subquery
870− :: Aliased (Query db params) rel
870+ :: Aliased (Query db params) query
871− -> FromClause schema params '[rel]
871+ -> FromClause schema params '[query]
872subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
872subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
873
873
874-- | `view` derives a table from a `View`.
874-- | `view` derives a table from a `View`.
875view
875view
876− :: Has view schema ('View row)
876+ :: HasQualified sch vw db schema ('View view)
877− => Aliased Alias (alias ::: view)
877+ => Aliased (QualifiedAlias sch) (alias ::: vw)
878− -> FromClause schema params '[alias ::: row]
878+ -> FromClause db params '[alias ::: view]
879view (vw `As` alias) = UnsafeFromClause $
879view (vw `As` alias) = UnsafeFromClause $
880− renderAlias vw <+> "AS" <+> renderAlias alias
880+ renderQualifiedAlias vw <+> "AS" <+> renderAlias alias
881
881
882{- | @left & crossJoin right@. For every possible combination of rows from
882{- | @left & crossJoin right@. For every possible combination of rows from
883 @left@ and @right@ (i.e., a Cartesian product), the joined table will contain
883 @left@ and @right@ (i.e., a Cartesian product), the joined table will contain