Documentation
¶
Overview ¶
Package models implements all PocketBase DB models.
Index ¶
- Constants
- type Admin
- type BaseAccount
- 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) RefreshCreated()
- func (m *BaseModel) RefreshId()
- func (m *BaseModel) RefreshUpdated()
- func (m *BaseModel) SetId(id string)
- func (m *BaseModel) UnmarkAsNew()
- type Collection
- type ColumnValueMapper
- type FilesManager
- type Model
- type Param
- type Record
- func (m *Record) BaseFilesPath() string
- func (m *Record) Collection() *Collection
- func (m *Record) ColumnValueMap() map[string]any
- func (m *Record) Data() map[string]any
- func (m *Record) FindFileFieldByFile(filename string) *schema.SchemaField
- func (m *Record) GetBoolDataValue(key string) bool
- func (m *Record) GetDataValue(key string) any
- func (m *Record) GetDateTimeDataValue(key string) types.DateTime
- func (m *Record) GetExpand() map[string]any
- func (m *Record) GetFloatDataValue(key string) float64
- func (m *Record) GetIntDataValue(key string) int
- func (m *Record) GetStringDataValue(key string) string
- func (m *Record) GetStringSliceDataValue(key string) []string
- func (m *Record) GetTimeDataValue(key string) time.Time
- func (m *Record) Load(data map[string]any) error
- func (m Record) MarshalJSON() ([]byte, error)
- func (m *Record) PublicExport() map[string]any
- func (m *Record) SetDataValue(key string, value any)
- func (m *Record) SetExpand(data map[string]any)
- func (m *Record) TableName() string
- func (m *Record) UnmarshalJSON(data []byte) error
- type Request
- type User
Constants ¶
const ( RequestAuthGuest = "guest" RequestAuthUser = "user" RequestAuthAdmin = "admin" )
list with the supported values for `Request.Auth`
const ( // ProfileCollectionName is the name of the system user profiles collection. ProfileCollectionName = "profiles" // ProfileCollectionUserFieldName is the name of the user field from the system user profiles collection. ProfileCollectionUserFieldName = "userId" )
const DefaultIdLength = 15
DefaultIdLength is the default length of the generated model id.
const (
ParamAppSettings = "settings"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Admin ¶
type Admin struct {
BaseAccount
Avatar int `db:"avatar" json:"avatar"`
}
type BaseAccount ¶
type BaseAccount struct {
BaseModel
Email string `db:"email" json:"email"`
TokenKey string `db:"tokenKey" json:"-"`
PasswordHash string `db:"passwordHash" json:"-"`
LastResetSentAt types.DateTime `db:"lastResetSentAt" json:"lastResetSentAt"`
}
BaseAccount defines common fields and methods used by auth models (aka. users and admins).
func (*BaseAccount) RefreshTokenKey ¶
func (m *BaseAccount) RefreshTokenKey()
RefreshTokenKey generates and sets new random token key.
func (*BaseAccount) SetPassword ¶
func (m *BaseAccount) SetPassword(password string) error
SetPassword sets cryptographically secure string to `model.Password`.
Additionally this method also resets the LastResetSentAt and the TokenKey fields.
func (*BaseAccount) ValidatePassword ¶
func (m *BaseAccount) ValidatePassword(password string) bool
ValidatePassword validates a plain password against the model's password.
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 ¶ added in v0.4.0
IsNew indicates what type of db query (insert or update) should be used with the model instance.
func (*BaseModel) MarkAsNew ¶ added in v0.4.0
func (m *BaseModel) MarkAsNew()
MarkAsNew sets the model isNewFlag enforcing [m.IsNew()] to be true.
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.
func (*BaseModel) UnmarkAsNew ¶ added in v0.4.0
func (m *BaseModel) UnmarkAsNew()
UnmarkAsNew resets the model isNewFlag.
type Collection ¶
type Collection struct {
BaseModel
Name string `db:"name" json:"name"`
System bool `db:"system" json:"system"`
Schema schema.Schema `db:"schema" json:"schema"`
ListRule *string `db:"listRule" json:"listRule"`
ViewRule *string `db:"viewRule" json:"viewRule"`
CreateRule *string `db:"createRule" json:"createRule"`
UpdateRule *string `db:"updateRule" json:"updateRule"`
DeleteRule *string `db:"deleteRule" json:"deleteRule"`
}
func (*Collection) BaseFilesPath ¶
func (m *Collection) BaseFilesPath() string
BaseFilesPath returns the storage dir path used by the collection.
func (*Collection) TableName ¶
func (m *Collection) TableName() string
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 ¶ added in v0.3.0
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()
UnmarkAsNew()
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.
type Param ¶
type Record ¶
type Record struct {
BaseModel
// contains filtered or unexported fields
}
func NewRecord ¶
func NewRecord(collection *Collection) *Record
NewRecord initializes a new empty Record model.
func NewRecordFromNullStringMap ¶
func NewRecordFromNullStringMap(collection *Collection, data dbx.NullStringMap) *Record
NewRecordFromNullStringMap initializes a single new Record model with data loaded from the provided NullStringMap.
func NewRecordsFromNullStringMaps ¶
func NewRecordsFromNullStringMaps(collection *Collection, rows []dbx.NullStringMap) []*Record
NewRecordsFromNullStringMaps initializes a new Record model for each row in the provided NullStringMap slice.
func (*Record) BaseFilesPath ¶
BaseFilesPath returns the storage dir path used by the record.
func (*Record) Collection ¶
func (m *Record) Collection() *Collection
Collection returns the Collection model associated to the current Record model.
func (*Record) ColumnValueMap ¶
ColumnValueMap implements ColumnValueMapper interface.
func (*Record) FindFileFieldByFile ¶
func (m *Record) FindFileFieldByFile(filename string) *schema.SchemaField
FindFileFieldByFile returns the first file type field for which any of the record's data contains the provided filename.
func (*Record) GetBoolDataValue ¶
GetBoolDataValue returns the data value for `key` as a bool.
func (*Record) GetDataValue ¶
GetDataValue returns the current record's data value for `key`.
Returns nil if data value with `key` is not found or set.
func (*Record) GetDateTimeDataValue ¶
GetDateTimeDataValue returns the data value for `key` as a DateTime instance.
func (*Record) GetExpand ¶
GetExpand returns a shallow copy of the optional `expand` data attached to the current Record model.
func (*Record) GetFloatDataValue ¶
GetFloatDataValue returns the data value for `key` as a float64.
func (*Record) GetIntDataValue ¶
GetIntDataValue returns the data value for `key` as an int.
func (*Record) GetStringDataValue ¶
GetStringDataValue returns the data value for `key` as a string.
func (*Record) GetStringSliceDataValue ¶
GetStringSliceDataValue returns the data value for `key` as a slice of unique strings.
func (*Record) GetTimeDataValue ¶
GetTimeDataValue returns the data value for `key` as a time.Time instance.
func (Record) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
Only the data exported by `PublicExport()` will be serialized.
func (*Record) PublicExport ¶
PublicExport exports only the record fields that are safe to be public.
This method also skips the "hidden" fields, aka. fields prefixed with `#`.
func (*Record) SetDataValue ¶
SetDataValue sets the provided key-value data pair for the current Record model.
This method does nothing if the record doesn't have a `key` field.
func (*Record) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Request ¶
type Request struct {
BaseModel
Url string `db:"url" json:"url"`
Method string `db:"method" json:"method"`
Status int `db:"status" json:"status"`
Auth string `db:"auth" json:"auth"`
Ip string `db:"ip" json:"ip"`
Referer string `db:"referer" json:"referer"`
UserAgent string `db:"userAgent" json:"userAgent"`
Meta types.JsonMap `db:"meta" json:"meta"`
}
type User ¶
type User struct {
BaseAccount
Verified bool `db:"verified" json:"verified"`
LastVerificationSentAt types.DateTime `db:"lastVerificationSentAt" json:"lastVerificationSentAt"`
// profile rel
Profile *Record `db:"-" json:"profile"`
}