mysql

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MySQL

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

Middleware for interacting with the MySQL database.

This implements the database.Database interface and, therefore, provides all methods defined in it.

func (m *MySQL) CreateShortlink(shortlinkToCreate *models.ShortlinkToCreate, user *models.User) bool

Inserts the passed shortlink into the database and therefore finalizes its creation.

func (*MySQL) CreateUser

func (m *MySQL) CreateUser(user *models.User) bool

Inserts the passed user into the database.

func (m *MySQL) DeleteShortlink(short string) (int64, error)

Revokes/deletes a shortlink from the database. The shortlink is identified by its unique part.

func (m *MySQL) GetShortlink(short string) (models.Shortlink, error)

Obtains a shortlink from the database by it's unique part.

func (m *MySQL) GetShortlinkList(user *models.User) ([]models.Shortlink, error)

Returns a list of all the user's shortlinks.

func (*MySQL) GetUser

func (m *MySQL) GetUser(username string) (*models.User, error)

Obtains a full user from the database by their username.

func (*MySQL) Init

func (m *MySQL) Init() error

Checks whether all needed tables exist and if not, it automatically creates them as well as an admin user.

func (*MySQL) IsShortlinkTaken

func (m *MySQL) IsShortlinkTaken(short string) bool

Performs a DB lookup for the passed unique part of a shortlink and checks whether or not it is already taken by a shortlink

func (*MySQL) Open

func (m *MySQL) Open(config *config.Config) error

Opens a database connection that is safe for concurrent use as it utilizes a connection pool. Reference: https://pkg.go.dev/database/sql#Open

func (*MySQL) ValidateUser

func (m *MySQL) ValidateUser(user *models.User) int

Validates whether or not a user is okay to be created.

Jump to

Keyboard shortcuts

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