linkstorage

package
v0.0.0-...-1bce007 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MysqlConnect

func MysqlConnect(dbUser, dbPassword, dbHost, dbName string) (*sqlx.DB, error)

MysqlConnect creates mysql connection

func MysqlDropDB

func MysqlDropDB(dbUser, dbPassword, dbHost, dbName string) error

MysqlDropDB drops the application database

func MysqlInitStorage

func MysqlInitStorage(dbUser, dbPassword, dbHost, dbName string, createDb bool) error

MysqlInitStorage initializes MySQL storage by creating the database (optionally) and the tables

Types

type InMemoryStorage

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

InMemoryStorage stores all of the links, needs to be injected into User and Link Resource. In the real world, you would use a database for that.

func (*InMemoryStorage) Delete

func (s *InMemoryStorage) Delete(id string) error

Delete one :(

func (*InMemoryStorage) GetOne

func (s *InMemoryStorage) GetOne(id string) (*model.Link, error)

GetOne link

func (*InMemoryStorage) GetOneByShortName

func (s *InMemoryStorage) GetOneByShortName(shortName string) (*model.Link, error)

GetOneByShortName returns a link byt its short name

func (*InMemoryStorage) Insert

func (s *InMemoryStorage) Insert(c model.Link) (*model.Link, error)

Insert a fresh one

func (*InMemoryStorage) PaginatedGetAll

func (s *InMemoryStorage) PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error)

PaginatedGetAll returns a slice of links according to desired pagination and total number of items

func (*InMemoryStorage) Update

func (s *InMemoryStorage) Update(c model.Link) error

Update updates an existing link

type MysqlStorage

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

MysqlStorage defines a storage implementation that uses MySQL

func (*MysqlStorage) Delete

func (m *MysqlStorage) Delete(id string) error

Delete one :(

func (*MysqlStorage) GetOne

func (m *MysqlStorage) GetOne(id string) (*model.Link, error)

GetOne link

func (*MysqlStorage) GetOneByShortName

func (m *MysqlStorage) GetOneByShortName(shortName string) (*model.Link, error)

GetOneByShortName returns a link byt its short name

func (*MysqlStorage) Insert

func (m *MysqlStorage) Insert(c model.Link) (*model.Link, error)

Insert a fresh one

func (*MysqlStorage) PaginatedGetAll

func (m *MysqlStorage) PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error)

PaginatedGetAll returns a slice of links according to desired pagination and total number of items

func (*MysqlStorage) Update

func (m *MysqlStorage) Update(c model.Link) error

Update updates an existing link

type Storage

type Storage interface {
	PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error)
	GetOne(id string) (*model.Link, error)
	GetOneByShortName(shortName string) (*model.Link, error)
	Insert(c model.Link) (*model.Link, error)
	Delete(id string) error
	Update(c model.Link) error
}

Storage defines an interface that must be implemented in order to be used as a backend to store the links

func NewInMemoryStorage

func NewInMemoryStorage() Storage

NewInMemoryStorage initializes the storage

func NewMysqlStorage

func NewMysqlStorage(db *sqlx.DB) Storage

NewMysqlStorage initializes the MySQL storage

Jump to

Keyboard shortcuts

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