Rename type class method.

This commit is contained in:
Kei Hibino 2013-05-10 10:54:00 +09:00
parent faf91d14f5
commit 2ddffc5853
4 changed files with 17 additions and 17 deletions

View File

@ -29,7 +29,7 @@ import Database.Record.Persistable
Persistable(persistable), PersistableType)
import qualified Database.Record.Persistable as Persistable
import Database.Record.KeyConstraint
(HasKeyConstraint(constraintKey), KeyConstraint, NotNull, index)
(HasKeyConstraint(keyConstraint), KeyConstraint, NotNull, index)
import Control.Monad (liftM, ap)
import Control.Applicative ((<$>), Applicative(pure, (<*>)))
@ -90,7 +90,7 @@ instance (FromSql q a, FromSql q b) => FromSql q (a, b) where
instance (HasKeyConstraint NotNull a, FromSql q a, PersistableType q)
=> FromSql q (Maybe a) where
recordFromSql = outer recordFromSql $ constraintKey
recordFromSql = outer recordFromSql $ keyConstraint
instance FromSql q () where
recordFromSql = recordFromSql'

View File

@ -21,13 +21,13 @@ module Database.Record.KeyConstraint (
unique, notNull,
leftKeyConstraint,
HasKeyConstraint (constraintKey),
HasKeyConstraint (keyConstraint),
derivedUniqueConstraint,
derivedNotNullConstraint
) where
newtype KeyConstraint c a = KeyConstraint { index :: Int }
newtype KeyConstraint c r = KeyConstraint { index :: Int }
data Unique
data NotNull
@ -37,13 +37,13 @@ type UniqueConstraint = KeyConstraint Unique
type NotNullConstraint = KeyConstraint NotNull
type PrimaryConstraint = KeyConstraint Primary
specifyKeyConstraint :: Int -> KeyConstraint c a
specifyKeyConstraint :: Int -> KeyConstraint c r
specifyKeyConstraint = KeyConstraint
unique :: PrimaryConstraint a -> UniqueConstraint a
unique :: PrimaryConstraint r -> UniqueConstraint r
unique = specifyKeyConstraint . index
notNull :: PrimaryConstraint a -> NotNullConstraint a
notNull :: PrimaryConstraint r -> NotNullConstraint r
notNull = specifyKeyConstraint . index
@ -51,13 +51,13 @@ leftKeyConstraint :: KeyConstraint k a -> KeyConstraint k (a, b)
leftKeyConstraint pa = KeyConstraint (index pa)
class HasKeyConstraint c a where
constraintKey :: KeyConstraint c a
keyConstraint :: KeyConstraint c a
instance HasKeyConstraint c a => HasKeyConstraint c (a, b) where
constraintKey = leftKeyConstraint constraintKey
keyConstraint = leftKeyConstraint keyConstraint
derivedUniqueConstraint :: HasKeyConstraint Primary a => UniqueConstraint a
derivedUniqueConstraint = unique constraintKey
derivedUniqueConstraint :: HasKeyConstraint Primary r => UniqueConstraint r
derivedUniqueConstraint = unique keyConstraint
derivedNotNullConstraint :: HasKeyConstraint Primary a => NotNullConstraint a
derivedNotNullConstraint = notNull constraintKey
derivedNotNullConstraint :: HasKeyConstraint Primary r => NotNullConstraint r
derivedNotNullConstraint = notNull keyConstraint

View File

@ -34,7 +34,7 @@ import Language.Haskell.TH
clause, cxt, varStrictType, strictType, isStrict)
import Database.Record
(HasKeyConstraint(constraintKey), Primary, NotNull,
(HasKeyConstraint(keyConstraint), Primary, NotNull,
Persistable(persistable), PersistableWidth(persistableWidth),
fromSql, toSql,
FromSql(recordFromSql), recordFromSql',
@ -48,7 +48,7 @@ import Database.Record.Persistable
defineHasKeyConstraintInstance :: TypeQ -> TypeQ -> Int -> Q [Dec]
defineHasKeyConstraintInstance constraint typeCon index =
[d| instance HasKeyConstraint $constraint $typeCon where
constraintKey = specifyKeyConstraint $(integralE index) |]
keyConstraint = specifyKeyConstraint $(integralE index) |]
recordTypeNameDefault :: String -> ConName
recordTypeNameDefault = conCamelcaseName

View File

@ -27,7 +27,7 @@ module Database.Record.ToSql (
import Database.Record.Persistable
(PersistableRecord, Persistable(persistable))
import Database.Record.KeyConstraint
(HasKeyConstraint(constraintKey), KeyConstraint, Primary, Unique, unique, index)
(HasKeyConstraint(keyConstraint), KeyConstraint, Primary, Unique, unique, index)
import qualified Database.Record.Persistable as Persistable
@ -75,4 +75,4 @@ updateValuesByUnique = updateValuesByUnique' recordToSql
updateValuesByPrimary :: (HasKeyConstraint Primary a, ToSql q a) =>
a -> [q]
updateValuesByPrimary = updateValuesByUnique (unique constraintKey)
updateValuesByPrimary = updateValuesByUnique (unique keyConstraint)