model

package
v0.0.0-...-d3a19af Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {

	// ID is the unique identifier of the object of the model.
	// It is generated automatically when the object is created. So, you cannot pass a custom value for it.
	//
	// Example: "550e8400-e29b-41d4-a716-446655440000"
	ID uuid.UUID `json:"id" gorm:"primaryKey;not null;type:uuid"`

	// CreatedAt is the time when the object was created.
	// It is set automatically when the object is created.
	//
	// Example: "2021-07-01T12:00:00Z"
	CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`

	// UpdatedAt is the time when the object was last updated.
	// It is set automatically when the object is updated.
	//
	// Example: "2021-07-01T12:00:00Z"
	UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`

	// DeletedAt is the time when the object was deleted.
	// It is set automatically when the object is marked deleted.
	// Generally, used for soft deletes (marking records as deleted without actually removing them from the database).
	//
	// Example: "2021-07-01T12:00:00Z"
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

func (*Base) BeforeCreate

func (b *Base) BeforeCreate(tx *gorm.DB) error

BeforeCreate hook for gorm. This function is called by gorm before creating a record.

It performs the following operations:

- Generates a new UUID for the record.

type Record

type Record struct {
	Base

	// Title of the record.
	//
	// Example: "Test Record"
	//
	// It is a required field.
	Title string `json:"title" gorm:"not null;check:(length(title)>0)"`

	//	ID of the user who created the record.
	//
	//	Example: "550e8400-e29b-41d4-a716-446655440000"
	//
	//	It is a required field.
	UserID uuid.UUID `json:"user_id" gorm:"not null;type:uuid"`
}

Jump to

Keyboard shortcuts

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