git.mcksp
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
module Repos.Characters
    ( getAll
    , create
    ) where

import Database.SQLite.Simple (Only(..))
import Database.SQLite.Simple.QQ
import Models
import Data.Text
import Repos.Utils
import Types

getAll :: (CanDB m, HasAuth m) => m [Character]
getAll = do
    userId <- getAuthUserId
    query [sql|
        select id, user_id, name, description, created_at
        from characters
        where user_id = (?)
        |] (Only userId)

create :: (CanDB m, HasAuth m) => Text -> Text -> Text -> m DbR
create cId name desc = do
    userId <- getAuthUserId
    execute [sql|
        insert into characters(id, user_id, name, description, created_at)
        values (?, ?, ?, ?, datetime())
        |] (cId, userId, name, desc)