-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An extensible mysql effect using extensible-effects and mysql-simple -- -- Any help (especially documentation) is very welcome, @package mysql-effect @version 0.2.0.2 -- | A thin MySQL effect. -- -- See the documentation of 'mysql-simple' for details regarding the -- various functions. module Control.Eff.MySQL -- | See query for details. query :: (SetMember Lift (Lift IO) r, Member MySQL r, QueryResults a, QueryParams p) => Query -> p -> Eff r [a] -- | See query_ for details. query_ :: (SetMember Lift (Lift IO) r, Member MySQL r, QueryResults a) => Query -> Eff r [a] -- | See execute for details. execute :: (SetMember Lift (Lift IO) r, Member MySQL r, QueryParams p) => Query -> p -> Eff r Int64 -- | See execute_ for details. execute_ :: (SetMember Lift (Lift IO) r, Member MySQL r) => Query -> Eff r Int64 -- | See executeMany for details. executeMany :: (SetMember Lift (Lift IO) r, Member MySQL r, QueryParams p) => Query -> [p] -> Eff r Int64 -- | See 'M.insertID ' for details. insertID :: (SetMember Lift (Lift IO) r, Member MySQL r) => Eff r Word64 -- | See 'M.autocommit ' for details. autocommit :: (SetMember Lift (Lift IO) r, Member MySQL r) => Bool -> Eff r () -- | See 'M.commit ' for details. commit :: (SetMember Lift (Lift IO) r, Member MySQL r) => Eff r () -- | See 'M.rollback ' for details. rollback :: (SetMember Lift (Lift IO) r, Member MySQL r) => Eff r () -- | See formatMany for details. formatMany :: (SetMember Lift (Lift IO) r, Member MySQL r, QueryParams p) => Query -> [p] -> Eff r ByteString -- | See formatQuery for details. formatQuery :: (SetMember Lift (Lift IO) r, Member MySQL r, QueryParams p) => Query -> p -> Eff r ByteString -- | Run the MySQL effect. In case of exceptions it will not close the -- connection. (That will still be done by the GC at one point.) runMySQL :: SetMember Lift (Lift IO) r => Eff (MySQL :> r) a -> ConnectInfo -> Eff r a -- | Run the MySQL effect with a given Connection. runMySQLWithConnection :: Eff (MySQL :> r) a -> Connection -> Eff r a data ConnectInfo :: * ConnectInfo :: String -> Word16 -> String -> String -> String -> [Option] -> FilePath -> Maybe SSLInfo -> ConnectInfo connectHost :: ConnectInfo -> String connectPort :: ConnectInfo -> Word16 connectUser :: ConnectInfo -> String connectPassword :: ConnectInfo -> String connectDatabase :: ConnectInfo -> String connectOptions :: ConnectInfo -> [Option] connectPath :: ConnectInfo -> FilePath connectSSL :: ConnectInfo -> Maybe SSLInfo -- | Wrap a list of values for use in an IN clause. Replaces a -- single "?" character with a parenthesized list of rendered -- values. -- -- Example: -- --
--   query c "select * from whatever where id in ?" (In [3,4,5])
--   
newtype In a :: * -> * In :: a -> In a -- | A single-value "collection". -- -- This is useful if you need to supply a single parameter to a SQL -- query, or extract a single column from a SQL result. -- -- Parameter example: -- --
--   query c "select x from scores where x > ?" (Only (42::Int))
--   
-- -- Result example: -- --
--   xs <- query_ c "select id from users"
--   forM_ xs $ \(Only id) -> {- ... -}
--   
newtype Only a :: * -> * Only :: a -> Only a fromOnly :: Only a -> a -- | A query string. This type is intended to make it difficult to -- construct a SQL query by concatenating string fragments, as that is an -- extremely common way to accidentally introduce SQL injection -- vulnerabilities into an application. -- -- This type is an instance of IsString, so the easiest way to -- construct a query is to enable the OverloadedStrings language -- extension and then simply write the query in double quotes. -- --
--   {-# LANGUAGE OverloadedStrings #-}
--   
--   import Database.MySQL.Simple
--   
--   q :: Query
--   q = "select ?"
--   
-- -- The underlying type is a ByteString, and literal Haskell -- strings that contain Unicode characters will be correctly transformed -- to UTF-8. data Query :: * -- | A collection type that can be turned into a list of rendering -- Actions. -- -- Instances should use the render method of the Param -- class to perform conversion of each element of the collection. class QueryParams a renderParams :: QueryParams a => a -> [Action] -- | A collection type that can be converted from a list of strings. -- -- Instances should use the convert method of the Result -- class to perform conversion of each element of the collection. -- -- This example instance demonstrates how to convert a two-column row -- into a Haskell pair. Each field in the metadata is paired up with each -- value from the row, and the two are passed to convert. -- --
--   instance (Result a, Result b) => QueryResults (a,b) where
--       convertResults [fa,fb] [va,vb] = (a,b)
--           where !a = convert fa va
--                 !b = convert fb vb
--       convertResults fs vs  = convertError fs vs 2
--   
-- -- Notice that this instance evaluates each element to WHNF before -- constructing the pair. By doing this, we guarantee two important -- properties: -- -- -- -- You can also declare Haskell types of your own to be instances of -- QueryResults. -- --
--   data User = User { firstName :: String, lastName :: String }
--   
--   instance QueryResults User where
--       convertResults [fa,fb] [va,vb] = User $ a * b
--           where !a = convert fa va
--                 !b = convert fb vb
--       convertResults fs vs  = convertError fs vs 2
--   
class QueryResults a convertResults :: QueryResults a => [Field] -> [Maybe ByteString] -> a -- | Default information for setting up a connection. -- -- Defaults are as follows: -- -- -- -- Use as in the following example: -- --
--   connect defaultConnectInfo { connectHost = "db.example.com" }
--   
defaultConnectInfo :: ConnectInfo