didi / gendry

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

builder where & update support Raw SQL #147

Closed twz915 closed 1 year ago

twz915 commented 1 year ago

related issues https://github.com/didi/gendry/issues/141 https://github.com/didi/gendry/issues/122

builder supports such as

update = map[string]interface{}{
    "code": builder.Raw("VALUES(code)"), // mysql 8.x  builder.Raw("new.code")
    "name": builder.Raw("VALUES(name)"), // mysql 8.x  builder.Raw("new.name")
}

// INSERT INTO country (id, code, name) VALUES (?,?,?),(?,?,?),(?,?,?) 
// ON DUPLICATE KEY UPDATE code=VALUES(code),name=VALUES(name)
where := map[string]interface{}{"gmt_create <": builder.Raw("gmt_modified")}
// SELECT * FROM x 
// WHERE gmt_create < gmt_modified
caibirdme commented 1 year ago

Thx, I'll review this pr later

twz915 commented 1 year ago

我把默认的 VALUES 移除了,都让用户用的时候自己指定吧,这样好理解些

caibirdme commented 1 year ago

希望可以再加一点测试用例

twz915 commented 1 year ago

已经添加单测

caibirdme commented 1 year ago

Thx for your contribution!