mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-12 20:27:51 +03:00
Rename type class method.
This commit is contained in:
parent
faf91d14f5
commit
2ddffc5853
@ -29,7 +29,7 @@ import Database.Record.Persistable
|
|||||||
Persistable(persistable), PersistableType)
|
Persistable(persistable), PersistableType)
|
||||||
import qualified Database.Record.Persistable as Persistable
|
import qualified Database.Record.Persistable as Persistable
|
||||||
import Database.Record.KeyConstraint
|
import Database.Record.KeyConstraint
|
||||||
(HasKeyConstraint(constraintKey), KeyConstraint, NotNull, index)
|
(HasKeyConstraint(keyConstraint), KeyConstraint, NotNull, index)
|
||||||
|
|
||||||
import Control.Monad (liftM, ap)
|
import Control.Monad (liftM, ap)
|
||||||
import Control.Applicative ((<$>), Applicative(pure, (<*>)))
|
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)
|
instance (HasKeyConstraint NotNull a, FromSql q a, PersistableType q)
|
||||||
=> FromSql q (Maybe a) where
|
=> FromSql q (Maybe a) where
|
||||||
recordFromSql = outer recordFromSql $ constraintKey
|
recordFromSql = outer recordFromSql $ keyConstraint
|
||||||
|
|
||||||
instance FromSql q () where
|
instance FromSql q () where
|
||||||
recordFromSql = recordFromSql'
|
recordFromSql = recordFromSql'
|
||||||
|
@ -21,13 +21,13 @@ module Database.Record.KeyConstraint (
|
|||||||
unique, notNull,
|
unique, notNull,
|
||||||
|
|
||||||
leftKeyConstraint,
|
leftKeyConstraint,
|
||||||
HasKeyConstraint (constraintKey),
|
HasKeyConstraint (keyConstraint),
|
||||||
|
|
||||||
derivedUniqueConstraint,
|
derivedUniqueConstraint,
|
||||||
derivedNotNullConstraint
|
derivedNotNullConstraint
|
||||||
) where
|
) where
|
||||||
|
|
||||||
newtype KeyConstraint c a = KeyConstraint { index :: Int }
|
newtype KeyConstraint c r = KeyConstraint { index :: Int }
|
||||||
|
|
||||||
data Unique
|
data Unique
|
||||||
data NotNull
|
data NotNull
|
||||||
@ -37,13 +37,13 @@ type UniqueConstraint = KeyConstraint Unique
|
|||||||
type NotNullConstraint = KeyConstraint NotNull
|
type NotNullConstraint = KeyConstraint NotNull
|
||||||
type PrimaryConstraint = KeyConstraint Primary
|
type PrimaryConstraint = KeyConstraint Primary
|
||||||
|
|
||||||
specifyKeyConstraint :: Int -> KeyConstraint c a
|
specifyKeyConstraint :: Int -> KeyConstraint c r
|
||||||
specifyKeyConstraint = KeyConstraint
|
specifyKeyConstraint = KeyConstraint
|
||||||
|
|
||||||
unique :: PrimaryConstraint a -> UniqueConstraint a
|
unique :: PrimaryConstraint r -> UniqueConstraint r
|
||||||
unique = specifyKeyConstraint . index
|
unique = specifyKeyConstraint . index
|
||||||
|
|
||||||
notNull :: PrimaryConstraint a -> NotNullConstraint a
|
notNull :: PrimaryConstraint r -> NotNullConstraint r
|
||||||
notNull = specifyKeyConstraint . index
|
notNull = specifyKeyConstraint . index
|
||||||
|
|
||||||
|
|
||||||
@ -51,13 +51,13 @@ leftKeyConstraint :: KeyConstraint k a -> KeyConstraint k (a, b)
|
|||||||
leftKeyConstraint pa = KeyConstraint (index pa)
|
leftKeyConstraint pa = KeyConstraint (index pa)
|
||||||
|
|
||||||
class HasKeyConstraint c a where
|
class HasKeyConstraint c a where
|
||||||
constraintKey :: KeyConstraint c a
|
keyConstraint :: KeyConstraint c a
|
||||||
|
|
||||||
instance HasKeyConstraint c a => HasKeyConstraint c (a, b) where
|
instance HasKeyConstraint c a => HasKeyConstraint c (a, b) where
|
||||||
constraintKey = leftKeyConstraint constraintKey
|
keyConstraint = leftKeyConstraint keyConstraint
|
||||||
|
|
||||||
derivedUniqueConstraint :: HasKeyConstraint Primary a => UniqueConstraint a
|
derivedUniqueConstraint :: HasKeyConstraint Primary r => UniqueConstraint r
|
||||||
derivedUniqueConstraint = unique constraintKey
|
derivedUniqueConstraint = unique keyConstraint
|
||||||
|
|
||||||
derivedNotNullConstraint :: HasKeyConstraint Primary a => NotNullConstraint a
|
derivedNotNullConstraint :: HasKeyConstraint Primary r => NotNullConstraint r
|
||||||
derivedNotNullConstraint = notNull constraintKey
|
derivedNotNullConstraint = notNull keyConstraint
|
||||||
|
@ -34,7 +34,7 @@ import Language.Haskell.TH
|
|||||||
clause, cxt, varStrictType, strictType, isStrict)
|
clause, cxt, varStrictType, strictType, isStrict)
|
||||||
|
|
||||||
import Database.Record
|
import Database.Record
|
||||||
(HasKeyConstraint(constraintKey), Primary, NotNull,
|
(HasKeyConstraint(keyConstraint), Primary, NotNull,
|
||||||
Persistable(persistable), PersistableWidth(persistableWidth),
|
Persistable(persistable), PersistableWidth(persistableWidth),
|
||||||
fromSql, toSql,
|
fromSql, toSql,
|
||||||
FromSql(recordFromSql), recordFromSql',
|
FromSql(recordFromSql), recordFromSql',
|
||||||
@ -48,7 +48,7 @@ import Database.Record.Persistable
|
|||||||
defineHasKeyConstraintInstance :: TypeQ -> TypeQ -> Int -> Q [Dec]
|
defineHasKeyConstraintInstance :: TypeQ -> TypeQ -> Int -> Q [Dec]
|
||||||
defineHasKeyConstraintInstance constraint typeCon index =
|
defineHasKeyConstraintInstance constraint typeCon index =
|
||||||
[d| instance HasKeyConstraint $constraint $typeCon where
|
[d| instance HasKeyConstraint $constraint $typeCon where
|
||||||
constraintKey = specifyKeyConstraint $(integralE index) |]
|
keyConstraint = specifyKeyConstraint $(integralE index) |]
|
||||||
|
|
||||||
recordTypeNameDefault :: String -> ConName
|
recordTypeNameDefault :: String -> ConName
|
||||||
recordTypeNameDefault = conCamelcaseName
|
recordTypeNameDefault = conCamelcaseName
|
||||||
|
@ -27,7 +27,7 @@ module Database.Record.ToSql (
|
|||||||
import Database.Record.Persistable
|
import Database.Record.Persistable
|
||||||
(PersistableRecord, Persistable(persistable))
|
(PersistableRecord, Persistable(persistable))
|
||||||
import Database.Record.KeyConstraint
|
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
|
import qualified Database.Record.Persistable as Persistable
|
||||||
|
|
||||||
|
|
||||||
@ -75,4 +75,4 @@ updateValuesByUnique = updateValuesByUnique' recordToSql
|
|||||||
|
|
||||||
updateValuesByPrimary :: (HasKeyConstraint Primary a, ToSql q a) =>
|
updateValuesByPrimary :: (HasKeyConstraint Primary a, ToSql q a) =>
|
||||||
a -> [q]
|
a -> [q]
|
||||||
updateValuesByPrimary = updateValuesByUnique (unique constraintKey)
|
updateValuesByPrimary = updateValuesByUnique (unique keyConstraint)
|
||||||
|
Loading…
Reference in New Issue
Block a user