go-gorm/datatypes

Greater/Lesser function for JSONQuery

deorth-kku opened this issue · 0 comments

It would be good to have something like this.

DB.First(&user, datatypes.JSONQuery("attributes").Lesser("age", 35))

// MySQL
// SELECT * FROM `user` WHERE JSON_EXTRACT(`attributes`, '$.age') < 35

DB.First(&user, datatypes.JSONQuery("attributes").Greater("age", 35))

// MySQL
// SELECT * FROM `user` WHERE JSON_EXTRACT(`attributes`, '$.age') > 35

Of course, we will need these as well.

DB.First(&user, datatypes.JSONQuery("attributes").NotLesser("age", 35))

// MySQL
// SELECT * FROM `user` WHERE JSON_EXTRACT(`attributes`, '$.age') >= 35

DB.First(&user, datatypes.JSONQuery("attributes").NotGreater("age", 35))

// MySQL
// SELECT * FROM `user` WHERE JSON_EXTRACT(`attributes`, '$.age') <= 35

Finally,

DB.First(&user, datatypes.JSONQuery("attributes").NotEquals("age", 35))

// MySQL
// SELECT * FROM `user` WHERE JSON_EXTRACT(`attributes`, '$.age') >< 35