Debug LoginAttempts.increment
When this was an UPDATE statement with a WHERE clause, and the LoginAttempts table was vacant, nothing would happen. Thankfully, SQLite supports an UPSERT clause so that I can INSERT a new record or UPDATE conditionally. And the best part is: it works!
This commit is contained in:
parent
8ebc89b44b
commit
ea31a01497
1 changed files with 3 additions and 2 deletions
|
@ -23,7 +23,8 @@ forUsername dbFile username = withConnection dbFile $ \conn -> do
|
|||
[T.LoginAttempt{..}] -> pure (Just loginAttemptNumAttempts)
|
||||
_ -> pure Nothing
|
||||
|
||||
-- | INSERT a failed login attempt for `username` or UPDATE an existing entry.
|
||||
increment :: FilePath -> T.Username -> IO ()
|
||||
increment dbFile username = withConnection dbFile $ \conn ->
|
||||
execute conn "UPDATE LoginAttempts SET numAttempts = numAttempts + 1 WHERE username = ?"
|
||||
(Only username)
|
||||
execute conn "INSERT INTO LoginAttempts (username,numAttempts) VALUES (?,?) ON CONFLICT (username) DO UPDATE SET numAttempts = numAttempts + 1"
|
||||
(username, 1 :: Integer)
|
||||
|
|
Loading…
Reference in a new issue