database

package
v0.0.0-...-d4b7561 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CompatVersion = 1

version defines the current migration version. This ensures the app is always compatible with the version of the database.

Variables

View Source
var (
	IncorrectPassword = errors.New("password was incorrect")
	NonexistentUser   = errors.New("user doesn't exist")
	InvalidToken      = errors.New("token is not valid")
	ExpiredToken      = errors.New("token has expired")
)
View Source
var (
	InvalidUsername = errors.New("username was invalid; must be 2-16 long, begin with a letter, and contain alphanumerics/underscores only")
	InvalidEmail    = errors.New("email was in an invalid format")
	InvalidPassword = errors.New("password was invalid; must be 5-32 long")
	// https://www.alexedwards.net/blog/validation-snippets-for-go#email-validation
	InvalidPageSize = errors.New(
		"gave an invalid page size. Pages can between 50 and 100 entries long")
)

Functions

func AddPermission

func AddPermission(giver *models.User, userId uint64,
	permission *models.Permission) error

func AuthorizeWithPassword

func AuthorizeWithPassword(usernameOrEmail, password string) (*models.User, error)

func AuthorizeWithToken

func AuthorizeWithToken(token string) (*models.User, error)

func Clear

func Clear() error

func CommitDbMigrate

func CommitDbMigrate(try func(*sql.DB) error)

func ConnectToDb

func ConnectToDb()

func CreateToken

func CreateToken(userId uint64) (string, error)

func ExperimentDb

func ExperimentDb(try func(*sql.DB) error)

func GetAuthor

func GetAuthor(authorId uint64) (*models.Author, error)

func GetBook

func GetBook(bookId uint64) (*models.Book, error)

func GetImage

func GetImage(id uint64) ([]byte, string, error)

func GetPermissions

func GetPermissions(user *models.User) ([]models.Permission, error)

func GetUser

func GetUser(id uint64) (*models.User, error)

func HasPermissions

func HasPermissions(user *models.User, permissions []models.Permission) (bool, error)

func InsertAuthor

func InsertAuthor(user *models.User,
	firstName string, lastName string) (uint64, error)

func InsertBook

func InsertBook(user *models.User, title string, description string) (uint64, error)

func InsertImage

func InsertImage(image []byte, extension string) (uint64, error)

func InsertUser

func InsertUser(username, email, password string, userGroup uint64) error

func InsertValidateBook

func InsertValidateBook(user *models.User,
	title string, description string) (uint64, error)

func InsertWrittenBy

func InsertWrittenBy(user *models.User,
	authorId, bookId uint64) (uint64, error)

func MergeAuthorInto

func MergeAuthorInto(from uint64, into uint64) error

func MergeBookInto

func MergeBookInto(from uint64, into uint64) error

func RemovePermissions

func RemovePermissions(userId uint64, permission models.Permission) error

func SelectAuthors

func SelectAuthors(pageIndex uint64) ([]models.Author, error)

func SelectBooks

func SelectBooks(pageIndex uint64) ([]models.Book, error)

func SelectUsers

func SelectUsers(pageIndex uint64) ([]models.User, error)

func UpdateProfilePic

func UpdateProfilePic(user *models.User, imageId uint64) error

func UpdateUser

func UpdateUser(user *models.User, username, email string) error

func UpdateUserGroup

func UpdateUserGroup(id uint64, userGroup uint64) error

func UpdateUserPassword

func UpdateUserPassword(user *models.User, oldPass, newPass string) error

func ValidateAuthor

func ValidateAuthor(user *models.User, authorId uint64) error

func ValidateBook

func ValidateBook(user *models.User, bookId uint64) error

func ValidateWrittenBy

func ValidateWrittenBy(user *models.User, authorId, bookId uint64) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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