mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-12 12:09:08 +03:00
Update with integrated Database.Record module and divide module about
Singleton wraped type like DB-record.
This commit is contained in:
parent
44479d6330
commit
faf91d14f5
@ -20,6 +20,7 @@ library
|
||||
|
||||
exposed-modules:
|
||||
Database.HDBC.Record.Persistable
|
||||
Database.HDBC.Record.Singleton
|
||||
Database.HDBC.Record.TH
|
||||
Database.HDBC.Record.Query
|
||||
Database.HDBC.TH
|
||||
|
@ -9,14 +9,9 @@ module Database.HDBC.Record.Persistable (
|
||||
persistableSqlValue
|
||||
) where
|
||||
|
||||
import Database.Record.Persistable
|
||||
(Singleton,
|
||||
persistableSqlTypeFromNull, PersistableType (..),
|
||||
PersistableSqlValue,
|
||||
PersistableWidth (),
|
||||
PersistableValue (persistableValue), derivedPersistableSingleton,
|
||||
Persistable (persistable))
|
||||
import qualified Database.Record.Persistable as Persistable
|
||||
import Database.Record (PersistableSqlValue, PersistableType (..), PersistableValue (..))
|
||||
import Database.Record.Persistable (persistableSqlTypeFromNull)
|
||||
import qualified Database.Record.Persistable as Record
|
||||
import Database.HDBC.Record.TH (derivePersistableInstancesFromConvertibleSqlValues)
|
||||
|
||||
import Data.Convertible (Convertible)
|
||||
@ -27,14 +22,10 @@ instance PersistableType SqlValue where
|
||||
|
||||
persistableSqlValue :: (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> PersistableSqlValue SqlValue a
|
||||
persistableSqlValue = Persistable.persistableSqlValue persistableType fromSql toSql
|
||||
persistableSqlValue = Record.persistableSqlValue persistableType fromSql toSql
|
||||
|
||||
instance (Convertible SqlValue a, Convertible a SqlValue)
|
||||
=> PersistableValue SqlValue a where
|
||||
persistableValue = persistableSqlValue
|
||||
|
||||
$(derivePersistableInstancesFromConvertibleSqlValues)
|
||||
|
||||
instance (Convertible SqlValue a, Convertible a SqlValue, PersistableWidth (Singleton a))
|
||||
=> Persistable SqlValue (Singleton a) where
|
||||
persistable = derivedPersistableSingleton
|
||||
|
@ -28,8 +28,9 @@ import qualified Database.HDBC as HDBC
|
||||
|
||||
import Database.Relational.Query (Query, untypeQuery)
|
||||
|
||||
import Database.Record.ToSql (RecordToSql(fromRecord), ToSql(recordToSql))
|
||||
import Database.Record.FromSql (RecordFromSql, runToRecord, FromSql(recordFromSql))
|
||||
import Database.Record
|
||||
(RecordToSql, ToSql(recordToSql), runFromRecord,
|
||||
RecordFromSql, FromSql(recordFromSql), runToRecord)
|
||||
|
||||
newtype PreparedQuery p a = PreparedQuery { prepared :: Statement }
|
||||
|
||||
@ -49,7 +50,7 @@ prepare :: IConnection conn => conn -> Query p a -> IO (PreparedQuery p a)
|
||||
prepare conn = fmap PreparedQuery . HDBC.prepare conn . untypeQuery
|
||||
|
||||
bindTo' :: RecordToSql SqlValue p -> p -> PreparedQuery p a -> BoundStatement a
|
||||
bindTo' toSql p q = BoundStatement { bound = prepared q, params = fromRecord toSql p }
|
||||
bindTo' toSql p q = BoundStatement { bound = prepared q, params = runFromRecord toSql p }
|
||||
|
||||
bindTo :: ToSql SqlValue p => p -> PreparedQuery p a -> BoundStatement a
|
||||
bindTo = bindTo' recordToSql
|
||||
|
16
schema-th/src/Database/HDBC/Record/Singleton.hs
Normal file
16
schema-th/src/Database/HDBC/Record/Singleton.hs
Normal file
@ -0,0 +1,16 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
|
||||
module Database.HDBC.Record.Singleton () where
|
||||
|
||||
import Database.HDBC.Record.Persistable ()
|
||||
|
||||
import Database.HDBC (SqlValue)
|
||||
|
||||
import Database.Record (PersistableWidth, Persistable(persistable), PersistableValue)
|
||||
import Database.Record.Singleton (Singleton, derivedPersistableSingleton)
|
||||
|
||||
instance (PersistableValue SqlValue a, PersistableWidth (Singleton a))
|
||||
=> Persistable SqlValue (Singleton a) where
|
||||
persistable = derivedPersistableSingleton
|
@ -11,14 +11,15 @@ import Data.List (intersect)
|
||||
|
||||
import Language.Haskell.TH
|
||||
(Q, Dec (InstanceD), Type(AppT, ConT),
|
||||
Info (ClassI), reify, runIO)
|
||||
Info (ClassI), reify)
|
||||
import Language.Haskell.TH.Name.Extra (compileError)
|
||||
import Data.Convertible (Convertible)
|
||||
import Database.HDBC (SqlValue)
|
||||
import Database.HDBC.SqlValueExtra ()
|
||||
import Database.Record.Persistable
|
||||
(Persistable(persistable), derivedPersistableRecord, PersistableWidth(persistableWidth))
|
||||
import Database.Record.FromSql (FromSql(recordFromSql), recordFromSql')
|
||||
import Database.Record.ToSql (ToSql(recordToSql), recordToSql')
|
||||
import Database.Record
|
||||
(Persistable(persistable), derivedPersistableValueRecord, PersistableWidth(persistableWidth),
|
||||
FromSql(recordFromSql), recordFromSql',
|
||||
ToSql(recordToSql), recordToSql')
|
||||
import qualified Database.Record.Persistable as Persistable
|
||||
|
||||
|
||||
@ -28,7 +29,7 @@ sqlValueType = [t| SqlValue |]
|
||||
convertibleSqlValues' :: Q [(Type, Type)]
|
||||
convertibleSqlValues' = cvInfo >>= d0 where
|
||||
cvInfo = reify ''Convertible
|
||||
unknownDeclaration = runIO . ioError . userError
|
||||
unknownDeclaration = compileError
|
||||
. ("convertibleSqlValues: Unknown declaration pattern: " ++)
|
||||
d0 (ClassI _ is) = fmap catMaybes . sequence . map d1 $ is where
|
||||
d1 (InstanceD _cxt (AppT (AppT (ConT _n) a) b) _ds)
|
||||
@ -57,7 +58,7 @@ derivePersistableInstanceFromValue typ =
|
||||
persistableWidth = Persistable.valueWidth
|
||||
|
||||
instance Persistable SqlValue $(typ) where
|
||||
persistable = derivedPersistableRecord
|
||||
persistable = derivedPersistableValueRecord
|
||||
|
||||
instance FromSql SqlValue $(typ) where
|
||||
recordFromSql = recordFromSql'
|
||||
|
@ -37,7 +37,7 @@ import Database.Relational.Query.Type (unsafeTypedQuery, fromRelation)
|
||||
import Database.Relational.Query.TH (defineRecordAndTableDefault)
|
||||
import Database.Relational.Query
|
||||
(Query, PrimeRelation, inner, relation,
|
||||
wheres, (.=.), (!), (!?), placeholder, asc)
|
||||
wheres, (.=.), (!), placeholder, asc)
|
||||
|
||||
import Language.SQL.Keyword (Keyword(..))
|
||||
import qualified Language.SQL.Keyword as SQL
|
||||
|
Loading…
Reference in New Issue
Block a user