You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want query json columns with sql SELECT * FROM `group` WHERE JSON_EXTRACT(`users`,'$') LIKE '%admin%'
But I use datatypes.JSONQuery("files").Likes("%"+user+"%") and get error
Because method not support empty key
package main
import (
"fmt"
"strconv"
"strings"
"gorm.io/datatypes"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type Group struct {
ID uint `gorm:"primarykey"`
Users datatypes.JSONSlice[string] `gorm:"type:json" `
Name string
}
func main() {
dsn := "root:123456@tcp(localhost:3306)/test_db?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.New(
mysql.Config{
DSN: dsn,
DefaultStringSize: 256,
DisableDatetimePrecision: true,
DontSupportRenameIndex: true,
DontSupportRenameColumn: true,
SkipInitializeWithVersion: false,
}),
)
if err != nil {
panic(err)
}
var groups []Group
user := "admin"
db.Debug().
// Where(datatypes.JSONQuery("users").Likes("%"+user+"%")). // want to support
Where("JSON_EXTRACT(`users`,'$') LIKE ?", "%"+user+"%"). // current use
Find(&groups)
}
<!-- Describe the requested Feature -->
## Motivation
<!-- Describe the motivation behind it -->
## Related Issues
<!-- Link related issues here -->
The text was updated successfully, but these errors were encountered:
Describe the feature
I want query json columns with sql
SELECT * FROM `group` WHERE JSON_EXTRACT(`users`,'$') LIKE '%admin%'
But I use
datatypes.JSONQuery("files").Likes("%"+user+"%")
and get errorBecause method not support empty key
datatypes/json.go
Line 188 in 610acc2
The text was updated successfully, but these errors were encountered: