Documentation
¶
Overview ¶
Package models implements all PocketBase DB models and DTOs.
Index ¶
- Constants
- type BaseModel
- func (m *BaseModel) GetCreated() types.DateTime
- func (m *BaseModel) GetId() string
- func (m *BaseModel) GetUpdated() types.DateTime
- func (m *BaseModel) HasId() bool
- func (m *BaseModel) IsNew() bool
- func (m *BaseModel) MarkAsNew()
- func (m *BaseModel) MarkAsNotNew()
- func (m *BaseModel) PostScan() error
- func (m *BaseModel) RefreshCreated()
- func (m *BaseModel) RefreshId()
- func (m *BaseModel) RefreshUpdated()
- func (m *BaseModel) SetId(id string)
- type ColumnValueMapper
- type FilesManager
- type Model
Constants ¶
const ( // DefaultIdLength is the default length of the generated model id. DefaultIdLength = 15 // DefaultIdAlphabet is the default characters set used for generating the model id. DefaultIdAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶
type BaseModel struct {
Id string `db:"id" json:"id"`
Created types.DateTime `db:"created" json:"created"`
Updated types.DateTime `db:"updated" json:"updated"`
// contains filtered or unexported fields
}
BaseModel defines common fields and methods used by all other models.
func (*BaseModel) GetCreated ¶
GetCreated returns the model Created datetime.
func (*BaseModel) GetUpdated ¶
GetUpdated returns the model Updated datetime.
func (*BaseModel) IsNew ¶
IsNew indicates what type of db query (insert or update) should be used with the model instance.
func (*BaseModel) MarkAsNew ¶
func (m *BaseModel) MarkAsNew()
MarkAsNew marks the model as "new" (aka. enforces m.IsNew() to be true).
func (*BaseModel) MarkAsNotNew ¶
func (m *BaseModel) MarkAsNotNew()
MarkAsNotNew marks the model as "not new" (aka. enforces m.IsNew() to be false)
func (*BaseModel) PostScan ¶
PostScan implements the [dbx.PostScanner] interface.
It is executed right after the model was populated with the db row values.
func (*BaseModel) RefreshCreated ¶
func (m *BaseModel) RefreshCreated()
RefreshCreated updates the model Created field with the current datetime.
func (*BaseModel) RefreshId ¶
func (m *BaseModel) RefreshId()
RefreshId generates and sets a new model id.
The generated id is a cryptographically random 15 characters length string.
func (*BaseModel) RefreshUpdated ¶
func (m *BaseModel) RefreshUpdated()
RefreshUpdated updates the model Updated field with the current datetime.
type ColumnValueMapper ¶
type ColumnValueMapper interface {
// ColumnValueMap returns the data to be used when persisting the model.
ColumnValueMap() map[string]any
}
ColumnValueMapper defines an interface for custom db model data serialization.
type FilesManager ¶
type FilesManager interface {
// BaseFilesPath returns the storage dir path used by the interface instance.
BaseFilesPath() string
}
FilesManager defines an interface with common methods that files manager models should implement.
type Model ¶
type Model interface {
TableName() string
IsNew() bool
MarkAsNew()
MarkAsNotNew()
HasId() bool
GetId() string
SetId(id string)
GetCreated() types.DateTime
GetUpdated() types.DateTime
RefreshId()
RefreshCreated()
RefreshUpdated()
}
Model defines an interface with common methods that all db models should have.