persistent-mysql 1.2.0 → 1.2.1
raw patch · 2 files changed
+40/−33 lines, 2 filesdep +blaze-builderPVP ok
version bump matches the API change (PVP)
Dependencies added: blaze-builder
API changes (from Hackage documentation)
Files
- Database/Persist/MySQL.hs +38/−32
- persistent-mysql.cabal +2/−1
Database/Persist/MySQL.hs view
@@ -22,6 +22,7 @@ import Data.Aeson import Data.ByteString (ByteString) import Data.Either (partitionEithers)+import Data.Fixed (Pico) import Data.Function (on) import Data.IORef import Data.List (find, intercalate, sort, groupBy)@@ -29,6 +30,7 @@ import System.Environment (getEnvironment) import Data.Conduit+import qualified Blaze.ByteString.Builder.Char8 as BBB import qualified Data.Conduit.List as CL import qualified Data.Map as Map import qualified Data.Text as T@@ -149,33 +151,33 @@ -> [PersistValue] -> Source m [PersistValue] withStmt' conn query vals =- bracketP openS closeS pull+ bracketP createResult MySQLBase.freeResult fetchRows >>= CL.sourceList where- openS = do+ createResult = do -- Execute the query- MySQLBase.query conn =<< MySQL.formatQuery conn query (map P vals)- result <- MySQLBase.storeResult conn+ formatted <- MySQL.formatQuery conn query (map P vals)+ MySQLBase.query conn formatted+ MySQLBase.storeResult conn + fetchRows result = liftIO $ do -- Find out the type of the columns fields <- MySQLBase.fetchFields result let getters = [ maybe PersistNull (getGetter (MySQLBase.fieldType f) f . Just) | f <- fields]+ convert = use getters+ where use (g:gs) (col:cols) =+ let v = g col+ vs = use gs cols+ in v `seq` vs `seq` (v:vs)+ use _ _ = [] -- Ready to go!- return (result, getters)-- closeS (result, _) = MySQLBase.freeResult result-- pull x = do- y <- liftIO $ pullS x- case y of- Nothing -> return ()- Just z -> yield z >> pull x-- pullS (result, getters) = do- row <- MySQLBase.fetchRow result- case row of- [] -> return Nothing -- Do not free the result per sourceIO's docs.- _ -> return $ Just $ zipWith ($) getters row+ let go acc = do+ row <- MySQLBase.fetchRow result+ case row of+ [] -> return (acc [])+ _ -> let converted = convert row+ in converted `seq` go (acc . (converted:))+ go id -- | @newtype@ around 'PersistValue' that supports the@@ -195,6 +197,9 @@ render (P PersistNull) = MySQL.render MySQL.Null render (P (PersistList l)) = MySQL.render $ listToJSON l render (P (PersistMap m)) = MySQL.render $ mapToJSON m+ render (P (PersistRational r)) =+ MySQL.Plain $ BBB.fromString $ show (fromRational r :: Pico)+ -- FIXME: Too Ambigous, can not select precision without information about field render (P (PersistObjectId _)) = error "Refusing to serialize a PersistObjectId to a MySQL value" @@ -606,19 +611,20 @@ showSqlType :: SqlType -> Maybe Integer -- ^ @maxlen@ -> String-showSqlType SqlBlob Nothing = "BLOB"-showSqlType SqlBlob (Just i) = "VARBINARY(" ++ show i ++ ")"-showSqlType SqlBool _ = "TINYINT(1)"-showSqlType SqlDay _ = "DATE"-showSqlType SqlDayTime _ = "DATETIME"-showSqlType SqlDayTimeZoned _ = "VARCHAR(50) CHARACTER SET utf8"-showSqlType SqlInt32 _ = "INT"-showSqlType SqlInt64 _ = "BIGINT"-showSqlType SqlReal _ = "DOUBLE PRECISION"-showSqlType SqlString Nothing = "TEXT CHARACTER SET utf8"-showSqlType SqlString (Just i) = "VARCHAR(" ++ show i ++ ") CHARACTER SET utf8"-showSqlType SqlTime _ = "TIME"-showSqlType (SqlOther t) _ = T.unpack t+showSqlType SqlBlob Nothing = "BLOB"+showSqlType SqlBlob (Just i) = "VARBINARY(" ++ show i ++ ")"+showSqlType SqlBool _ = "TINYINT(1)"+showSqlType SqlDay _ = "DATE"+showSqlType SqlDayTime _ = "DATETIME"+showSqlType SqlDayTimeZoned _ = "VARCHAR(50) CHARACTER SET utf8"+showSqlType SqlInt32 _ = "INT"+showSqlType SqlInt64 _ = "BIGINT"+showSqlType SqlReal _ = "DOUBLE PRECISION"+showSqlType (SqlNumeric s prec) _ = "NUMERIC(" ++ show s ++ "," ++ show prec ++ ")"+showSqlType SqlString Nothing = "TEXT CHARACTER SET utf8"+showSqlType SqlString (Just i) = "VARCHAR(" ++ show i ++ ") CHARACTER SET utf8"+showSqlType SqlTime _ = "TIME"+showSqlType (SqlOther t) _ = T.unpack t -- | Render an action that must be done on the database. showAlterDb :: AlterDB -> (Bool, Text)
persistent-mysql.cabal view
@@ -1,5 +1,5 @@ name: persistent-mysql-version: 1.2.0+version: 1.2.1 license: MIT license-file: LICENSE author: Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman@@ -28,6 +28,7 @@ , transformers >= 0.2.1 , mysql-simple >= 0.2.2.3 && < 0.3 , mysql >= 0.1.1.3 && < 0.2+ , blaze-builder , persistent >= 1.2 && < 1.3 , containers >= 0.2 , bytestring >= 0.9