feat: entgo.

This commit is contained in:
Bobo
2025-02-08 00:08:10 +08:00
parent d549d305ae
commit f73f016ec5
3 changed files with 6 additions and 4 deletions

View File

@@ -565,12 +565,12 @@ func filterDatePartField(s *sql.Selector, datePart, field string) string {
}
// filterJsonb 提取JSONB字段
// Postgresql: WHERE ("app_profile"."preferences" -> daily_email) = 'true'
// Postgresql: WHERE ("app_profile"."preferences" ->> 'daily_email') = 'true'
func filterJsonb(s *sql.Selector, p *sql.Predicate, jsonbField, field string) *sql.Predicate {
p.Append(func(b *sql.Builder) {
switch s.Builder.Dialect() {
case dialect.Postgres:
b.Ident(s.C(field)).WriteString(" -> ").WriteString(jsonbField)
b.Ident(s.C(field)).WriteString(" ->> ").WriteString("'" + jsonbField + "'")
//b.Arg(strings.ToLower(value))
break

View File

@@ -7,6 +7,7 @@ import (
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -681,7 +682,7 @@ func TestFilter(t *testing.T) {
s.Where(p)
query, args := s.Query()
require.Equal(t, "SELECT * FROM \"app_profile\" WHERE \"app_profile\".\"preferences\" -> daily_email = $1", query)
require.Equal(t, "SELECT * FROM \"app_profile\" WHERE \"app_profile\".\"preferences\" ->> 'daily_email' = $1", query)
require.NotEmpty(t, args)
require.Equal(t, args[0], "true")
})
@@ -691,4 +692,5 @@ func TestFilterJsonbField(t *testing.T) {
s := sql.Dialect(dialect.Postgres).Select("*").From(sql.Table("app_profile"))
str := filterJsonbField(s, "daily_email", "preferences")
fmt.Println(str)
assert.Equal(t, str, "\"app_profile\".\"preferences\" ->> 'daily_email'")
}

View File

@@ -3,7 +3,7 @@ git tag v1.1.13
git tag bank_card/v1.1.3
git tag geoip/v1.1.3
git tag entgo/v1.1.19
git tag entgo/v1.1.20
git tag gorm/v1.1.3
git push origin --tags