From 4fdc8feafc7098f26d1d13cfe4926de0a0fcae7c Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Tue, 21 Feb 2023 20:03:27 +0200 Subject: [PATCH] updated daos.HasTable to check also for views --- daos/table.go | 4 ++-- daos/table_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) 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 {