aboutsummaryrefslogtreecommitdiff
path: root/server/src/Thermoprint/Server/Database.hs
blob: 5bd451234c0abe946efc25acfab7b5f1b100a1c6 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE QuasiQuotes                #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE ExistentialQuantification  #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE FlexibleInstances          #-}

module Thermoprint.Server.Database
       ( Job(..), JobId
       , Draft(..), DraftId
       , Key(..)
       , migrateAll
       ) where

import Control.DeepSeq

import Thermoprint.API (Printout, DraftTitle, JobStatus, castId)

import Database.Persist.TH
import Database.Persist.Sql (unSqlBackendKey, SqlBackend)
import Database.Persist.Class (Key, BackendKey)

import Thermoprint.Server.Database.Instances

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Job
    content Printout
Draft
    title DraftTitle Maybe
    content Printout
|]

deriving instance Enum     (Key Job)
deriving instance Num      (Key Job)
deriving instance Real     (Key Job)
deriving instance Integral (Key Job)

deriving instance Enum     (Key Draft)
deriving instance Num      (Key Draft)
deriving instance Real     (Key Draft)
deriving instance Integral (Key Draft)

instance NFData (Key Job) where
  rnf = rnf . unSqlBackendKey . unJobKey