database

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTaskRepository

func NewTaskRepository(tasks map[int]*task.Task, DB DatabaseHandler) task.TaskRepository

NewTaskRepository returns a new repository initialized with the given tasks and database handler

Types

type DatabaseHandler

type DatabaseHandler interface {
	// GetConnection stablishes connection with a given type of database
	GetConnection(conString string) error

	// GetAllTasks retrieves all tasks from a given type of database
	GetAllTasks() (map[int]*task.Task, error)

	// CreateNewTask creates a new task in a given type of database
	CreateNewTask(name string) error

	// DeleteTask deletes a given task from a given type of database
	DeleteTask(id int) error

	// CheckTask modifies a given task from a given type of database
	CheckTask(id int) error
}

Interface for accesses to a database

type PostgresHandler

type PostgresHandler struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

Type to access a Postgresql database Implements DatabaseHandler

func NewPostgres

func NewPostgres(db *sql.DB, ctx context.Context) *PostgresHandler

NewPostgres returns a new PostgresHandler element

func (*PostgresHandler) CheckTask added in v0.1.3

func (handler *PostgresHandler) CheckTask(id int) error

CheckTask marks a given task as done

func (*PostgresHandler) CreateNewTask

func (handler *PostgresHandler) CreateNewTask(name string) error

CreateNewTask creates a new task in the database

func (*PostgresHandler) DeleteTask

func (handler *PostgresHandler) DeleteTask(id int) error

DeleteTask deletes a given task from the database

func (*PostgresHandler) GetAllTasks

func (handler *PostgresHandler) GetAllTasks() (map[int]*task.Task, error)

GetAllTasks retrieves all tasks from the database and returns a map with the tasks formatted for the application to use (type of Task)

func (*PostgresHandler) GetConnection

func (handler *PostgresHandler) GetConnection(conString string) error

GetConnection stablish a connection with the database

Jump to

Keyboard shortcuts

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