Try out some basic sqlite stuff

This commit is contained in:
Joscha 2018-03-17 20:39:22 +00:00
parent 14c5a29aa4
commit 9a956785ef
3 changed files with 46 additions and 2 deletions

View file

@ -1,6 +1,8 @@
module Main where
import Lib
import qualified Database.SQLite.Simple as DB
import qualified TaskMachine.Database as TMB
main :: IO ()
main = someFunc
main = DB.withConnection "test.db" TMB.initializeNewDB

View file

@ -21,6 +21,18 @@ description: Please see the README on Github at <https://github.com/Garm
dependencies:
- base >= 4.7 && < 5
- sqlite-simple
#- containers
#- unordered-containers
#- text
#- time
#- transformers
#- async
#- aeson
#- bytestring
#- stm
#- megaparsec
#- brick
library:
source-dirs: src

View file

@ -0,0 +1,30 @@
{-# LANGUAGE OverloadedStrings #-}
module TaskMachine.Database
( initializeNewDB
) where
--import qualified Data.Text as T
import qualified Database.SQLite.Simple as DB
initializeNewDB :: DB.Connection -> IO ()
initializeNewDB c = do
DB.execute_ c createTaskTable
DB.execute_ c createVersionTable
DB.execute c fillVersionTable (DB.Only (1 :: Integer))
where
createTaskTable =
"CREATE TABLE IF NOT EXISTS tasks (\
\ id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\
\ deadline TEXT,\
\ formula TEXT,\
\ description TEXT NOT NULL,\
\ repetitions_total INTEGER NOT NULL DEFAULT 1,\
\ repetitions_done INTEGER NOT NULL DEFAULT 0\
\)"
createVersionTable =
"CREATE TABLE version (\
\ version_number INTEGER\
\)"
fillVersionTable =
"INSERT INTO version (version_number) VALUES (?)"