persistent 0.2.2.2 → 0.2.3
raw patch · 3 files changed
+32/−2 lines, 3 files
Files
- Database/Persist/GenericSql.hs +30/−0
- Database/Persist/Quasi.hs +1/−1
- persistent.cabal +1/−1
Database/Persist/GenericSql.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE PackageImports #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- | This is a helper module for creating SQL backends. Regular users do not@@ -18,6 +19,7 @@ , runMigrationSilent , runMigrationUnsafe , migrate+ , mkMigrate ) where import Database.Persist.Base@@ -34,6 +36,7 @@ import "MonadCatchIO-transformers" Control.Monad.CatchIO import Control.Monad (liftM, unless) import Data.Enumerator hiding (map, length)+import Language.Haskell.TH.Syntax hiding (lift) type ConnectionPool = Pool Connection @@ -503,3 +506,30 @@ go (Left PersistNull) = [] go (Left x) = [x] go (Right xs) = filter (/= PersistNull) xs++-- | Creates a single function to perform all migrations for the entities+-- defined here. One thing to be aware of is dependencies: if you have entities+-- with foreign references, make sure to place those definitions after the+-- entities they reference.+mkMigrate :: String -> [EntityDef] -> Q [Dec]+mkMigrate fun defs = do+ body' <- body+ return+ [ SigD (mkName fun) typ+ , FunD (mkName fun) [Clause [] (NormalB body') []]+ ]+ where+ typ = ForallT [PlainTV $ mkName "m"]+ [ ClassP ''MonadCatchIO [VarT $ mkName "m"]+ ]+ $ ConT ''Migration `AppT` (ConT ''SqlPersist `AppT` VarT (mkName "m"))+ body =+ case defs of+ [] -> [|return ()|]+ _ -> DoE `fmap` mapM toStmt defs+ toStmt ed = do+ let n = entityName ed+ u <- [|undefined|]+ m <- [|migrate|]+ let u' = SigE u $ ConT $ mkName n+ return $ NoBindS $ m `AppE` u'
Database/Persist/Quasi.hs view
@@ -43,7 +43,7 @@ s <- fmap (not . null) $ many space t <- many token eof- return (s, t)+ return (s, takeWhile (/= "--") t) where token = do t <- (char '"' >> quoted) <|> unquoted
persistent.cabal view
@@ -1,5 +1,5 @@ name: persistent-version: 0.2.2.2+version: 0.2.3 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>