createArticle :: Title -> Summary -> Content -> FromURL -> CreatedAt -> MySQL Int64
createArticle title summary content fromURL ct prefix conn = do
  oldID <- existsArticle fromURL prefix conn
  ct' <- if ct > 0 then return ct else liftIO $ read . show . toEpochTime <$> getUnixTime
  case oldID of
    Just id -> return id
    Nothing -> do
      void $ execute conn sql (title, summary, content, fromURL, fromURLHash, ct')
      fromIntegral <$> insertID conn
  where fromURLHash = hex $ hash (pack fromURL)
        sql = fromString $ concat [ "INSERT INTO `", prefix, "_articles` "
                                  , "(`title`, `summary`, `content`, `from_url`,"
                                  , " `from_url_hash`, `created_at`)"
                                  , " VALUES "
                                  , "( ?, ?, ?, ?, ?, ?)"
                                  ]
createArticle :: Title -> Summary -> Content -> FromURL -> CreatedAt -> MySQL Int64
createArticle title summary content fromURL ct prefix conn = do
  oldID <- existsArticle fromURL prefix conn
  ct' <- if ct > 0 then return ct else liftIO $ read . show . toEpochTime <$> getUnixTime
  case oldID of
    Just id -> return id
    Nothing -> do
      void $ execute conn sql (title, summary, content, fromURL, fromURLHash, ct')
      fromIntegral <$> insertID conn
  where fromURLHash = hex $ hash (pack fromURL)
        sql = fromString $ concat [ "INSERT INTO `", prefix, "_articles` "
                                  , "(`title`, `summary`, `content`, `from_url`,"
                                  , " `from_url_hash`, `created_at`)"
                                  , " VALUES "
                                  , "( ?, ?, ?, ?, ?, ?)"
                                  ]
createArticle title summary content fromURL ct prefix conn = do
  oldID <- existsArticle fromURL prefix conn
  ct' <- if ct > 0 then return ct else liftIO $ read . show . toEpochTime <$> getUnixTime
  case oldID of
    Just id -> return id
    Nothing -> do
      void $ execute conn sql (title, summary, content, fromURL, fromURLHash, ct')
      fromIntegral <$> insertID conn
  where fromURLHash = hex $ hash (pack fromURL)
        sql = fromString $ concat [ "INSERT INTO `", prefix, "_articles` "
                                  , "(`title`, `summary`, `content`, `from_url`,"
                                  , " `from_url_hash`, `created_at`)"
                                  , " VALUES "
                                  , "( ?, ?, ?, ?, ?, ?)"
                                  ]