pocketbase integration for persisting data

This commit is contained in:
2023-10-06 17:17:26 +02:00
parent 488f733ab1
commit 732e8856b7
3 changed files with 40 additions and 15 deletions
+32 -7
View File
@@ -1,17 +1,42 @@
// pb.go
package pb
import (
"sync"
"github.com/charmbracelet/log"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/models"
)
func Run() {
app := pocketbase.New()
var (
app *pocketbase.PocketBase
once sync.Once
)
func() {
if err := app.Start(); err != nil {
log.Fatal(err)
}
}()
// Init initializes the PocketBase app
func Init() {
once.Do(func() {
app = pocketbase.New()
// Add any necessary configuration or initialization here
func() {
if err := app.Start(); err != nil {
log.Fatal(err)
}
}()
})
}
func GetRecordById(collectionID string, recordID string) (*models.Record, error) {
// Access the PocketBase DAO and perform database operations
// Example: Retrieve all records from the "articles" collection
record, err := app.Dao().FindRecordById(collectionID, recordID)
if err != nil {
log.Error(err)
return nil, err
}
return record, nil
}