models

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserModelNil                = errors.New("user model is nil")
	ErrOrganizationModelNil        = errors.New("organization model is nil")
	ErrProjectModelNil             = errors.New("project model is nil")
	ErrFailedToConvertOrgToEntity  = errors.New("failed to convert organization to entity")
	ErrFailedToConvertUserToEntity = errors.New("failed to convert user to entity")
	ErrBlogModelNil                = errors.New("blog model is nil")
)
View Source
var LoadModels = []interface{}{
	&UserModel{},
	&OrganizationModel{},
	&ProjectModel{},
	&BlogModel{},
}

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

func CombineQueryParts

func CombineQueryParts(queryParts []string) string

func GetProjectQuery

func GetProjectQuery(filter *entity.ProjectFilter) (string, []interface{})

func NewBlogRepository

func NewBlogRepository(db *gorm.DB) repository.BlogRepository

NewBlogRepository creates a new blog repository.

func NewOrganizationRepository

func NewOrganizationRepository(db *gorm.DB) repository.OrganizationRepository

NewOrganizationRepository creates a new organization repository.

func NewProjectRepository

func NewProjectRepository(db *gorm.DB) repository.ProjectRepository

NewProjectRepository creates a new project repository.

func NewUserRepository

func NewUserRepository(db *gorm.DB) repository.UserRepository

Types

type BaseModel

type BaseModel struct {
	gorm.Model
	ID          uuid.UUID `gorm:"type:uuid;primary_key"`
	Description string
}

func (*BaseModel) BeforeCreate

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

type BlogModel

type BlogModel struct {
	ResourceModel
	Path    string `gorm:"index:unique_blog,unique"`
	RawData []byte `gorm:"type:bytea"`
}

func (*BlogModel) FromEntity

func (m *BlogModel) FromEntity(e *entity.Blog) error

FromEntity converts an entity to a DO.

func (*BlogModel) TableName

func (m *BlogModel) TableName() string

TableName returns the name of the database table that the struct is mapped to.

func (*BlogModel) ToEntity

func (m *BlogModel) ToEntity() (*entity.Blog, error)

ToEntity converts the DO to an entity.

type MultiString

type MultiString []string

func (MultiString) GormDBDataType

func (s MultiString) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type

func (MultiString) GormDataType

func (s MultiString) GormDataType() string

GormDataType gorm common data type

func (*MultiString) Scan

func (s *MultiString) Scan(src any) error

Scan implements the Scanner interface for the MultiString type.

func (MultiString) Value

func (s MultiString) Value() (driver.Value, error)

Value implements the Valuer interface for the MultiString type.

type OrganizationModel

type OrganizationModel struct {
	BaseModel
	Name   string      `gorm:"index:unique_organization,unique"`
	Labels MultiString `gorm:"type:text[]"`
}

func (*OrganizationModel) FromEntity

func (o *OrganizationModel) FromEntity(entity *entity.Organization) error

func (*OrganizationModel) TableName

func (o *OrganizationModel) TableName() string

func (*OrganizationModel) ToEntity

func (o *OrganizationModel) ToEntity() (*entity.Organization, error)

type OrganizationRole

type OrganizationRole string
const (
	OrganizationRoleOwner OrganizationRole = "owner"
	OrganizationRoleAdmin OrganizationRole = "admin"
	OrganizationRoleUser  OrganizationRole = "user"
)

type ProjectModel

type ProjectModel struct {
	ResourceModel
	Name           string `gorm:"index:unique_project,unique"`
	OrganizationID uuid.UUID
	Organization   *OrganizationModel `gorm:"foreignKey:OrganizationID;references:ID"`
	Path           string             `gorm:"index:unique_project,unique"`
	Labels         MultiString
}

func (*ProjectModel) FromEntity

func (m *ProjectModel) FromEntity(e *entity.Project) error

FromEntity converts an entity to a DO.

func (*ProjectModel) TableName

func (m *ProjectModel) TableName() string

The TableName method returns the name of the database table that the struct is mapped to.

func (*ProjectModel) ToEntity

func (m *ProjectModel) ToEntity() (*entity.Project, error)

ToEntity converts the DO to an entity.

type ResourceModel

type ResourceModel struct {
	BaseModel
	CreatedByID uuid.UUID
	CreatedBy   *UserModel `gorm:"foreignKey:CreatedByID;references:ID"`
}

func (*ResourceModel) BeforeCreate

func (r *ResourceModel) BeforeCreate(tx *gorm.DB) error

type UserModel

type UserModel struct {
	BaseModel
	Name     string
	Username string `gorm:"index:unique_user,unique"`
	Email    string `gorm:"index:unique_user,unique"`
	Password string `json:"-"`
}

func (*UserModel) FromEntity

func (u *UserModel) FromEntity(entity *entity.User) error

func (*UserModel) TableName

func (u *UserModel) TableName() string

func (*UserModel) ToEntity

func (u *UserModel) ToEntity() (*entity.User, error)

Jump to

Keyboard shortcuts

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