repository

package
v0.0.0-...-8cb9352 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	ID      uint   `gorm:"primaryKey"`  // Primary key for the migration
	Version string `gorm:"uniqueIndex"` // Unique version identifier for each migration
}

Migration represents a database migration entry. Each migration is uniquely identified by a version string.

type Migrator

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

Migrator is responsible for applying database migrations. It holds a list of migrations, each associated with a version and a function that applies the migration.

func NewMigrator

func NewMigrator() *Migrator

NewMigrator initializes a new Migrator with a list of migrations.

Each migration is represented by a version string and a function that performs the migration. In this case, the initial migration (version "1.0") creates the `Project` and `Task` tables.

func (*Migrator) Migrate

func (m *Migrator) Migrate(db *gorm.DB) error

Migrate applies any pending migrations to the database.

It first ensures that the `Migration` table exists, then checks the latest applied migration. Migrations that have a version greater than the last applied one are executed sequentially. After each migration is applied, a record is inserted into the `Migration` table.

type Repository

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

Repository manages the database connection and migrations for the application. It encapsulates the GORM database instance and a migrator responsible for applying database migrations.

func NewRepository

func NewRepository() (*Repository, error)

NewRepository initializes a new Repository instance, setting up the SQLite database connection. It also configures a custom GORM logger and applies any pending migrations.

func (*Repository) Close

func (r *Repository) Close() error

Close closes the database connection gracefully. It retrieves the underlying SQL database object from GORM and calls its Close method.

func (*Repository) CreateProject

func (r *Repository) CreateProject(project *models.Project) error

CreateProject inserts a new project into the database.

func (*Repository) CreateTask

func (r *Repository) CreateTask(task *models.Task) error

CreateTask inserts a new task into the database.

func (*Repository) DeleteProject

func (r *Repository) DeleteProject(id int) error

DeleteProject removes a project from the database by its ID.

func (*Repository) DeleteTask

func (r *Repository) DeleteTask(id int) error

DeleteTask removes a task from the database by its ID.

func (*Repository) GetAllProjects

func (r *Repository) GetAllProjects() ([]*models.Project, error)

GetAllProjects retrieves all projects from the database.

func (*Repository) GetAllTasks

func (r *Repository) GetAllTasks() ([]*models.Task, error)

GetAllTasks retrieves all tasks from the database.

func (*Repository) GetNextProjectID

func (r *Repository) GetNextProjectID() (int, error)

GetNextProjectID retrieves the next available project ID in the database. It selects the maximum project ID and adds 1 to determine the next available ID.

func (*Repository) GetNextTaskID

func (r *Repository) GetNextTaskID() (int, error)

GetNextTaskID retrieves the next available task ID in the database. It selects the maximum task ID and adds 1 to determine the next available ID.

func (*Repository) GetProjectByID

func (r *Repository) GetProjectByID(id int) (*models.Project, error)

GetProjectByID retrieves a project from the database by its ID.

func (*Repository) GetProjectByName

func (r *Repository) GetProjectByName(name string) (*models.Project, error)

GetProjectByName retrieves a project from the database by its name.

func (*Repository) GetSubprojects

func (r *Repository) GetSubprojects(parentProjectID int) ([]*models.Project, error)

GetSubprojects retrieves all subprojects that have the given parent project ID.

func (*Repository) GetSubtasks

func (r *Repository) GetSubtasks(parentTaskID int) ([]*models.Task, error)

GetSubtasks retrieves all subtasks that have the given parent task ID.

func (*Repository) GetTaskByID

func (r *Repository) GetTaskByID(id int) (*models.Task, error)

GetTaskByID retrieves a task from the database by its ID.

func (*Repository) GetTasksByProjectID

func (r *Repository) GetTasksByProjectID(projectID int) ([]*models.Task, error)

GetTasksByProjectID retrieves all tasks associated with a specific project by the project's ID.

func (*Repository) UpdateProject

func (r *Repository) UpdateProject(project *models.Project) error

UpdateProject updates an existing project in the database.

func (*Repository) UpdateTask

func (r *Repository) UpdateTask(task *models.Task) error

UpdateTask updates an existing task in the database.

Jump to

Keyboard shortcuts

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