packages feed

persistent-mysql 2.1.2.1 → 2.1.3

raw patch · 3 files changed

+34/−13 lines, 3 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Database.Persist.MySQL: instance Show MySQLConf
- Database.Persist.MySQL: withMySQLConn :: (MonadBaseControl IO m, MonadIO m, MonadLogger m) => ConnectInfo -> (Connection -> m a) -> m a
+ Database.Persist.MySQL: withMySQLConn :: (MonadBaseControl IO m, MonadIO m, MonadLogger m) => ConnectInfo -> (SqlBackend -> m a) -> m a

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## Master++Added a `Show` instance for `MySQLConf`.+ ## 2.1.2.1  Documentation typo fix
Database/Persist/MySQL.hs view
@@ -27,6 +27,7 @@ import Data.IORef import Data.List (find, intercalate, sort, groupBy) import Data.Text (Text, pack)+import Text.Read (readMaybe) import System.Environment (getEnvironment) import Data.Acquire (Acquire, mkAcquire, with) @@ -84,7 +85,7 @@ withMySQLConn :: (MonadBaseControl IO m, MonadIO m, MonadLogger m) =>                  MySQL.ConnectInfo               -- ^ Connection information.-              -> (Connection -> m a)+              -> (SqlBackend -> m a)               -- ^ Action to be executed that uses the connection.               -> m a withMySQLConn = withSqlConn . open'@@ -299,7 +300,7 @@         let uniques = flip concatMap udspair $ \(uname, ucols) ->                       [ AlterTable name $                         AddUniqueConstraint uname $-                        map (findTypeOfColumn allDefs name) ucols ]+                        map (findTypeAndMaxLen name) ucols ]         let foreigns = do               Column { cName=cname, cReference=Just (refTblName, a) } <- newcols               return $ AlterColumn name (refTblName, addReference allDefs (refName name cname) refTblName cname)@@ -322,7 +323,12 @@       -- Errors       (_, _, (errs, _)) -> return $ Left errs +      where+        findTypeAndMaxLen tblName col = let (col', ty) = findTypeOfColumn allDefs tblName col+                                            (_, ml) = findMaxLenOfColumn allDefs tblName col+                                         in (col', ty, ml) + -- | Find out the type of a column. findTypeOfColumn :: [EntityDef] -> DBName -> DBName -> (DBName, FieldType) findTypeOfColumn allDefs name col =@@ -334,6 +340,15 @@             fieldDef <- find ((== col)  . fieldDB) (entityFields entDef)             return (fieldType fieldDef) +-- | Find out the maxlen of a column (default to 200)+findMaxLenOfColumn :: [EntityDef] -> DBName -> DBName -> (DBName, Integer)+findMaxLenOfColumn allDefs name col =+   maybe (col, 200)+         ((,) col) $ do+           entDef     <- find ((== name) . entityDB) allDefs+           fieldDef   <- find ((== col) . fieldDB) (entityFields entDef)+           maxLenAttr <- find ((T.isPrefixOf "maxlen=") . T.toLower) (fieldAttrs fieldDef)+           readMaybe . T.unpack . T.drop 7 $ maxLenAttr  -- | Helper for 'AddRefence' that finds out the 'entityId'. addReference :: [EntityDef] -> DBName -> DBName -> DBName -> AlterColumn@@ -356,7 +371,7 @@  type AlterColumn' = (DBName, AlterColumn) -data AlterTable = AddUniqueConstraint DBName [(DBName, FieldType)]+data AlterTable = AddUniqueConstraint DBName [(DBName, FieldType, Integer)]                 | DropUniqueConstraint DBName  data AlterDB = AddTable String@@ -571,16 +586,18 @@     getAltersU ((name, cols):news) old =         case lookup name old of             Nothing ->-                AddUniqueConstraint name (map findType cols) : getAltersU news old+                AddUniqueConstraint name (map findTypeAndMaxLen cols) : getAltersU news old             Just ocols ->                 let old' = filter (\(x, _) -> x /= name) old                  in if sort cols == ocols                         then getAltersU news old'                         else  DropUniqueConstraint name-                            : AddUniqueConstraint name (map findType cols)+                            : AddUniqueConstraint name (map findTypeAndMaxLen cols)                             : getAltersU news old'         where-          findType = findTypeOfColumn allDefs tblName+          findTypeAndMaxLen col = let (col', ty) = findTypeOfColumn allDefs tblName col+                                      (_, ml) = findMaxLenOfColumn allDefs tblName col+                                   in (col', ty, ml)   -- | @findAlters newColumn oldColumns@ finds out what needs to be@@ -681,10 +698,10 @@     , ")"     ]     where-      escapeDBName' (name, (FTTypeCon _ "Text"      )) = escapeDBName name ++ "(200)"-      escapeDBName' (name, (FTTypeCon _ "String"    )) = escapeDBName name ++ "(200)"-      escapeDBName' (name, (FTTypeCon _ "ByteString")) = escapeDBName name ++ "(200)"-      escapeDBName' (name, _                       ) = escapeDBName name+      escapeDBName' (name, (FTTypeCon _ "Text"      ), maxlen) = escapeDBName name ++ "(" ++ show maxlen ++ ")"+      escapeDBName' (name, (FTTypeCon _ "String"    ), maxlen) = escapeDBName name ++ "(" ++ show maxlen ++ ")"+      escapeDBName' (name, (FTTypeCon _ "ByteString"), maxlen) = escapeDBName name ++ "(" ++ show maxlen ++ ")"+      escapeDBName' (name, _                         , _) = escapeDBName name showAlterTable table (DropUniqueConstraint cname) = concat     [ "ALTER TABLE "     , escapeDBName table@@ -790,7 +807,7 @@       -- ^ The connection information.     , myPoolSize :: Int       -- ^ How many connections should be held on the connection pool.-    }+    } deriving Show  instance FromJSON MySQLConf where     parseJSON = withObject "MySQLConf" $ \o -> do
persistent-mysql.cabal view
@@ -1,5 +1,5 @@ name:            persistent-mysql-version:         2.1.2.1+version:         2.1.3 license:         MIT license-file:    LICENSE author:          Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman@@ -26,7 +26,7 @@ extra-source-files: ChangeLog.md  library-    build-depends:   base                  >= 4        && < 5+    build-depends:   base                  >= 4.6        && < 5                    , transformers          >= 0.2.1                    , mysql-simple          >= 0.2.2.3  && < 0.3                    , mysql                 >= 0.1.1.3  && < 0.2