MCPcopy
hub / github.com/ent/ent / ColumnsHasPrefix

Method ColumnsHasPrefix

dialect/sql/builder.go:1256–1274  ·  view source on GitHub ↗

ColumnsHasPrefix appends a new predicate that checks if the given column begins with the other column (prefix).

(col, prefixC string)

Source from the content-addressed store, hash-verified

1254
1255// ColumnsHasPrefix appends a new predicate that checks if the given column begins with the other column (prefix).
1256func (p *Predicate) ColumnsHasPrefix(col, prefixC string) *Predicate {
1257 return p.Append(func(b *Builder) {
1258 switch p.dialect {
1259 case dialect.MySQL:
1260 b.Ident(col)
1261 b.WriteOp(OpLike)
1262 b.S("CONCAT(REPLACE(REPLACE(").Ident(prefixC).S(", '_', '\\_'), '%', '\\%'), '%')")
1263 case dialect.Postgres, dialect.SQLite:
1264 b.Ident(col)
1265 b.WriteOp(OpLike)
1266 b.S("(REPLACE(REPLACE(").Ident(prefixC).S(", '_', '\\_'), '%', '\\%') || '%')")
1267 if p.dialect == dialect.SQLite {
1268 p.WriteString(" ESCAPE ").Arg("\\")
1269 }
1270 default:
1271 b.AddError(fmt.Errorf("ColumnsHasPrefix: unsupported dialect: %q", p.dialect))
1272 }
1273 })
1274}
1275
1276// HasSuffix is a helper predicate that checks suffix using the LIKE predicate.
1277func HasSuffix(col, suffix string) *Predicate { return P().HasSuffix(col, suffix) }

Callers 1

ColumnsHasPrefixFunction · 0.80

Calls 7

AppendMethod · 0.95
IdentMethod · 0.80
WriteOpMethod · 0.80
SMethod · 0.80
ArgMethod · 0.80
WriteStringMethod · 0.80
AddErrorMethod · 0.45

Tested by

no test coverage detected