import System.Random (randomIO)
import Data.Time.Clock (getCurrentTime, UTCTime)
import Database.HDBC
import Database.HDBC.PostgreSQL
import Database.NySQL.TH
import Database.NySQL.Options
import Control.Monad
import Control.Monad.Trans
import Control.Exception

import Control.Monad.Catch

$(mkSqlWith (defOpts { paramModifier = ('_':) }) "src/sql/createUser.sql")

main :: IO ()
main = do

  c <- connectPostgreSQL "dbname=example host=localhost user=postgres password=postgres"
  n <- getCurrentTime

  k0 :: Int <- randomIO
  k1 :: Int <- randomIO

  void $ runStmt c CreateUser
    { _key        = show k0
    , _username   = "jsmith"
    , _password   = "Testing0123"
    , _first_name = "John"
    , _last_name  = "Smith"
    , _created_on = n
    , _deleted_on = Nothing :: Maybe UTCTime
    }

  void $ runStmt c CreateUser
    { _key        = show k1
    , _username   = "jsmith"
    , _password   = "Testing0123"
    , _first_name = "John"
    , _last_name  = "Smith"
    , _created_on = n
    , _deleted_on = Nothing :: Maybe UTCTime
    }
