Documentation ¶
Overview ¶
Package gomodel provides a simple and eloquent way to interact with the GORM ORM.
Index ¶
- func Create(db *gorm.DB, m ModelInterface) error
- func CreateOrUpdate(db *gorm.DB, m ModelInterface) error
- func Delete(db *gorm.DB, m ModelInterface, id int64) error
- func Exist(db *gorm.DB, m ModelInterface, id int64, withTrashed bool) bool
- func Find[t ModelInterface](db *gorm.DB, m t, id int64, relations ...string) (t, error)
- func Restore(db *gorm.DB, m ModelInterface, id int64) error
- func Update(db *gorm.DB, m ModelInterface) error
- type Model
- func (m *Model[t]) All() ([]t, error)
- func (m *Model[t]) Create(model t) (*Model[t], error)
- func (m *Model[t]) CreateOrUpdate(model t) (*Model[t], error)
- func (m *Model[t]) Delete() error
- func (m *Model[t]) Exist() bool
- func (m *Model[t]) Find(id int64) (t, error)
- func (m *Model[t]) FindModel(id int64) (*Model[t], error)
- func (m *Model[t]) Fresh() error
- func (m *Model[t]) Get() (t, error)
- func (m *Model[t]) MustCreate(model t) *Model[t]
- func (m *Model[t]) MustCreateOrUpdate(model t) *Model[t]
- func (m *Model[t]) MustUpdate(model t) *Model[t]
- func (m *Model[t]) Query() *gorm.DB
- func (m *Model[t]) Restore() error
- func (m *Model[t]) Save() (*Model[t], error)
- func (m *Model[t]) Set(model t) *Model[t]
- func (m *Model[t]) Update(model t) (*Model[t], error)
- func (m *Model[t]) With(relations ...string) *Model[t]
- func (m *Model[t]) WithTrashed() *Model[t]
- type ModelInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateOrUpdate ¶
func CreateOrUpdate(db *gorm.DB, m ModelInterface) error
Types ¶
type Model ¶
type Model[t ModelInterface] struct { Base t DB *gorm.DB // contains filtered or unexported fields }
func New ¶
func New[t ModelInterface](db *gorm.DB, m t) *Model[t]
New instantiate a new Model for the given t type.
func (*Model[t]) CreateOrUpdate ¶
func (*Model[t]) Exist ¶
Exist return true if the model with the primary key (id) exists in the database.
func (*Model[t]) MustCreate ¶
func (*Model[t]) MustCreateOrUpdate ¶
func (*Model[t]) MustUpdate ¶
func (*Model[t]) Save ¶
Save the model to the database. If the model doesn't exist yet, it will be created. Otherwise, it will be updated.
func (*Model[t]) Set ¶
Set sets the internal model to the given model, but doesn't save it to the database.
func (*Model[t]) WithTrashed ¶
WithTrashed returns a new Model with the withTrashed flag set to true.
Click to show internal directories.
Click to hide internal directories.