models

package
v0.0.0-...-a2ff9df Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsModel

func AsModel[Model any](i InternalValue) (Model, error)

AsModel decodes an InternalValue to a model. It uses mapstructure package to do so.

Types

type BaseModel

type BaseModel struct {
	ID        uuid.UUID `gorm:"type:uuid;primary_key;" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

BaseModel contains common columns for all tables.

func (*BaseModel) BeforeCreate

func (base *BaseModel) BeforeCreate(tx *gorm.DB) error

BeforeCreate will set a UUID rather than numeric ID.

type InternalValue

type InternalValue map[string]any

InternalValue is a map that holds model data. It is used to avoid heavy use of reflection during read operations.

func AsInternalValue

func AsInternalValue[Model any](entity Model) InternalValue

AsInternalValue Uses reflect package to do a shallow translation of the model to a map wrapped in an InternalValue. We could use mapstructure, but it does a deep translation, which is not what we want.

type SliceField

type SliceField[T any] []T

SliceField is a field that represents a slice of any type

func (*SliceField[T]) FromRepresentation

func (s *SliceField[T]) FromRepresentation(rawValue any) error

func (*SliceField[T]) Scan

func (s *SliceField[T]) Scan(value any) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (SliceField[T]) ToRepresentation

func (s SliceField[T]) ToRepresentation() (any, error)

func (SliceField[T]) Value

func (s SliceField[T]) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

Jump to

Keyboard shortcuts

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