mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-21 14:46:34 +02:00
updated daos.HasTable to check also for views
This commit is contained in:
parent
41c3cc8a90
commit
4fdc8feafc
@ -7,13 +7,13 @@ import (
|
|||||||
"github.com/pocketbase/pocketbase/models"
|
"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 {
|
func (dao *Dao) HasTable(tableName string) bool {
|
||||||
var exists bool
|
var exists bool
|
||||||
|
|
||||||
err := dao.DB().Select("count(*)").
|
err := dao.DB().Select("count(*)").
|
||||||
From("sqlite_schema").
|
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})).
|
AndWhere(dbx.NewExp("LOWER([[name]])=LOWER({:tableName})", dbx.Params{"tableName": tableName})).
|
||||||
Limit(1).
|
Limit(1).
|
||||||
Row(&exists)
|
Row(&exists)
|
||||||
|
@ -24,6 +24,7 @@ func TestHasTable(t *testing.T) {
|
|||||||
{"_admins", true},
|
{"_admins", true},
|
||||||
{"demo3", true},
|
{"demo3", true},
|
||||||
{"DEMO3", true}, // table names are case insensitives by default
|
{"DEMO3", true}, // table names are case insensitives by default
|
||||||
|
{"view1", true}, // view
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, scenario := range scenarios {
|
for i, scenario := range scenarios {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user