didi / gendry

a golang library for sql builder
Apache License 2.0
1.62k stars 195 forks source link

is null 和 is not null #11

Closed aimuz closed 6 years ago

aimuz commented 6 years ago

is null 和 is not null 这样的应该怎样使用?

caibirdme commented 6 years ago

For now, you can do it via NamedQuery:

builder.NamedQuery(`select colA,colB,colC from tb where colA is not null and colB in {{some}}`, map[string]interface{}{
    "some": []int{1,3,5,7},
})
aimuz commented 6 years ago
where := map[string]interface{}{
    "city in": []interface{}{"beijing", "shanghai"},
    "score": 5,
    "age >": 35,
    "_orderby": "bonus desc",
    "_groupby": "department",
}
table := "some_table"
selectFields := []string{"name", "age", "sex"}
cond, values, err := builder.BuildSelect(table, where, selectFields)

这种用法有没有那个is null

builder.NamedQuery(`select colA,colB,colC from tb where colA is not null and colB in {{some}}`, map[string]interface{}{
    "some": []int{1,3,5,7},
})

这个用法,好像相较于直接写SQL,没有太大区别

caibirdme commented 6 years ago

是的,按照我们的实践,复杂查询我们推荐应该直接写SQL,这样才不容易不错。NamedQuery帮助来把in的对象展开,相当于一个helper。 上面你说的我觉得还是有必要把这个feature加上,最终的效果如下:

where := map[string]interface{}{
    "city in": []interface{}{"beijing", "shanghai"},
    "score": 5,
    "age >": 35,
        "name": builder.ISNotNull,
        "address": builder.ISNull,
}

你觉得使用起来OK吗

caibirdme commented 6 years ago

@aimuz 这个功能已经加上

aimuz commented 6 years ago

good