groundhog-postgresql 0.4.0.3 → 0.4.1
raw patch · 3 files changed
+26/−7 lines, 3 filesdep ~groundhog
Dependency ranges changed: groundhog
Files
- Database/Groundhog/Postgresql.hs +21/−2
- Database/Groundhog/Postgresql/Array.hs +3/−3
- groundhog-postgresql.cabal +2/−2
Database/Groundhog/Postgresql.hs view
@@ -7,10 +7,13 @@ , Postgresql(..) , module Database.Groundhog , module Database.Groundhog.Generic.Sql.Functions+ , explicitType+ , castType ) where import Database.Groundhog import Database.Groundhog.Core+import Database.Groundhog.Expression import Database.Groundhog.Generic import Database.Groundhog.Generic.Migration hiding (MigrationPack(..)) import qualified Database.Groundhog.Generic.Migration as GM@@ -63,13 +66,15 @@ insertBy u v = H.insertBy escapeS queryRawTyped' True u v insertByAll v = H.insertByAll escapeS queryRawTyped' True v replace k v = H.replace escapeS queryRawTyped' executeRaw' (insertIntoConstructorTable False) k v+ replaceBy k v = H.replaceBy escapeS executeRaw' k v select options = H.select escapeS queryRawTyped' "" renderCond' options selectAll = H.selectAll escapeS queryRawTyped' get k = H.get escapeS queryRawTyped' k getBy k = H.getBy escapeS queryRawTyped' k update upds cond = H.update escapeS executeRaw' renderCond' upds cond delete cond = H.delete escapeS executeRaw' renderCond' cond- deleteByKey k = H.deleteByKey escapeS executeRaw' k+ deleteBy k = H.deleteBy escapeS executeRaw' k+ deleteAll v = H.deleteAll escapeS executeRaw' v count cond = H.count escapeS queryRawTyped' renderCond' cond countAll fakeV = H.countAll escapeS queryRawTyped' fakeV project p options = H.project escapeS queryRawTyped' "" renderCond' p options@@ -325,7 +330,7 @@ else [DropTrigger schema trigName schema name, addTrigger]) return (trigExisted, funcMig ++ trigMig) --- | Table name and a list of field names and according delete statements+-- | Table name and a list of field names and according delete statements -- assume that this function is called only for ephemeral fields migTriggerOnUpdate :: (MonadBaseControl IO m, MonadIO m, MonadLogger m) => Maybe String -> String -> [(String, String)] -> DbPersist Postgresql m [(Bool, [AlterDB])] migTriggerOnUpdate schema name dels = forM dels $ \(fieldName, del) -> do@@ -737,3 +742,17 @@ withSchema :: Maybe String -> String -> String withSchema sch name = maybe "" (\x -> escape x ++ ".") sch ++ escape name+++-- | Put explicit type for expression. It is useful for values which are defaulted to a wrong type.+-- For example, a literal Int from a 64bit machine can be defaulted to a 32bit int by Postgresql. +-- Also a value entered as an external string (geometry, arrays and other complex types have this representation) may need an explicit type. +explicitType :: (Expression Postgresql r a, PersistField a) => a -> Expr Postgresql r a+explicitType a = castType a t where+ t = case dbType a of+ DbTypePrimitive t' _ _ _ -> showSqlType t'+ _ -> error "explicitType: type is not primitive"++-- | Casts expression to a type. @castType value \"INT\"@ results in @value::INT@.+castType :: Expression Postgresql r a => a -> String -> Expr Postgresql r a+castType a t = Expr $ Snippet $ \esc _ -> ["(" <> renderExpr esc (toExpr a) <> ")::" <> fromString t] where
Database/Groundhog/Postgresql/Array.hs view
@@ -131,13 +131,13 @@ (!:) arr (i1, i2) = Expr $ Snippet $ \esc _ -> [renderExpr esc (toExpr arr) <> "[" <> renderExpr esc (toExpr i1) <> ":" <> renderExpr esc (toExpr i2) <> "]"] prepend :: (ExpressionOf Postgresql r a elem, ExpressionOf Postgresql r b (Array elem)) => a -> b -> Expr Postgresql r (Array elem) -prepend a b = Expr $ operator 50 "||" a b +prepend a b = Expr $ function "array_prepend" [toExpr a, toExpr b] append :: (ExpressionOf Postgresql r a (Array elem), ExpressionOf Postgresql r b elem) => a -> b -> Expr Postgresql r (Array elem) -append a b = Expr $ operator 50 "||" a b +append a b = Expr $ function "array_append" [toExpr a, toExpr b] arrayCat :: (ExpressionOf Postgresql r a (Array elem), ExpressionOf Postgresql r b (Array elem)) => a -> b -> Expr Postgresql r (Array elem) -arrayCat a b = Expr $ operator 50 "||" a b +arrayCat a b = Expr $ function "array_cat" [toExpr a, toExpr b] arrayDims :: (ExpressionOf Postgresql r a (Array elem)) => a -> Expr Postgresql r String arrayDims arr = Expr $ function "array_dims" [toExpr arr]
groundhog-postgresql.cabal view
@@ -1,5 +1,5 @@ name: groundhog-postgresql-version: 0.4.0.3+version: 0.4.1 license: BSD3 license-file: LICENSE author: Boris Lykah <lykahb@gmail.com>@@ -18,7 +18,7 @@ , bytestring >= 0.9 , blaze-builder >= 0.3.0.0 , transformers >= 0.2.1- , groundhog >= 0.4.0.3 && < 0.5.0+ , groundhog >= 0.4.1 && < 0.5.0 , monad-control >= 0.3 , monad-logger >= 0.3 , containers >= 0.2