<commit_before>{-# LANGUAGE OverloadedStrings #-}

import Database.Persist (insert, get)
import Database.Persist.Sql (runMigration)
import Database.Persist.Sqlite (runSqlite)
import Database.Persist.Postgresql (withPostgresqlPool, runSqlPersistMPool)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Logger (runStdoutLoggingT)
import System.Environment (getArgs)

import Model

main :: IO ()
main = do
    args <- getArgs
    (if elem "pg" args
        then runPostgresql ""
        else runSqlite ":memory:") action

action = do
    runMigration migrateAll
    stringTopic <- insert $ Topic "String" ""
    howToString <- insert $ Concept (Just stringTopic) "How to string"
    stringGuide <- insert $ Resource {
        resourceTitle = "How does one string? All your questions answered.",
        resourceMedia = "text",
        resourceUrl   = "http://example.com/howtostring.html",
        resourceCourse = "Example.com Enterprise Programming Tutorials",
        resourceSummary = "blah blah blah",
        resourcePreview = "blah blah blah",
        resourceKeywords = "strings, stringing, str"
     }
    string <- get stringGuide
    liftIO $ print string

runPostgresql connStr action
    = runStdoutLoggingT $ withPostgresqlPool connStr 1 $ \pool ->
        liftIO $ flip runSqlPersistMPool pool $ action<commit_msg>If we have a database URL, use it - otherwise use SQLite.<commit_after>{-# LANGUAGE OverloadedStrings #-}

import Database.Persist (insert, get)
import Database.Persist.Sql (runMigration)
import Database.Persist.Sqlite (runSqlite)
import Database.Persist.Postgresql (withPostgresqlPool, runSqlPersistMPool)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Logger (runStdoutLoggingT)
import System.Environment (lookupEnv)
import Data.String (fromString)

import Model

main :: IO ()
main = do
    connStr <- lookupEnv "DATABASE_URL"
    let runDB = case connStr of
            Nothing -> runSqlite ":memory:"
            Just cs -> runPostgresql (fromString cs)
    runDB action

action = do
    runMigration migrateAll
    stringTopic <- insert $ Topic "String" ""
    howToString <- insert $ Concept (Just stringTopic) "How to string"
    stringGuide <- insert $ Resource {
        resourceTitle = "How does one string? All your questions answered.",
        resourceMedia = "text",
        resourceUrl   = "http://example.com/howtostring.html",
        resourceCourse = "Example.com Enterprise Programming Tutorials",
        resourceSummary = "blah blah blah",
        resourcePreview = "blah blah blah",
        resourceKeywords = "strings, stringing, str"
     }
    string <- get stringGuide
    liftIO $ print string

runPostgresql connStr action
    = runStdoutLoggingT $ withPostgresqlPool connStr 1 $ \pool ->
        liftIO $ flip runSqlPersistMPool pool $ action
{'fraction_non_alphanumeric': 0.09110244594115562, 'fraction_numerical': 0.0007089684509039348, 'mean_word_length': 3.4231974921630095, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2297470', 'n_tokens_mistral': 832, 'n_tokens_neox': 800, 'n_words': 242}