packages feed

pg-schema 0.6.1.1 → 0.7.0.0

raw patch · 8 files changed

+33/−23 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ PgSchema.DML: type CondAnn (ann :: Ann) = Cond AnnRen ann AnnSch ann AnnTab ann
+ PgSchema.DML: type QueryParamAnn (ann :: Ann) = QueryParam AnnRen ann AnnSch ann AnnTab ann
- PgSchema.DML: deleteByCond :: forall (ren :: Renamer) sch (t :: NameNSK) -> SingI t => Connection -> Cond ren sch t -> IO (Int64, (Text, [SomeToField]))
+ PgSchema.DML: deleteByCond :: forall (ann :: Ann) -> SingI (AnnTab ann) => Connection -> CondAnn ann -> IO (Int64, (Text, [SomeToField]))
- PgSchema.DML: deleteText :: forall (ren :: Renamer) sch (t :: NameNSK) s. (IsString s, Monoid s, SingI t) => Cond ren sch t -> (s, [SomeToField])
+ PgSchema.DML: deleteText :: forall (ann :: Ann) s. (IsString s, Monoid s, SingI (AnnTab ann)) => CondAnn ann -> (s, [SomeToField])
- PgSchema.DML: selectSch :: forall (ann :: Ann) -> forall r. Selectable ann r => Connection -> QueryParam (AnnRen ann) (AnnSch ann) (AnnTab ann) -> IO ([r], (Text, [SomeToField]))
+ PgSchema.DML: selectSch :: forall (ann :: Ann) -> forall r. Selectable ann r => Connection -> QueryParamAnn ann -> IO ([r], (Text, [SomeToField]))
- PgSchema.DML: selectText :: forall (ann :: Ann) -> forall r. CRecInfo ann r => QueryParam (AnnRen ann) (AnnSch ann) (AnnTab ann) -> (Text, [SomeToField])
+ PgSchema.DML: selectText :: forall (ann :: Ann) -> forall r. CRecInfo ann r => QueryParamAnn ann -> (Text, [SomeToField])
- PgSchema.DML: updateByCond :: forall (ann :: Ann) -> forall r r'. UpdateReturning ann r r' => Connection -> r -> Cond (AnnRen ann) (AnnSch ann) (AnnTab ann) -> IO [r']
+ PgSchema.DML: updateByCond :: forall (ann :: Ann) -> forall r r'. UpdateReturning ann r r' => Connection -> r -> CondAnn ann -> IO [r']
- PgSchema.DML: updateByCond_ :: forall (ann :: Ann) -> forall r. UpdateNonReturning ann r => Connection -> r -> Cond (AnnRen ann) (AnnSch ann) (AnnTab ann) -> IO Int64
+ PgSchema.DML: updateByCond_ :: forall (ann :: Ann) -> forall r. UpdateNonReturning ann r => Connection -> r -> CondAnn ann -> IO Int64
- PgSchema.DML: updateText :: forall (ann :: Ann) -> forall r r' s. (CRecInfo ann r, CRecInfo ann r', IsString s, Monoid s) => Cond (AnnRen ann) (AnnSch ann) (AnnTab ann) -> (s, [SomeToField])
+ PgSchema.DML: updateText :: forall (ann :: Ann) -> forall r r' s. (CRecInfo ann r, CRecInfo ann r', IsString s, Monoid s) => CondAnn ann -> (s, [SomeToField])
- PgSchema.DML: updateText_ :: forall (ren :: Renamer) sch (t :: NameNSK). forall (ann :: Ann) -> forall r s. (IsString s, Monoid s, CRecInfo ann r) => Cond ren sch t -> (s, [SomeToField])
+ PgSchema.DML: updateText_ :: forall (ann :: Ann) -> forall r s. (IsString s, Monoid s, CRecInfo ann r) => CondAnn ann -> (s, [SomeToField])

Files

ChangeLog.md view
@@ -1,5 +1,11 @@ # Changelog for pg-schema +## 0.7.0.0++- Bug fixing (updateText_ signature)+- Change signature for deleteByCond+- Add CondAnn & QueryParamsAnn+ ## 0.6.1.0  - Bug fixing (ins/upsertJSON for json db-fields)
pg-schema.cabal view
@@ -1,6 +1,6 @@ cabal-version:  3.12 name:           pg-schema-version:        0.6.1.1+version:        0.7.0.0 category:       Database author:         Dmitry Olshansky maintainer:     olshanskydr@gmail.com
src/PgSchema/DML.hs view
@@ -77,7 +77,8 @@   , qRoot, qPath, qPathFromHere, qPathToHere, qWhere, qOrderBy   , qDistinct, qDistinctOn, qLimit, qOffset   -- **** Internals-  , QueryParam(..), CondWithPath(..), OrdWithPath(..), LimOffWithPath(..), DistWithPath(..)+  , QueryParam(..), QueryParamAnn, CondWithPath(..), OrdWithPath(..)+  , LimOffWithPath(..), DistWithPath(..)   -- *** Conditions   -- | Example: @"name" =? "John"@   , (<?),(>?),(<=?),(>=?),(=?)@@ -86,7 +87,7 @@   , (|||), (&&&), pnot, pnull, pin, pinArr   , pparent, pchild, TabParam(..), defTabParam   , pUnsafeCond, UnsafeCol(..)-  , Cond(..), Cmp(..), BoolOp(..)+  , Cond(..), CondAnn, Cmp(..), BoolOp(..)   , CondMonad, SomeToField(..), showCmp, tabPref, qual   , CDBField, CDBValue, CDBFieldNullable, CRelDef   -- *** Order By and others
src/PgSchema/DML/Delete.hs view
@@ -7,6 +7,7 @@ import Database.PostgreSQL.Simple import GHC.Int +import PgSchema.Ann import PgSchema.Schema import PgSchema.Utils.Internal import Data.Singletons@@ -14,21 +15,21 @@  -- | Delete records in table by condition. ---deleteByCond :: forall ren sch t -> SingI t =>-  Connection -> Cond ren sch t -> IO (Int64, (Text,[SomeToField]))-deleteByCond ren sch t conn cond = traceShow' (q,ps)+deleteByCond :: forall ann -> SingI (AnnTab ann) => Connection -> CondAnn ann+  -> IO (Int64, (Text,[SomeToField]))+deleteByCond ann conn cond = traceShow' (q,ps)   $ (,(q,ps)) <$> execute conn (fromString $ T.unpack q) ps   where-    (q, ps) = deleteText @ren @sch @t cond+    (q, ps) = deleteText @ann cond  -- | Construct SQL text for deleting records by condition. ---deleteText :: forall ren sch t s. (IsString s, Monoid s, SingI t) =>-  Cond ren sch t -> (s, [SomeToField])+deleteText :: forall ann s. (IsString s, Monoid s, SingI (AnnTab ann)) =>+  CondAnn ann -> (s, [SomeToField]) deleteText cond =   ("delete from " <> tn <> " t0 " <> fromText whereTxt, condParams )   where-    tn = fromText $ qualName $ demote @t+    tn = fromText $ qualName $ demote @(AnnTab ann)     (condTxt, condParams) = pgCond 0 cond     whereTxt       | T.null condTxt = mempty
src/PgSchema/DML/Select.hs view
@@ -73,15 +73,14 @@ -- Build 'QueryParam' with the 'MonadQP' API. -- selectSch :: forall ann -> forall r. Selectable ann r-  => Connection -> QueryParam (AnnRen ann) (AnnSch ann) (AnnTab ann)-  -> IO ([r], (Text,[SomeToField]))+  => Connection -> QueryParamAnn ann -> IO ([r], (Text,[SomeToField])) selectSch ann @r conn (selectText ann @r -> (sql,fs)) =   trace' ("\n\n" <> T.unpack sql <> "\n\n" <> P.show fs <> "\n\n")   $ (,(sql,fs)) . fmap (unPgTag @ann @r) <$> query conn (fromString $ T.unpack sql) fs  -- | Return the generated @SELECT@ SQL text (and bind parameters), e.g. for debugging. selectText :: forall ann -> forall r. (CRecInfo ann r)-  => QueryParam (AnnRen ann) (AnnSch ann) (AnnTab ann) -> (Text,[SomeToField])+  => QueryParamAnn ann -> (Text,[SomeToField]) selectText ann @r qp = evalRWS (selectM "" (getRecordInfo @ann @r)) (qr0 qp) qs0  qr0 :: QueryParam ren sch tab -> QueryRead ren sch tab
src/PgSchema/DML/Select/Types.hs view
@@ -44,6 +44,8 @@   , qpDistinct  :: ![DistWithPath ren sch t]    -- ^ `distinct` and `distinct on` clauses   } +type QueryParamAnn ann = QueryParam (AnnRen ann) (AnnSch ann) (AnnTab ann)+ -- | Empty 'QueryParam'. -- -- It means that @SELECT@ is defined only by structure of output type@@ -326,6 +328,8 @@   -- ^ @JOIN@ to parent rows that satisfy the nested condition   UnsafeCond :: CondMonad Text -> Cond ren sch tab   -- ^ Unsafe condition built manually inside 'CondMonad'++type CondAnn ann = Cond (AnnRen ann) (AnnSch ann) (AnnTab ann)  -- Conjunction '(&&&)' is much more often operation for query conditions so -- we use it for 'Semigroup'.
src/PgSchema/DML/Update.hs view
@@ -20,8 +20,7 @@  -- | Update rows matching a condition; the result type selects which columns are returned. updateByCond :: forall ann -> forall r r'.-  (UpdateReturning ann r r') =>-  Connection -> r -> Cond (AnnRen ann) (AnnSch ann) (AnnTab ann) -> IO [r']+  (UpdateReturning ann r r') => Connection -> r -> CondAnn ann -> IO [r'] updateByCond ann @r @r' conn r (updateText ann @r @r' -> (q,ps)) =   trace' (q <> "\n\n" <> P.show ps <> "\n\n")   $ fmap (fmap (unPgTag @ann @r'))@@ -30,7 +29,7 @@  -- | Update records by condition without @RETURNING@. updateByCond_ :: forall ann -> forall r. UpdateNonReturning ann r =>-  Connection -> r -> Cond (AnnRen ann) (AnnSch ann) (AnnTab ann) -> IO Int64+  Connection -> r -> CondAnn ann -> IO Int64 updateByCond_ ann @r conn r (updateText_ ann @r -> (q, ps)) =   trace' (q <> "\n\n" <> P.show ps <> "\n\n")   $ execute conn (fromString q)@@ -39,7 +38,7 @@ -- | Construct SQL text for updating records by condition and returning some fields. updateText :: forall ann -> forall r r' s.   (CRecInfo ann r, CRecInfo ann r', IsString s, Monoid s)-  => Cond (AnnRen ann) (AnnSch ann) (AnnTab ann) -> (s, [SomeToField])+  => CondAnn ann -> (s, [SomeToField]) updateText ann @r @r' (updateText_ ann @r -> (q, p)) = (q <> " returning " <> fs', p)   where     ri' = getRecordInfo @ann @r'@@ -48,7 +47,7 @@ -- | Construct SQL text for updating records by condition without @RETURNING@. updateText_   :: forall ann -> forall r s. (IsString s, Monoid s, CRecInfo ann r)-  => Cond ren sch t -> (s, [SomeToField])+  => CondAnn ann -> (s, [SomeToField]) updateText_ ann @r (pgCond 0 -> (condTxt, condParams)) =   ("update " <> tn <> " t0 set " <> fs <> fromText whereTxt, condParams )   where
test-pgs/Utils.hs view
@@ -66,21 +66,21 @@ insSch_ tn = insertSch_ (AnnSch tn)  selSch :: forall tn -> forall r. Selectable (AnnSch tn) r-  => Connection -> QueryParam RenamerSch Sch (TS tn) -> IO ([r], (Text,[SomeToField]))+  => Connection -> QueryParamAnn (AnnSch tn) -> IO ([r], (Text,[SomeToField])) selSch tn = selectSch (AnnSch tn)  updByCond_   :: forall tn -> forall r. UpdateNonReturning (AnnSch tn) r-  => Connection -> r -> Cond RenamerSch Sch (TS tn) -> IO Int64+  => Connection -> r -> CondAnn (AnnSch tn) -> IO Int64 updByCond_ tn = updateByCond_ (AnnSch tn)  updByCond :: forall tn -> forall r r'. UpdateReturning (AnnSch tn) r r'-  => Connection -> r -> Cond RenamerSch Sch (TS tn) -> IO [r']+  => Connection -> r -> CondAnn (AnnSch tn) -> IO [r'] updByCond tn = updateByCond (AnnSch tn)  delByCond :: forall tn -> ToStar tn-  => Connection -> Cond RenamerSch Sch (TS tn) -> IO (Int64, (Text,[SomeToField]))-delByCond tn = deleteByCond RenamerSch Sch (TS tn)+  => Connection -> CondAnn (AnnSch tn) -> IO (Int64, (Text,[SomeToField]))+delByCond tn = deleteByCond (AnnSch tn)  insJSON_   :: forall tn -> forall r. (InsertTreeNonReturning (AnnSch tn) r)