snaplet-mysql-simple 0.2.0.3 → 0.2.1.0
raw patch · 5 files changed
+24/−27 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Changelog.md +4/−0
- resources/db/devel.cfg +2/−2
- snaplet-mysql-simple.cabal +1/−1
- src/Snap/Snaplet/Auth/Backends/MysqlSimple.hs +15/−22
- src/Snap/Snaplet/MysqlSimple.hs +2/−2
Changelog.md view
@@ -1,3 +1,7 @@+## Version 0.2.1.0++Fix Snap.Snaplet.Auth.Backends.MysqlSimple, courtesty of klasske.+ ## Version 0.2 Do not export `withTransaction` as it was broken. It needs a different kind
resources/db/devel.cfg view
@@ -1,8 +1,8 @@ host = "localhost" port = 3306 user = "mysql"-pass = ""-db = "testdb"+password = ""+dbname = "testdb" # Nmuber of distinct connection pools to maintain. The smallest acceptable # value is 1.
snaplet-mysql-simple.cabal view
@@ -1,5 +1,5 @@ name: snaplet-mysql-simple-version: 0.2.0.3+version: 0.2.1.0 synopsis: mysql-simple snaplet for the Snap Framework description: This snaplet contains support for using the MariaDB and MySQL database with a Snap Framework application via the mysql-simple
src/Snap/Snaplet/Auth/Backends/MysqlSimple.hs view
@@ -98,26 +98,21 @@ ------------------------------------------------------------------------------ -- | Create the user table if it doesn't exist.--- XXX: Check sql createTableIfMissing :: MysqlAuthManager -> IO () createTableIfMissing MysqlAuthManager{..} = do withResource pamConnPool $ \conn -> do- res <- M.query_ conn $ Query $ T.encodeUtf8 $- "select relname from pg_class where relname='"- `T.append` schemaless (tblName pamTable) `T.append` "'"- when (null (res :: [Only T.Text])) $- M.execute_ conn (Query $ T.encodeUtf8 q) >> return ()+ M.execute_ conn (Query $ T.encodeUtf8 q) return () where- schemaless = T.reverse . T.takeWhile (/='.') . T.reverse q = T.concat- [ "CREATE TABLE \""+ [ "CREATE TABLE IF NOT EXISTS " , tblName pamTable- , "\" ("- , T.intercalate "," (map (fDesc . ($pamTable) . (fst)) colDef)+ , "("+ , T.intercalate ", " (map (fDesc . ($pamTable) . (fst)) colDef) , ")" ] + buildUid :: Int -> UserId buildUid = UserId . T.pack . show @@ -173,7 +168,7 @@ !_userResetRequestedAt = convert f18 b18 !_userRoles = [] !_userMeta = HM.empty- convertResults fs vs = convertError fs vs 18+ convertResults fs vs = convertError fs vs 19 querySingle :: (QueryParams q, QueryResults a)@@ -223,22 +218,22 @@ = AuthTable { tblName = "snap_auth_user" , colId = ("uid", "SERIAL PRIMARY KEY")- , colLogin = ("login", "VARCHAR UNIQUE NOT NULL")- , colEmail = ("email", "VARCHAR")- , colPassword = ("password", "VARCHAR")+ , colLogin = ("login", "VARCHAR(255) UNIQUE NOT NULL")+ , colEmail = ("email", "VARCHAR(255)")+ , colPassword = ("password", "VARCHAR(255)") , colActivatedAt = ("activated_at", "TIMESTAMP") , colSuspendedAt = ("suspended_at", "TIMESTAMP")- , colRememberToken = ("remember_token", "VARCHAR")+ , colRememberToken = ("remember_token", "VARCHAR(255)") , colLoginCount = ("login_count", "INTEGER NOT NULL") , colFailedLoginCount = ("failed_login_count", "INTEGER NOT NULL") , colLockedOutUntil = ("locked_out_until", "TIMESTAMP") , colCurrentLoginAt = ("current_login_at", "TIMESTAMP") , colLastLoginAt = ("last_login_at", "TIMESTAMP")- , colCurrentLoginIp = ("current_login_ip", "VARCHAR")- , colLastLoginIp = ("last_login_ip", "VARCHAR")+ , colCurrentLoginIp = ("current_login_ip", "VARCHAR(255)")+ , colLastLoginIp = ("last_login_ip", "VARCHAR(255)") , colCreatedAt = ("created_at", "TIMESTAMP") , colUpdatedAt = ("updated_at", "TIMESTAMP")- , colResetToken = ("reset_token", "VARCHAR")+ , colResetToken = ("reset_token", "VARCHAR(255)") , colResetRequestedAt = ("reset_requested_at", "TIMESTAMP") , rolesTable = "user_roles" }@@ -308,10 +303,8 @@ let (qstr, params) = saveQuery pamTable u let q = Query $ T.encodeUtf8 qstr let action = withResource pamConnPool $ \conn -> do- _ <- M.execute conn q params- newUid <- M.insertID conn- return . Right $- u{ userId = Just $ buildUid $ fromIntegral newUid}+ res <- M.query conn q params+ return $ Right $ fromMaybe u $ listToMaybe res E.catch action onFailure
src/Snap/Snaplet/MysqlSimple.hs view
@@ -132,7 +132,7 @@ ------------------------------------------------------------------------------ -- | The state for the mysql-simple snaplet. To use it in your app--- include this in your application state and use pgsInit to initialize it.+-- include this in your application state and use mysqlInit to initialize it. data Mysql = Mysql { mysqlPool :: Pool M.Connection -- ^ Function for retrieving the connection pool@@ -159,7 +159,7 @@ -- | A convenience instance to make it easier to use this snaplet in the -- Initializer monad like this: ----- > d <- nestSnaplet "db" db pgsInit+-- > d <- nestSnaplet "db" db mysqlInit -- > count <- liftIO $ runReaderT (execute "INSERT ..." params) d instance (MonadCatchIO m) => HasMysql (ReaderT (Snaplet Mysql) m) where getMysqlState = asks (^# snapletValue)