psql

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package psql used for storing data in PostgreSQL database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(cfg Config) (*sql.DB, error)

NewDB creates and validates new db connection

Types

type Auth

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

Auth represents repository for authorization and authentication

func NewAuth

func NewAuth(db *sql.DB) *Auth

NewAuth return instance of auth repository

func (*Auth) CreateUser

func (r *Auth) CreateUser(u core.User) (core.User, error)

CreateUser creates new user in DB

func (*Auth) GetUser

func (r *Auth) GetUser(username, pwd string) (core.User, error)

GetUser returns user from DB by username and password

type Config

type Config struct {
	Host     string
	Port     string
	Username string
	Password string
	DBName   string
	SSLMode  string
	Logger   *zap.Logger
}

Config represents all required fields for connecting to postgres db

func (Config) String

func (cfg Config) String() string

String returns connection string from config

type Storage

type Storage struct {
	Auth     *Auth
	TodoList *TodoList
	TodoItem *TodoItem
}

Storage contains all implemented repositories

func NewStorage

func NewStorage(db *sql.DB) *Storage

NewStorage returns all implemented repositories

type TodoItem

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

TodoItem represents Todo repository

func NewTodoItem

func NewTodoItem(db *sql.DB) *TodoItem

NewTodoItem returns instance of Todo repository

func (*TodoItem) CreateTodo

func (r *TodoItem) CreateTodo(listID int, t core.TodoItem) (core.TodoItem, error)

CreateTodo creates new Todo in DB and links it to the List

func (*TodoItem) DeleteTodo

func (r *TodoItem) DeleteTodo(todoID int) error

DeleteTodo removes todo from DB by ID

func (*TodoItem) GetAllTodos

func (r *TodoItem) GetAllTodos(listID int) ([]core.TodoItem, error)

GetAllTodos returns all todos which related to the given List

func (*TodoItem) GetTodoByID

func (r *TodoItem) GetTodoByID(listID, todoID int) (core.TodoItem, error)

GetTodoByID returns todo by ID which related to the given list

func (*TodoItem) UpdateTodo

func (r *TodoItem) UpdateTodo(todoID int, data core.UpdateItemData) (core.TodoItem, error)

UpdateTodo save Todo changes to the db

type TodoList

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

TodoList represents List of todos repository

func NewTodoList

func NewTodoList(db *sql.DB) *TodoList

NewTodoList returns instance of List repository

func (*TodoList) CreateList

func (r *TodoList) CreateList(userID int, l core.Todolist) (core.Todolist, error)

CreateList creates new List in the DB and links it to the given User

func (*TodoList) DeleteList

func (r *TodoList) DeleteList(listID int) error

DeleteList removes List from DB by ID

func (*TodoList) GetAllLists

func (r *TodoList) GetAllLists(userID int) ([]core.Todolist, error)

GetAllLists returns all lists from DB which belong to the given User

func (*TodoList) GetListByID

func (r *TodoList) GetListByID(userID, listID int) (core.Todolist, error)

GetListByID returns list by ID from DB which belongs to the given User

func (*TodoList) UpdateList

func (r *TodoList) UpdateList(listID int, data core.UpdateListData) (core.Todolist, error)

UpdateList save changes of list to the DB

Jump to

Keyboard shortcuts

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