gorose icon indicating copy to clipboard operation
gorose copied to clipboard

How I can Execute this SQL-query?

Open devig opened this issue 4 years ago • 1 comments

How I can Execute this SQL-query:

update matching_times set duration=TIME_TO_SEC(TIMEDIFF('2021-03-11 16:23:21',created_at)) where user_id in (145, 146,...)

These are not work's

DB().Execute("update matching_times set duration=TIME_TO_SEC(TIMEDIFF(?,created_at)) where user_id in (?) ", currentTimeString, []int{145, 146}) How I can add elements from slice in "in"?

or

DB().Table("matching_times").WhereIn("user_id", userList).Data(gorose.Data{"duration":"TIME_TO_SEC(TIMEDIFF("+currentTimeString+",created_at))"}).Update()

Do you have opportunity to add Raw SQL in query builder?

devig avatar Mar 11 '21 14:03 devig

@devig the Data(arg interface{}) also receive raw in sql builder https://github.com/gohouse/gorose/blob/master/builder_default.go#L172 just do it like this

DB().Table("matching_times").WhereIn("user_id", userList).Data("duration=TIME_TO_SEC(TIMEDIFF("+currentTimeString+",created_at))").Update()

fizzday avatar Mar 13 '21 04:03 fizzday