packages feed

postgresql-query 1.1.0 → 1.1.1

raw patch · 4 files changed

+44/−22 lines, 4 files

Files

+ CHANGELOG.md view
@@ -0,0 +1,21 @@+# CHANGELOG++## 1.1.1++### Changed++* `pgInsertManyEntities` returns count of inserted entities+* `pgDeleteEntity` returns True if entity was actually deleted+* `pgUpdateEntity` returns True if entity was actually updated++## 1.1.0++### Added+* `deriveEntity` - TH derivation `Entity` instances for you types+* `deriveEverything` - TH derivation of `Entity`, `ToRow` and `FromRow` in one shot++### Changed+* Docs improoved++## 1.0.1+The first usable version
postgresql-query.cabal view
@@ -1,5 +1,5 @@ name:                postgresql-query-version:             1.1.0+version:             1.1.1  synopsis: Sql interpolating quasiquote plus some kind of primitive ORM           using it@@ -13,7 +13,8 @@ build-type:          Simple cabal-version:       >=1.10 -extra-source-files: README.md+extra-source-files: CHANGELOG.md+                  , README.md  homepage: https://bitbucket.org/s9gf4ult/postgresql-query source-repository head
src/Database/PostgreSQL/Query/Functions.hs view
@@ -252,11 +252,11 @@ -- 'pgInsertManyEntitiesId' does pgInsertManyEntities :: forall a m. (Entity a, HasPostgres m, MonadLogger m, ToRow a)                      => [a]-                     -> m ()-pgInsertManyEntities [] = return ()+                     -> m Int64+pgInsertManyEntities [] = return 0 pgInsertManyEntities ents' =     let ents = NL.fromList ents'-    in void $ pgExecute $ insertManyEntities ents+    in pgExecute $ insertManyEntities ents   {- | Delete entity.@@ -267,19 +267,21 @@     pgDeleteEntity uid @ +Return 'True' if row was actually deleted. -}  pgDeleteEntity :: forall a m. (Entity a, HasPostgres m, MonadLogger m, ToField (EntityId a), Functor m)                => EntityId a-               -> m ()+               -> m Bool pgDeleteEntity eid =     let p = Proxy :: Proxy a-    in (const ()) <$> pgExecute [sqlExp|DELETE FROM ^{mkIdent $ tableName p}-                                        WHERE id = #{eid}|]+    in fmap (1 ==)+       $ pgExecute [sqlExp|DELETE FROM ^{mkIdent $ tableName p}+                           WHERE id = #{eid}|]  -{- | Update entity using 'ToMarkedRow' instanced value. Requires 'Proxy' while-'EntityId' is not a data type.+{- | Update entity using 'ToMarkedRow' instanced value. Requires 'Proxy'+while 'EntityId' is not a data type.  @ fixUser :: Text -> EntityId User -> Handler ()@@ -293,19 +295,21 @@               ("name", mkValue username)] @ +Returns 'True' if record was actually updated and 'False' if there was+not row with such id (or was more than 1, in fact) -}  pgUpdateEntity :: forall a b m. (ToMarkedRow b, Entity a, HasPostgres m, MonadLogger m,                            ToField (EntityId a), Functor m, Typeable a, Typeable b)                => EntityId a                -> b-               -> m ()+               -> m Bool pgUpdateEntity eid b =     let p = Proxy :: Proxy a         mr = toMarkedRow b     in if L.null $ unMR mr-       then return ()-       else fmap (const ())+       then return False+       else fmap (1 ==)             $ pgExecute [sqlExp|UPDATE ^{mkIdent $ tableName p}                                 SET ^{mrToBuilder ", " mr}                                 WHERE id = #{eid}|]
src/Database/PostgreSQL/Query/Types.hs view
@@ -67,8 +67,7 @@  -- | type to put and get from db 'inet' and 'cidr' typed postgresql -- fields. This should be in postgresql-simple in fact.-newtype InetText =-    InetText+newtype InetText = InetText     { unInetText :: T.Text     } deriving ( IsString, Eq, Ord, Read, Show                , Typeable, Monoid, ToField )@@ -90,7 +89,7 @@   -{- | Dote separated field name. Each element in nested list will be+{- | Dot-separated field name. Each element in nested list will be properly quoted and separated by dot. It also have instance of 'ToSqlBuilder' and 'IsString` so you can: @@ -116,8 +115,7 @@  -} -newtype FN =-    FN [Text]+newtype FN = FN [Text]     deriving (Ord, Eq, Show, Monoid, Typeable, Generic)  instance ToSqlBuilder FN where@@ -166,8 +164,7 @@  -} -newtype MarkedRow =-    MR+newtype MarkedRow = MR     { unMR :: [(FN, SqlBuilder)]     } deriving (Monoid, Typeable, Generic) @@ -283,8 +280,7 @@ -- connection you can run queries in this monad using 'runPgMonadT'. Or you -- can use this transformer to run sequence of queries using same -- connection with 'launchPG'.-newtype PgMonadT m a =-    PgMonadT+newtype PgMonadT m a = PgMonadT     { unPgMonadT :: ReaderT Connection m a     } deriving ( Functor, Applicative, Monad , MonadWriter w                , MonadState s, MonadError e, MonadTrans