मैं वेबसाइट बनाने के लिए यसोड और लगातार उपयोग करने की कोशिश कर रहा हूं। मैं लगातार एपीआई का उपयोग करने के बारे में थोड़ा उलझन में हूं।हास्केल लगातार प्रविष्टि पंक्तियां यदि डेटाबेस में पहले से नहीं हैं
यहाँ मेरी टेबल के दो
Feed
url Text
UniqueFeed url
Subscription
feed FeedId
title Text
UniqueSubscription feed
मैं अगर उस URL वाला चारा मौजूद नहीं है एक फ़ीड बनाने के लिए, और फिर उस फ़ीड की सदस्यता जोड़ने, यदि अंशदान पहले से ही मौजूद नहीं है कोशिश कर रहा हूँ है ।
postFeedR :: Handler RepHtml
postFeedR = do
url <- runInputPost $ ireq urlField "url"
title <- runInputPost $ ireq textField "title"
runDB $ do
feedId <- insertFeed $ UniqueFeed url
subscriptionId <- insertSubscription feedId title
return
defaultLayout [whamlet| <p>done|]
insertFeed url = do
f <- insertBy $ UniqueFeed url
case f of
Left (Entity uid _) -> uid
Right (Key uid) -> do
(Key uid) <- insert $ Feed url
return uid
insertSubscription feedId title = do
s <- insertBy $ UniqueSubscription feedId
case s of
Left (Entity uid _) -> uid
Right (Key uid) -> do
(Key uid) <- insert $ Subscription feedId title
return uid
मुझे नीचे त्रुटियां मिलती हैं। मुझे समझ में नहीं आता क्यों ghc सोचता है कि सम्मिलित करें और सम्मिलित सदस्यता का वापसी मूल्य अद्वितीय फीड और अद्वितीय सदस्यता होना चाहिए। मैं उन कार्यों को नए बनाए गए रिकॉर्ड की चाबियाँ वापस करना चाहता हूं।
इसके अलावा, ऐसा लगता है कि मैं इस कुंजी को फेंक रहा हूं कि मैं मामले के प्रत्येक दाएं खंड में वापस आ गया हूं। लगातार उन चाबियाँ क्यों लौटती हैं। ऐसे मामले में जहां अद्वितीय सदस्यता डेटाबेस में नहीं है, लगातार नए सदस्यता रिकॉर्ड बनाने के लिए पर्याप्त जानकारी नहीं है, क्योंकि यह शीर्षक खो रहा है, जो अनन्य सदस्यता पर नहीं है।
अगर कोई मुझे लगातार एपीआई का उपयोग करने के बारे में कुछ संकेत दे सकता है, तो मैं वास्तव में इसकी सराहना करता हूं।
Handler/Home.hs:62:9:
Kind incompatibility when matching types:
a0 :: *
GHandler App App :: * -> *
Expected type: (a0 -> t0)
-> (t0 -> a0 -> m0 a0) -> YesodDB App App (m0 a0)
Actual type: (a0 -> t0) -> (t0 -> a0 -> m0 a0) -> a0 -> m0 a0
In a stmt of a 'do' block: feedId <- insertFeed $ UniqueFeed url
In the second argument of `($)', namely
`do { feedId <- insertFeed $ UniqueFeed url;
subscriptionId <- insertSubscription feedId title;
return }'
Handler/Home.hs:62:9:
Couldn't match type `YesodPersistBackend App' with `(->)'
Expected type: (a0 -> t0)
-> (t0 -> a0 -> m0 a0) -> YesodDB App App (m0 a0)
Actual type: (a0 -> t0) -> (t0 -> a0 -> m0 a0) -> a0 -> m0 a0
In a stmt of a 'do' block: feedId <- insertFeed $ UniqueFeed url
In the second argument of `($)', namely
`do { feedId <- insertFeed $ UniqueFeed url;
subscriptionId <- insertSubscription feedId title;
return }'
Handler/Home.hs:74:20:
Couldn't match expected type `Unique Feed'
with actual type `Database.Persist.Store.PersistValue'
In the first argument of `return', namely `uid'
In a stmt of a 'do' block: return uid
In the expression:
do { (Key uid) <- insert $ Feed url;
return uid }
Handler/Home.hs:83:20:
Couldn't match expected type `Unique Subscription'
with actual type `Database.Persist.Store.PersistValue'
In the first argument of `return', namely `uid'
In a stmt of a 'do' block: return uid
In the expression:
do { (Key uid) <- insert $ Subscription feedId title;
return uid }
'insertBy $ Feed url' का उपयोग करने का प्रयास करें। –