ColumnsHasPrefix appends a new predicate that checks if the given column begins with the other column (prefix).
(col, prefixC string)
| 1254 | |
| 1255 | // ColumnsHasPrefix appends a new predicate that checks if the given column begins with the other column (prefix). |
| 1256 | func (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. |
| 1277 | func HasSuffix(col, suffix string) *Predicate { return P().HasSuffix(col, suffix) } |
no test coverage detected