MCPcopy
hub / github.com/ent/ent / length

Method length

dialect/sql/sqljson/sqljson.go:533–544  ·  view source on GitHub ↗

value writes the path for getting the length of a JSON value.

(b *sql.Builder)

Source from the content-addressed store, hash-verified

531
532// value writes the path for getting the length of a JSON value.
533func (p *PathOptions) length(b *sql.Builder) {
534 switch {
535 case b.Dialect() == dialect.Postgres:
536 b.WriteString("JSONB_ARRAY_LENGTH(")
537 p.pgTextPath(b)
538 b.WriteByte(')')
539 case b.Dialect() == dialect.MySQL:
540 p.mysqlFunc("JSON_LENGTH", b)
541 default:
542 p.mysqlFunc("JSON_ARRAY_LENGTH", b)
543 }
544}
545
546// mysqlFunc writes the JSON path in MySQL format for the
547// given function. `JSON_EXTRACT("a", '$.b.c')`.

Callers 1

lenPathFunction · 0.80

Calls 5

pgTextPathMethod · 0.95
mysqlFuncMethod · 0.95
WriteStringMethod · 0.80
WriteByteMethod · 0.80
DialectMethod · 0.65

Tested by

no test coverage detected