mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 17:25:32 +00:00
Prev/next
This commit is contained in:
34
dbmodels/entries_functions.go
Normal file
34
dbmodels/entries_functions.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package dbmodels
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func (e *Entry) Prev(app core.App) *Entry {
|
||||
var entry Entry
|
||||
err := app.RecordQuery(ENTRIES_TABLE).
|
||||
Where(dbx.NewExp(MUSENALMID_FIELD+" < {:exp}", dbx.Params{"exp": e.MusenalmID()})).
|
||||
OrderBy(MUSENALMID_FIELD + " DESC").
|
||||
Limit(1).
|
||||
One(&entry)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &entry
|
||||
}
|
||||
|
||||
func (e *Entry) Next(app core.App) *Entry {
|
||||
var entry Entry
|
||||
err := app.RecordQuery(ENTRIES_TABLE).
|
||||
Where(dbx.NewExp(MUSENALMID_FIELD+" > {:exp}", dbx.Params{"exp": e.MusenalmID()})).
|
||||
OrderBy(MUSENALMID_FIELD + " ASC").
|
||||
Limit(1).
|
||||
One(&entry)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &entry
|
||||
}
|
||||
Reference in New Issue
Block a user