diff --git a/daos/table.go b/daos/table.go index 82bd8a14..a69ad5cf 100644 --- a/daos/table.go +++ b/daos/table.go @@ -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) diff --git a/daos/table_test.go b/daos/table_test.go index 533d71d3..e1ab2a31 100644 --- a/daos/table_test.go +++ b/daos/table_test.go @@ -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 {