mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2025-01-05 20:04:49 +03:00
Rename persistable value record and add type class.
This commit is contained in:
parent
48c10bfd48
commit
a7fbbd6c2c
@ -14,14 +14,14 @@ module Database.Record.Persistable (
|
||||
Singleton(runSingleton), singleton,
|
||||
|
||||
PersistableNullValue(runPersistableNullValue), persistableNullValue,
|
||||
PersistableValue, persistableValue,
|
||||
PersistableSqlValue, persistableSqlValue,
|
||||
PersistableRecord, persistableRecord,
|
||||
toRecord, fromRecord, width,
|
||||
|
||||
persistableRecordFromValue,
|
||||
|
||||
PersistableNull(..), sqlNullValue,
|
||||
|
||||
PersistableValue (..),
|
||||
Persistable (..), takeRecord
|
||||
) where
|
||||
|
||||
@ -31,8 +31,8 @@ newtype PersistableNullValue q =
|
||||
PersistableNullValue
|
||||
{ runPersistableNullValue :: q }
|
||||
|
||||
data PersistableValue q a =
|
||||
PersistableValue
|
||||
data PersistableSqlValue q a =
|
||||
PersistableSqlValue
|
||||
{ toValue :: q -> a
|
||||
, fromValue :: a -> q
|
||||
}
|
||||
@ -50,13 +50,13 @@ singleton = Singleton
|
||||
persistableNullValue :: q -> PersistableNullValue q
|
||||
persistableNullValue = PersistableNullValue
|
||||
|
||||
persistableValue :: (q -> a) -> (a -> q) -> PersistableValue q a
|
||||
persistableValue = PersistableValue
|
||||
persistableSqlValue :: (q -> a) -> (a -> q) -> PersistableSqlValue q a
|
||||
persistableSqlValue = PersistableSqlValue
|
||||
|
||||
persistableRecord :: ([q] -> a) -> (a -> [q]) -> Int -> PersistableRecord q a
|
||||
persistableRecord = PersistableRecord
|
||||
|
||||
persistableRecordFromValue :: PersistableValue q a -> PersistableRecord q a
|
||||
persistableRecordFromValue :: PersistableSqlValue q a -> PersistableRecord q a
|
||||
persistableRecordFromValue pv =
|
||||
persistableRecord(toValue pv . head) ((:[]) . fromValue pv) 1
|
||||
|
||||
@ -66,6 +66,9 @@ class Eq q => PersistableNull q where
|
||||
sqlNullValue :: PersistableNull q => q
|
||||
sqlNullValue = runPersistableNullValue persistableNull
|
||||
|
||||
class PersistableValue q a where
|
||||
persistableValue :: PersistableSqlValue q a
|
||||
|
||||
class Persistable q a where
|
||||
persistable :: PersistableRecord q a
|
||||
|
||||
|
@ -9,16 +9,18 @@ module Database.HDBC.Record.Persistable (
|
||||
import Database.Record.Persistable
|
||||
(Singleton, singleton, runSingleton,
|
||||
persistableNullValue, PersistableNull (..),
|
||||
PersistableValue, persistableValue,
|
||||
PersistableSqlValue, -- persistableSqlValue,
|
||||
PersistableRecord, persistableRecordFromValue,
|
||||
PersistableValue (persistableValue),
|
||||
Persistable (persistable))
|
||||
import qualified Database.Record.Persistable as 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)
|
||||
=> PersistableSqlValue SqlValue (Singleton a)
|
||||
persistableSqlValue = Persistable.persistableSqlValue (singleton . fromSql) (toSql . runSingleton)
|
||||
|
||||
persistableSingleton :: (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> PersistableRecord SqlValue (Singleton a)
|
||||
@ -27,6 +29,10 @@ persistableSingleton = persistableRecordFromValue persistableSqlValue
|
||||
instance PersistableNull SqlValue where
|
||||
persistableNull = persistableNullValue SqlNull
|
||||
|
||||
instance (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> PersistableValue SqlValue (Singleton a) where
|
||||
persistableValue = persistableSqlValue
|
||||
|
||||
instance (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> Persistable SqlValue (Singleton a) where
|
||||
persistable = persistableSingleton
|
||||
|
Loading…
Reference in New Issue
Block a user