MCPcopy
hub / github.com/pocketbase/pocketbase / IsCollectionNameUnique

Method IsCollectionNameUnique

core/collection_query.go:195–212  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

193// Note: case insensitive check because the name is used also as
194// table name for the records.
195func (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//

Callers

nothing calls this directly

Calls 4

CollectionQueryMethod · 0.95
NonzeroUniquesFunction · 0.92
ToInterfaceSliceFunction · 0.92
SelectMethod · 0.80

Tested by

no test coverage detected