persistence

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSourceModelNil                 = errors.New("source model can't be nil")
	ErrSystemConfigModelNil           = errors.New("system config model can't be nil")
	ErrStackModelNil                  = errors.New("stack model can't be nil")
	ErrProjectModelNil                = errors.New("project model can't be nil")
	ErrFailedToGetSourceProviderType  = errors.New("failed to parse source provider type")
	ErrFailedToGetSourceRemote        = errors.New("failed to parse source remote")
	ErrFailedToGetStackState          = errors.New("failed to parse stack state")
	ErrFailedToConvertSourceToEntity  = errors.New("failed to convert source model to entity")
	ErrFailedToConvertProjectToEntity = errors.New("failed to convert project model to entity")
	ErrFailedToConvertOrgToEntity     = errors.New("failed to convert org model to entity")
	ErrFailedToConvertBackendToEntity = errors.New("failed to convert backend model to entity")
	ErrOrganizationModelNil           = errors.New("organization model can't be nil")
	ErrWorkspaceModelNil              = errors.New("workspace model can't be nil")
	ErrBackendModelNil                = errors.New("backend model can't be nil")
)

Functions

func CloseDB

func CloseDB(t *testing.T, gdb *gorm.DB)

Close the gorm database connection

func GetMockDB

func GetMockDB() (*gorm.DB, sqlmock.Sqlmock, error)

Create a mock database connection

func NewBackendRepository

func NewBackendRepository(db *gorm.DB) repository.BackendRepository

NewBackendRepository creates a new backend 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 NewSourceRepository

func NewSourceRepository(db *gorm.DB) repository.SourceRepository

NewSourceRepository creates a new source repository.

func NewStackRepository

func NewStackRepository(db *gorm.DB) repository.StackRepository

NewStackRepository creates a new stack repository.

func NewWorkspaceRepository

func NewWorkspaceRepository(db *gorm.DB) repository.WorkspaceRepository

NewWorkspaceRepository creates a new workspace repository.

Types

type BackendModel

type BackendModel struct {
	gorm.Model
	Name          string `gorm:"index:unique_backend,unique"`
	Type          string `gorm:"index:unique_backend,unique"`
	Description   string
	Labels        MultiString
	Owners        MultiString
	BackendConfig v1.BackendConfig `gorm:"serializer:json" json:"backendConfig"`
}

BackendModel is a DO used to map the entity to the database.

func (*BackendModel) FromEntity

func (m *BackendModel) FromEntity(e *entity.Backend) error

FromEntity converts an entity to a DO.

func (*BackendModel) TableName

func (m *BackendModel) TableName() string

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

func (*BackendModel) ToEntity

func (m *BackendModel) ToEntity() (*entity.Backend, error)

ToEntity converts the DO to an entity.

type MultiString

type MultiString []string

MultiString is a custom type for handling arrays of strings with GORM.

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 {
	gorm.Model
	Name        string `gorm:"index:unique_org,unique"`
	Description string
	Labels      MultiString
	Owners      MultiString
}

OrganizationModel is a DO used to map the entity to the database.

func (*OrganizationModel) FromEntity

func (m *OrganizationModel) FromEntity(e *entity.Organization) error

FromEntity converts an entity to a DO.

func (*OrganizationModel) TableName

func (m *OrganizationModel) TableName() string

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

func (*OrganizationModel) ToEntity

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

ToEntity converts the DO to an entity.

func (*OrganizationModel) ToEntityWithSource

func (m *OrganizationModel) ToEntityWithSource(sourceEntity *entity.Source) (*entity.Organization, error)

ToEntity converts the DO to an entity.

type ProjectModel

type ProjectModel struct {
	gorm.Model
	Name           string `gorm:"index:unique_project,unique"`
	SourceID       uint
	Source         *SourceModel `gorm:"foreignKey:ID;references:SourceID"`
	OrganizationID uint
	Organization   *OrganizationModel `gorm:"foreignKey:ID;references:OrganizationID"`
	Path           string             `gorm:"index:unique_project,unique"`
	Description    string
	Labels         MultiString
	Owners         MultiString
}

ProjectModel is a DO used to map the entity to the database.

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.

func (*ProjectModel) ToEntityWithSourceAndOrg

func (m *ProjectModel) ToEntityWithSourceAndOrg(sourceEntity *entity.Source, organizationEntity *entity.Organization) (*entity.Project, error)

ToEntity converts the DO to an entity.

type SourceModel

type SourceModel struct {
	gorm.Model
	// SourceProvider is the type of the source provider.
	SourceProvider string `gorm:"index:unique_source,unique"`
	// Remote is the source URL, including scheme.
	Remote string `gorm:"index:unique_source,unique"`
	// Description is a human-readable description of the source.
	Description string
	// Labels are custom labels associated with the source.
	Labels MultiString
	// Owners is a list of owners for the source.
	Owners MultiString
}

SourceModel is a DO used to map the entity to the database.

func (*SourceModel) FromEntity

func (m *SourceModel) FromEntity(e *entity.Source) error

FromEntity converts an entity to a DO.

func (*SourceModel) TableName

func (m *SourceModel) TableName() string

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

func (*SourceModel) ToEntity

func (m *SourceModel) ToEntity() (*entity.Source, error)

ToEntity converts the DO to an entity.

type StackModel

type StackModel struct {
	gorm.Model
	Name string `gorm:"index:unique_project,unique"`
	// SourceID          uint
	// Source            *SourceModel
	ProjectID uint
	Project   *ProjectModel
	// OrganizationID    uint
	// Organization      *OrganizationModel
	Description       string
	Path              string `gorm:"index:unique_project,unique"`
	DesiredVersion    string
	Labels            MultiString
	Owners            MultiString
	SyncState         string
	LastSyncTimestamp time.Time
}

StackModel is a DO used to map the entity to the database.

func (*StackModel) FromEntity

func (m *StackModel) FromEntity(e *entity.Stack) error

FromEntity converts an entity to a DO.

func (*StackModel) TableName

func (m *StackModel) TableName() string

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

func (*StackModel) ToEntity

func (m *StackModel) ToEntity(ctx context.Context) (*entity.Stack, error)

ToEntity converts the DO to an entity.

type WorkspaceModel

type WorkspaceModel struct {
	gorm.Model
	Name        string `gorm:"index:unique_workspace,unique"`
	Description string
	Labels      MultiString
	Owners      MultiString
	BackendID   uint
	Backend     *BackendModel `gorm:"foreignKey:ID;references:BackendID"`
}

WorkspaceModel is a DO used to map the entity to the database.

func (*WorkspaceModel) FromEntity

func (m *WorkspaceModel) FromEntity(e *entity.Workspace) error

FromEntity converts an entity to a DO.

func (*WorkspaceModel) TableName

func (m *WorkspaceModel) TableName() string

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

func (*WorkspaceModel) ToEntity

func (m *WorkspaceModel) ToEntity() (*entity.Workspace, error)

ToEntity converts the DO to an entity.

Jump to

Keyboard shortcuts

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