<commit_before>{-# LANGUAGE DeriveDataTypeable, CPP #-}
module Jakway.Blackjack.IO.DatabaseCommon
(
createTables,
cardIdMap,
cardPermutations,
cardSqlArr,
cardsSqlValues,
cardToForeignKeyId,
idCardMap,
singleCardToSqlValues,
dropTables,
dropAllTables
)
where

import Jakway.Blackjack.Visibility
import Jakway.Blackjack.Cards
import Jakway.Blackjack.CardOps
import Database.HDBC
import qualified Data.Map.Strict as HashMap
import Control.Exception
import Data.Typeable
import Jakway.Blackjack.Util
import Jakway.Blackjack.IO.TableNames
import Jakway.Blackjack.IO.DatabaseConnection
import qualified Jakway.Blackjack.IO.RDBMS.Postgres as Postgres
import qualified Jakway.Blackjack.IO.RDBMS.SQLite as SQLite

#ifdef BUILD_POSTGRESQL
createTables :: IConnection a => a -> TableNames -> IO ()
createTables = Postgres.createTables
#else
createTables :: IConnection a => a -> TableNames -> IO ()
createTables = SQLite.createTables
#endif

dropAllTables :: IConnection a => a -> IO()
dropAllTables conn = withTransaction conn $ \t_conn -> getDropStatement t_conn >>= (\dropStatement -> 
                        getTableSQLValues t_conn >>= executeMany dropStatement )
        where getTableSQLValues p_conn = getTables p_conn >>= (\t -> return $ map (\x -> [toSql x]) t)
              getDropStatement p_conn = prepare p_conn $ "DROP TABLE ? "
              --cascade so we don't cause errors with foreign keys
#ifdef BUILD_POSTGRESQL
                                                        ++ "CASCADE"
#endif

dropTables :: IConnection a => a -> TableNames -> IO ()
dropTables conn tableNames = <commit_msg>delete newlines just in case<commit_after>{-# LANGUAGE DeriveDataTypeable, CPP #-}
module Jakway.Blackjack.IO.DatabaseCommon
(
createTables,
cardIdMap,
cardPermutations,
cardSqlArr,
cardsSqlValues,
cardToForeignKeyId,
idCardMap,
singleCardToSqlValues,
dropTables,
dropAllTables
)
where

import Jakway.Blackjack.Visibility
import Jakway.Blackjack.Cards
import Jakway.Blackjack.CardOps
import Database.HDBC
import qualified Data.Map.Strict as HashMap
import Control.Exception
import Data.Typeable
import Jakway.Blackjack.Util
import Jakway.Blackjack.IO.TableNames
import Jakway.Blackjack.IO.DatabaseConnection
import qualified Jakway.Blackjack.IO.RDBMS.Postgres as Postgres
import qualified Jakway.Blackjack.IO.RDBMS.SQLite as SQLite
import Control.Monad (join)

#ifdef BUILD_POSTGRESQL
createTables :: IConnection a => a -> TableNames -> IO ()
createTables = Postgres.createTables
#else
createTables :: IConnection a => a -> TableNames -> IO ()
createTables = SQLite.createTables
#endif

dropAllTables :: IConnection a => a -> IO()
dropAllTables conn = withTransaction conn $ \t_conn -> getDropStatement t_conn >>= (\dropStatement -> 
                        getTableSQLValues t_conn >>= executeMany dropStatement )
        where getTableSQLValues p_conn = getTables p_conn >>= (\t -> return $ map (\x -> [toSql x]) t)
              --remove newlines
              getDropStatement p_conn = prepare p_conn dropStr
              --see http://stackoverflow.com/questions/10050988/haskell-removes-all-occurrences-of-a-given-value-from-within-a-list-of-lists 
              dropStr = filter (== '\n') $ "DROP TABLE IF EXISTS ? " ++ cascadeStr 
              cascadeStr = 
              --cascade so we don't cause errors with foreign keys
#ifdef BUILD_POSTGRESQL
                            "CASCADE"
#else
                            ""
#endif

dropTables :: IConnection a => a -> TableNames -> IO ()
dropTables conn tableNames = 
{'fraction_non_alphanumeric': 0.09271335412531896, 'fraction_numerical': 0.0022682166146867026, 'mean_word_length': 3.4714828897338403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '661510', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1017, 'n_words': 274}