撰写表单验证

时间:2016-09-09 14:52:42

标签: haskell yesod yesod-forms

我想在同一输入字段中添加几个验证。例如,价格字段不应小于0(check),另一个将查询数据库(checkM

listItem1
newitem2
newItem3
newItem4
newItem5
newItem6

所以我知道如何每次添加一个验证,但是如何组合这些验证功能?

这是一个gist,其工作形式简化。

1 个答案:

答案 0 :(得分:0)

正如本comment中的@ user2407038所回答,我的答案是

dbo.BIRTH - ENTRY (datetime), ID (int)
dbo.DEATH - ENTRY (datetime), ID (int)


;with cte (MONTH) AS (

    SELECT 1
    UNION ALL
    SELECT MONTH + 1 FROM cte WHERE MONTH < 12
)
SELECT c.MONTH
       , COUNT(CASE WHEN b.ID = 1 THEN 1 END) AS MALEBIRTH
       , COUNT(CASE WHEN b.ID = 2 THEN 1 END) AS FEMALEBIRTH
       , COUNT(CASE WHEN b.ID = 1 OR b.ID = 2 THEN 1 END) AS TOTALBIRTH
       , (SELECT COUNT(CASE WHEN d.ID = 1 THEN 1 END) FROM DEATH d WHERE DATEPART(mm, d.ENTRY) = c.MONTH) AS MALEDEATH
       , (SELECT COUNT(CASE WHEN d.ID = 2 THEN 2 END) FROM DEATH d WHERE DATEPART(mm, d.ENTRY) = c.MONTH) AS FEMALEDEATH
       , (SELECT COUNT(CASE WHEN d.ID = 1 OR d.ID = 2 THEN 2 END) FROM DEATH d WHERE DATEPART(mm, d.ENTRY) = c.MONTH) AS TOTALDEATH
FROM BIRTH b FULL OUTER JOIN cte c ON DATEPART(mm, b.ENTRY) = c.MONTH 
     GROUP BY c.MONTH

我已使用工作解决方案更新gist