1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-03-20 22:36:00 +02:00

updated daos.HasTable to check also for views

This commit is contained in:
Gani Georgiev 2023-02-21 20:03:27 +02:00
parent 41c3cc8a90
commit 4fdc8feafc
2 changed files with 3 additions and 2 deletions

View File

@ -7,13 +7,13 @@ import (
"github.com/pocketbase/pocketbase/models"
)
// HasTable checks if a table with the provided name exists (case insensitive).
// HasTable checks if a table (or view) with the provided name exists (case insensitive).
func (dao *Dao) HasTable(tableName string) bool {
var exists bool
err := dao.DB().Select("count(*)").
From("sqlite_schema").
AndWhere(dbx.HashExp{"type": "table"}).
AndWhere(dbx.HashExp{"type": []any{"table", "view"}}).
AndWhere(dbx.NewExp("LOWER([[name]])=LOWER({:tableName})", dbx.Params{"tableName": tableName})).
Limit(1).
Row(&exists)

View File

@ -24,6 +24,7 @@ func TestHasTable(t *testing.T) {
{"_admins", true},
{"demo3", true},
{"DEMO3", true}, // table names are case insensitives by default
{"view1", true}, // view
}
for i, scenario := range scenarios {