mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-11-29 06:37:03 +03:00
Add Persistable instances for HDBC.
This commit is contained in:
parent
1d1cefbc19
commit
014577815d
32
schema-th/src/Database/HDBC/Record/Persistable.hs
Normal file
32
schema-th/src/Database/HDBC/Record/Persistable.hs
Normal file
@ -0,0 +1,32 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
|
||||
module Database.HDBC.Record.Persistable (
|
||||
persistableSingleton
|
||||
) where
|
||||
|
||||
import Database.Record.Persistable
|
||||
(Singleton, singleton, runSingleton,
|
||||
persistableNullValue, PersistableNull (..),
|
||||
PersistableValue, persistableValue,
|
||||
PersistableRecord, persistableRecordFromValue,
|
||||
Persistable (persistable))
|
||||
|
||||
import Data.Convertible (Convertible)
|
||||
import Database.HDBC (SqlValue(SqlNull), fromSql, toSql)
|
||||
|
||||
persistableSqlValue :: (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> PersistableValue SqlValue (Singleton a)
|
||||
persistableSqlValue = persistableValue (singleton . fromSql) (toSql . runSingleton)
|
||||
|
||||
persistableSingleton :: (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> PersistableRecord SqlValue (Singleton a)
|
||||
persistableSingleton = persistableRecordFromValue persistableSqlValue
|
||||
|
||||
instance PersistableNull SqlValue where
|
||||
persistableNull = persistableNullValue SqlNull
|
||||
|
||||
instance (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> Persistable SqlValue (Singleton a) where
|
||||
persistable = persistableSingleton
|
Loading…
Reference in New Issue
Block a user