1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-02-14 00:42:10 +02:00

removed unnecessary count

This commit is contained in:
Gani Georgiev 2025-01-17 15:58:57 +02:00
parent 0798b5ccbb
commit c70ca97888
3 changed files with 4 additions and 29 deletions

View File

@ -206,9 +206,9 @@ func (app *BaseApp) IsCollectionNameUnique(name string, excludeIds ...string) bo
query.AndWhere(dbx.NotIn("id", list.ToInterfaceSlice(uniqueExcludeIds)...))
}
var exists bool
var total int
return query.Row(&exists) == nil && !exists
return query.Row(&total) == nil && total == 0
}
// TruncateCollection deletes all records associated with the provided collection.

View File

@ -269,7 +269,7 @@ func (r *MigrationsRunner) initMigrationsTable() error {
func (r *MigrationsRunner) isMigrationApplied(txApp App, file string) bool {
var exists bool
err := txApp.DB().Select("count(*)").
err := txApp.DB().Select("(1)").
From(r.tableName).
Where(dbx.HashExp{"file": file}).
Limit(1).

View File

@ -202,7 +202,7 @@ func TestMigrationsRunnerRemoveMissingAppliedMigrations(t *testing.T) {
func isMigrationApplied(app core.App, file string) bool {
var exists bool
err := app.DB().Select("count(*)").
err := app.DB().Select("(1)").
From(core.DefaultMigrationsTable).
Where(dbx.HashExp{"file": file}).
Limit(1).
@ -210,28 +210,3 @@ func isMigrationApplied(app core.App, file string) bool {
return err == nil && exists
}
// // -------------------------------------------------------------------
// type testDB struct {
// *dbx.DB
// CalledQueries []string
// }
// // NB! Don't forget to call `db.Close()` at the end of the test.
// func createTestDB() (*testDB, error) {
// sqlDB, err := sql.Open("sqlite", ":memory:")
// if err != nil {
// return nil, err
// }
// db := testDB{DB: dbx.NewFromDB(sqlDB, "sqlite")}
// db.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
// db.CalledQueries = append(db.CalledQueries, sql)
// }
// db.ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {
// db.CalledQueries = append(db.CalledQueries, sql)
// }
// return &db, nil
// }