updated db pool limits, added logs VACUUM, updated api docs

This commit is contained in:
Gani Georgiev
2022-11-13 00:38:18 +02:00
parent 39dc1d2795
commit 521df149a2
64 changed files with 650 additions and 751 deletions
+3 -3
View File
@@ -18,18 +18,18 @@ func (dao *Dao) CollectionQuery() *dbx.SelectQuery {
// FindCollectionsByType finds all collections by the given type
func (dao *Dao) FindCollectionsByType(collectionType string) ([]*models.Collection, error) {
models := []*models.Collection{}
collections := []*models.Collection{}
err := dao.CollectionQuery().
AndWhere(dbx.HashExp{"type": collectionType}).
OrderBy("created ASC").
All(&models)
All(&collections)
if err != nil {
return nil, err
}
return models, nil
return collections, nil
}
// FindCollectionByNameOrId finds the first collection by its name or id.
+1 -1
View File
@@ -99,7 +99,7 @@ func (dao *Dao) FindRecordsByIds(
//
// Example:
// expr1 := dbx.HashExp{"email": "test@example.com"}
// expr2 := dbx.HashExp{"status": "active"}
// expr2 := dbx.NewExp("LOWER(username) = {:username}", dbx.Params{"username": "test"})
// dao.FindRecordsByExpr("example", expr1, expr2)
func (dao *Dao) FindRecordsByExpr(collectionNameOrId string, exprs ...dbx.Expression) ([]*models.Record, error) {
collection, err := dao.FindCollectionByNameOrId(collectionNameOrId)
+8
View File
@@ -35,3 +35,11 @@ func (dao *Dao) DeleteTable(tableName string) error {
return err
}
// Vacuum executes VACUUM on the current dao.DB() instance in order to
// reclaim unused db disk space.
func (dao *Dao) Vacuum() error {
_, err := dao.DB().NewQuery("VACUUM").Execute()
return err
}
+28
View File
@@ -1,7 +1,10 @@
package daos_test
import (
"context"
"database/sql"
"testing"
"time"
"github.com/pocketbase/pocketbase/tests"
"github.com/pocketbase/pocketbase/tools/list"
@@ -79,3 +82,28 @@ func TestDeleteTable(t *testing.T) {
}
}
}
func TestVacuum(t *testing.T) {
app, _ := tests.NewTestApp()
defer app.Cleanup()
calledQueries := []string{}
app.DB().QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
calledQueries = append(calledQueries, sql)
}
app.DB().ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {
calledQueries = append(calledQueries, sql)
}
if err := app.Dao().Vacuum(); err != nil {
t.Fatal(err)
}
if total := len(calledQueries); total != 1 {
t.Fatalf("Expected 1 query, got %d", total)
}
if calledQueries[0] != "VACUUM" {
t.Fatalf("Expected VACUUM query, got %s", calledQueries[0])
}
}