mysql

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(db *sql.DB, source string) error

Migrate is a helper function to migrate the database up to its most recent version

func NewDB

func NewDB(host, port, username, password, dbName, migrationSource, dataDir string) (db.DB, error)

NewDB creates a new DB instance by using the given connection parameters It will also migrate the database to the most recent version

func NewDBWithConnection

func NewDBWithConnection(conn *sqlx.DB, dataDir string) db.DB

NewDBWithConnection creates a new DB instance using an existing SQLX DB connection

The data dir parameter is used to get the files corresponding to attachments from the file system

ATTENTION: This func will NOT perform a database migration!

Types

type DB

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

func (*DB) AddPartStock

func (d *DB) AddPartStock(id, price, comment string, amount uint) error

AddPartStock adds one or more instances to the amount of parts present of the selected part type

func (*DB) Close

func (d *DB) Close()

Close closes the database connection

func (d *DB) CreateLink(link models.Link) (*models.Link, error)

CreateLink creates the link to the given target Passing a link with an empty ID will generate a new ID

func (*DB) CreateLoginToken

func (d *DB) CreateLoginToken(token models.LoginToken) error

CreateLoginToken creates a new login token for a user

func (*DB) CreatePartAttachmentEntry

func (d *DB) CreatePartAttachmentEntry(partID, filename, mimeType string) (*models.PartAttachment, error)

func (*DB) CreateUser

func (d *DB) CreateUser(user models.User) error

CreateUser creates a new user in the database

func (*DB) DeleteLinkByID

func (d *DB) DeleteLinkByID(linkID string) error

DeleteLinkByID will delete the link with the given ID

func (*DB) DeleteLoginToken

func (d *DB) DeleteLoginToken(id string) error

func (*DB) DeleteUser

func (d *DB) DeleteUser(name string) error

DeleteUser deletes the user with the given name from the database

func (*DB) GetAttachmentEntry

func (d *DB) GetAttachmentEntry(id string) (*models.PartAttachment, error)
func (d *DB) GetAttachmentsByPartLink(partLink string) ([]models.PartAttachment, error)

GetAttachmentsByPartLink returns a list of attachments belonging to the part identified with the given link

func (*DB) GetLinkByID

func (d *DB) GetLinkByID(id string) (*models.Link, error)

GetLinkByID returns the link with the given ID Mainly this is used internally to fetch the DB ID of entities

func (*DB) GetLinksByLinkID

func (d *DB) GetLinksByLinkID(id string) ([]*models.Link, error)

GetLinksByLinkID returns a list of links that have the same target as the given link, denoting all links a specific item has in the database

func (*DB) GetNonExpiredLoginTokenByID

func (d *DB) GetNonExpiredLoginTokenByID(id string) (*models.LoginToken, error)

GetNonExpiredLoginTokenByID returns the given login token model if it exists and is not expired yet

func (d *DB) GetPartByLink(id string) (*models.Part, error)

GetPartByLink returns the part belonging to the link given

func (d *DB) GetStorageLocationByLink(id string) (*models.StorageLocation, error)

GetStorageLocationByLink returns the storage location that belongs to the given ID

func (*DB) GetUserByName

func (d *DB) GetUserByName(name string) (*models.User, error)

GetUserByName returns the user with the given username or nothing if the user does not exist

func (*DB) GetUserList

func (d *DB) GetUserList() ([]string, error)

GetUserList returns a list of all existing users

func (*DB) ListLoginTokensForUser

func (d *DB) ListLoginTokensForUser(username string, expired bool) ([]models.LoginToken, error)

List all existing login tokens for a given user - optionally returning the expired ones as well

func (*DB) MovePart

func (d *DB) MovePart(partID int, newLocationID int) error

MovePart moves a part from its current storage location to a new one This function does not care about existence so the calling func needs to resolve the internal IDs and check if both included entities are really present

func (*DB) RemovePartStock

func (d *DB) RemovePartStock(id, comment string, amount uint) error

RemovePartStock removes one or more parts of the selected part type from the inventory

func (*DB) SearchParts

func (d *DB) SearchParts(search models.Search) ([]models.Part, error)

SearchParts searches for the parts matching the given search query and returns a list of them ordered by name

func (*DB) SearchStorageLocations

func (d *DB) SearchStorageLocations(search models.Search) ([]models.StorageLocation, error)

SearchStorageLocations searches for storage locations matching the provided search term. The result is provided as paginated list

func (*DB) SetUserPermissions

func (d *DB) SetUserPermissions(u models.User) error

SetUserPermissions sets the permissions for the selected user based on the given user struct

Jump to

Keyboard shortcuts

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