models

package
v0.0.0-...-185ece4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package models implements all PocketBase DB models and DTOs.

Index

Constants

View Source
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

func (m *BaseModel) GetCreated() types.DateTime

GetCreated returns the model Created datetime.

func (*BaseModel) GetId

func (m *BaseModel) GetId() string

GetId returns the model id.

func (*BaseModel) GetUpdated

func (m *BaseModel) GetUpdated() types.DateTime

GetUpdated returns the model Updated datetime.

func (*BaseModel) HasId

func (m *BaseModel) HasId() bool

HasId returns whether the model has a nonzero id.

func (*BaseModel) IsNew

func (m *BaseModel) IsNew() bool

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

func (m *BaseModel) PostScan() error

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.

func (*BaseModel) SetId

func (m *BaseModel) SetId(id string)

SetId sets the model id to the provided string value.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL