IsCollectionNameUnique checks that there is no existing collection with the provided name (case insensitive!). Note: case insensitive check because the name is used also as table name for the records.
(name string, excludeIds ...string)
| 193 | // Note: case insensitive check because the name is used also as |
| 194 | // table name for the records. |
| 195 | func (app *BaseApp) IsCollectionNameUnique(name string, excludeIds ...string) bool { |
| 196 | if name == "" { |
| 197 | return false |
| 198 | } |
| 199 | |
| 200 | query := app.CollectionQuery(). |
| 201 | Select("count(*)"). |
| 202 | AndWhere(dbx.NewExp("LOWER([[name]])={:name}", dbx.Params{"name": strings.ToLower(name)})). |
| 203 | Limit(1) |
| 204 | |
| 205 | if uniqueExcludeIds := list.NonzeroUniques(excludeIds); len(uniqueExcludeIds) > 0 { |
| 206 | query.AndWhere(dbx.NotIn("id", list.ToInterfaceSlice(uniqueExcludeIds)...)) |
| 207 | } |
| 208 | |
| 209 | var total int |
| 210 | |
| 211 | return query.Row(&total) == nil && total == 0 |
| 212 | } |
| 213 | |
| 214 | // TruncateCollection deletes all records associated with the provided collection. |
| 215 | // |
nothing calls this directly
no test coverage detected