Add an importer binary.

This commit is contained in:
Dhananjay Balan
2023-04-13 23:43:39 +02:00
parent 11c4e92cc7
commit 72b3e38980
6 changed files with 117 additions and 16 deletions

25
lib/Database.hs Normal file
View File

@@ -0,0 +1,25 @@
{-# LANGUAGE QuasiQuotes #-}
module Database where
import Database.SQLite.Simple.QQ
import Database.SQLite.Simple
import Api.Types
initDb :: FilePath -> IO ()
initDb dbFile = withConnection dbFile $ \conn ->
execute_ conn
[sql|CREATE TABLE IF NOT EXISTS quotes ( quote text non null
, author text
, title text
, page text
, chapter text
, created_on integer);|]
insertQts :: FilePath -> [Quote] -> IO ()
insertQts db qts = do
withConnection db $ \c ->
executeMany c qry qts
where
qry = [sql|INSERT INTO quotes VALUES (?,?,?,?,?,?);|]