sqlite

package
v0.0.0-...-f96b470 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package sqlite implements the sqlite repository.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateAndSeed

func MigrateAndSeed(db *gorm.DB, logger *slog.Logger, options *MigrationOptions) error

MigrateAndSeed migrates the sqlite database and seeds it with initial data.

Types

type APIKey

type APIKey struct {
	BaseModel
	Name      string    `gorm:"index:idx_api_key_name_user_id_unique,unique"`
	Key       string    `gorm:"uniqueIndex"`
	UserID    uuid.UUID `gorm:"index:idx_api_key_name_user_id_unique,unique"`
	IsDefault bool
}

APIKey is the sqlite model for storing API Keys.

type APIKeyRepository

type APIKeyRepository struct {
	// contains filtered or unexported fields
}

APIKeyRepository is the sqlite repository for storing API Keys.

func NewAPIKeyRepository

func NewAPIKeyRepository(conn *gorm.DB) *APIKeyRepository

NewAPIKeyRepository initialises the sqlite API Key repository.

func (*APIKeyRepository) CreateAPIKey

func (r *APIKeyRepository) CreateAPIKey(ctx context.Context, createAPIKeyRequest *domain.CreateAPIKeyRequest) (*domain.APIKey, error)

CreateAPIKey creates an API Key in sqlite.

func (*APIKeyRepository) DeleteAPIKey

func (r *APIKeyRepository) DeleteAPIKey(ctx context.Context, id uuid.UUID) error

DeleteAPIKey deletes an API Key from sqlite.

func (*APIKeyRepository) GetForNameAndUserID

func (r *APIKeyRepository) GetForNameAndUserID(ctx context.Context, getAPIKeyForNameAndUserIDRequest *domain.GetAPIKeyForNameAndUserIDRequest) (*domain.APIKey, error)

GetForNameAndUserID returns an API Key for a given name and user id.

func (*APIKeyRepository) UpdateKey

func (r *APIKeyRepository) UpdateKey(ctx context.Context, updateAPIKeyRequest *domain.UpdateAPIKeyRequest) error

UpdateKey updates the key of an API Key.

func (*APIKeyRepository) Validate

func (r *APIKeyRepository) Validate(ctx context.Context, s string) (uuid.UUID, error)

Validate returns true if the key is valid.

type BaseModel

type BaseModel struct {
	gorm.Model
	ID uuid.UUID `gorm:"type:uuid;primarykey"`
}

BaseModel is the base model for all sqlite models.

func (*BaseModel) BeforeCreate

func (u *BaseModel) BeforeCreate(_ *gorm.DB) (err error)

BeforeCreate ensures that the ID is set to a uuid value before inserting into the database.

type MigrationOptions

type MigrationOptions struct {
	APIKey string
}

MigrationOptions represents the options for the sqlite migration.

type Project

type Project struct {
	BaseModel
	Name      string `gorm:"uniqueIndex"`
	Scenarios []*Scenario
}

Project is the sqlite project model.

type ProjectRepository

type ProjectRepository struct {
	// contains filtered or unexported fields
}

ProjectRepository is the sqlite repository for projects.

func NewProjectRepository

func NewProjectRepository(conn *gorm.DB) *ProjectRepository

NewProjectRepository initialises the sqlite project repository.

func (*ProjectRepository) Create

Create creates a new project in sqlite.

func (*ProjectRepository) GetByID

func (r *ProjectRepository) GetByID(ctx context.Context, id uuid.UUID) (*domain.Project, error)

GetByID returns a project from sqlite by id.

func (*ProjectRepository) GetByName

func (r *ProjectRepository) GetByName(ctx context.Context, name string) (*domain.Project, error)

GetByName returns a project from sqlite by name.

func (*ProjectRepository) List

func (r *ProjectRepository) List(ctx context.Context, getProjectsRequest *domain.ListProjectsRequest) ([]*domain.Project, error)

List returns all projects from sqlite.

type Repository

type Repository struct {
	ProjectRepository  *ProjectRepository
	ScenarioRepository *ScenarioRepository
	RunRepository      *RunRepository
	APIKeyRepository   *APIKeyRepository
	UserRepository     *UserRepository
}

Repository is the sqlite repository.

func NewRepository

func NewRepository(dsn string, logger *slog.Logger, options *MigrationOptions) (*Repository, error)

NewRepository initialises the sqlite repository.

type Run

type Run struct {
	BaseModel
	ProjectID       uuid.UUID `gorm:"type:uuid;index:idx_project_id"`
	Success         bool
	State           RunState
	ErrorMessage    string
	ScenarioDetails []byte
}

Run is the sqlite model for runs.

type RunRepository

type RunRepository struct {
	// contains filtered or unexported fields
}

RunRepository is the sqlite repository for runs.

func NewRunRepository

func NewRunRepository(conn *gorm.DB) *RunRepository

NewRunRepository initialises the sqlite run repository.

func (*RunRepository) Create

func (r *RunRepository) Create(ctx context.Context, createRunRequest *domain.CreateRunRequest) (*domain.Run, error)

Create creates a new run in sqlite.

func (*RunRepository) Get

func (r *RunRepository) Get(ctx context.Context, id uuid.UUID) (*domain.Run, error)

Get returns a run from sqlite for a given id.

func (*RunRepository) ListForProject

func (r *RunRepository) ListForProject(ctx context.Context, getForProjectRequest *domain.ListRunsForProjectRequest) ([]*domain.Run, error)

ListForProject returns all runs for a given project list runs request.

func (*RunRepository) Update

func (r *RunRepository) Update(ctx context.Context, updateRunRequest *domain.UpdateRunRequest) (*domain.Run, error)

Update updates a run in sqlite.

type RunState

type RunState string

RunState is the state of a run.

const (
	RunStatePending   RunState = "pending"
	RunStateRunning   RunState = "running"
	RunStateCompleted RunState = "success"
	RunStateFailure   RunState = "failure"
	RunstateCancelled RunState = "cancelled"
)

different run states.

type Scenario

type Scenario struct {
	BaseModel
	Name      string `gorm:"index:idx_project_id_name_unique,unique"`
	SpecType  string
	Spec      string
	ProjectID uuid.UUID `gorm:"index:idx_project_id_name_unique,unique"`
}

Scenario is the sqlite model for scenarios.

type ScenarioDetails

type ScenarioDetails struct {
	Name       string        `json:"name"`
	Duration   time.Duration `json:"duration"`
	Assertions int           `json:"assertions"`
	Steps      []*Step       `json:"steps"`
	Success    bool          `json:"success"`
}

ScenarioDetails is the json model for scenario run details.

type ScenarioRepository

type ScenarioRepository struct {
	// contains filtered or unexported fields
}

ScenarioRepository is the sqlite repository for projects.

func NewScenarioRepository

func NewScenarioRepository(conn *gorm.DB) *ScenarioRepository

NewScenarioRepository initialises the sqlite scenario repository.

func (*ScenarioRepository) Create

func (r *ScenarioRepository) Create(ctx context.Context, createScenarioRequest *domain.CreateScenarioRequest) (*domain.Scenario, error)

Create creates a new scenario in sqlite.

func (*ScenarioRepository) GetForProject

func (r *ScenarioRepository) GetForProject(ctx context.Context, getForProjectRequest *domain.GetScenariosForProjectRequest) ([]*domain.Scenario, error)

GetForProject returns all scenarios for a given project.

type Step

type Step struct {
	Name            string        `json:"name"`
	Assertions      int           `json:"assertions"`
	URL             string        `json:"url"`
	RequestDuration time.Duration `json:"request_duration"`
	Duration        time.Duration `json:"duration"`
	Retries         int           `json:"retries"`
	Success         bool          `json:"success"`
}

Step is the json model for scenario step run details.

type User

type User struct {
	BaseModel
	Name string `gorm:"uniqueIndex"`
}

User is the sqlite model for users.

type UserRepository

type UserRepository struct {
	// contains filtered or unexported fields
}

UserRepository is the sqlite repository for users.

func NewUserRepository

func NewUserRepository(conn *gorm.DB) *UserRepository

NewUserRepository initialises the sqlite user repository.

func (*UserRepository) CreateUser

func (r *UserRepository) CreateUser(ctx context.Context, name string) (*domain.User, error)

CreateUser creates a user in sqlite.

func (*UserRepository) GetUserByName

func (r *UserRepository) GetUserByName(ctx context.Context, name string) (*domain.User, error)

GetUserByName returns a user from sqlite by name.

Jump to

Keyboard shortcuts

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