{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Database.Persist.Sql.Instances
  (
  ) where

import ClassyPrelude.Yesod

import Data.Binary (Binary)
import qualified Data.Binary as B

import Database.Persist.Sql


instance Binary (BackendKey SqlWriteBackend) where
  put = B.put . unSqlWriteBackendKey
  putList = B.putList . map unSqlWriteBackendKey
  get = SqlWriteBackendKey <$> B.get
instance Binary (BackendKey SqlReadBackend) where
  put = B.put . unSqlReadBackendKey
  putList = B.putList . map unSqlReadBackendKey
  get = SqlReadBackendKey <$> B.get
instance Binary (BackendKey SqlBackend) where
  put = B.put . unSqlBackendKey
  putList = B.putList . map unSqlBackendKey
  get = SqlBackendKey <$> B.get
  

instance {-# OVERLAPPABLE #-} ToBackendKey SqlBackend record => Binary (Key record) where
  put = B.put . fromSqlKey
  putList = B.putList . map fromSqlKey
  get = toSqlKey <$> B.get
