Documentation ¶
Index ¶
- func Migrate(db *sql.DB, source string) error
- func NewDB(host, port, username, password, dbName, migrationSource, dataDir string) (db.DB, error)
- func NewDBWithConnection(conn *sqlx.DB, dataDir string) db.DB
- type DB
- func (d *DB) AddPartStock(id, price, comment string, amount uint) error
- func (d *DB) Close()
- func (d *DB) CreateLink(link models.Link) (*models.Link, error)
- func (d *DB) CreateLoginToken(token models.LoginToken) error
- func (d *DB) CreatePartAttachmentEntry(partID, filename, mimeType string) (*models.PartAttachment, error)
- func (d *DB) CreateUser(user models.User) error
- func (d *DB) DeleteLinkByID(linkID string) error
- func (d *DB) DeleteLoginToken(id string) error
- func (d *DB) DeleteUser(name string) error
- func (d *DB) GetAttachmentEntry(id string) (*models.PartAttachment, error)
- func (d *DB) GetAttachmentsByPartLink(partLink string) ([]models.PartAttachment, error)
- func (d *DB) GetLinkByID(id string) (*models.Link, error)
- func (d *DB) GetLinksByLinkID(id string) ([]*models.Link, error)
- func (d *DB) GetNonExpiredLoginTokenByID(id string) (*models.LoginToken, error)
- func (d *DB) GetPartByLink(id string) (*models.Part, error)
- func (d *DB) GetStorageLocationByLink(id string) (*models.StorageLocation, error)
- func (d *DB) GetUserByName(name string) (*models.User, error)
- func (d *DB) GetUserList() ([]string, error)
- func (d *DB) ListLoginTokensForUser(username string, expired bool) ([]models.LoginToken, error)
- func (d *DB) MovePart(partID int, newLocationID int) error
- func (d *DB) RemovePartStock(id, comment string, amount uint) error
- func (d *DB) SearchParts(search models.Search) ([]models.Part, error)
- func (d *DB) SearchStorageLocations(search models.Search) ([]models.StorageLocation, error)
- func (d *DB) SetUserPermissions(u models.User) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDB ¶
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 ¶
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 ¶
AddPartStock adds one or more instances to the amount of parts present of the selected part type
func (*DB) CreateLink ¶
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 ¶
CreateUser creates a new user in the database
func (*DB) DeleteLinkByID ¶
DeleteLinkByID will delete the link with the given ID
func (*DB) DeleteLoginToken ¶
func (*DB) DeleteUser ¶
DeleteUser deletes the user with the given name from the database
func (*DB) GetAttachmentEntry ¶
func (d *DB) GetAttachmentEntry(id string) (*models.PartAttachment, error)
func (*DB) GetAttachmentsByPartLink ¶
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 ¶
GetLinkByID returns the link with the given ID Mainly this is used internally to fetch the DB ID of entities
func (*DB) GetLinksByLinkID ¶
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 (*DB) GetPartByLink ¶
GetPartByLink returns the part belonging to the link given
func (*DB) GetStorageLocationByLink ¶
func (d *DB) GetStorageLocationByLink(id string) (*models.StorageLocation, error)
GetStorageLocationByLink returns the storage location that belongs to the given ID
func (*DB) GetUserByName ¶
GetUserByName returns the user with the given username or nothing if the user does not exist
func (*DB) GetUserList ¶
GetUserList returns a list of all existing users
func (*DB) ListLoginTokensForUser ¶
List all existing login tokens for a given user - optionally returning the expired ones as well
func (*DB) MovePart ¶
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 ¶
RemovePartStock removes one or more parts of the selected part type from the inventory
func (*DB) SearchParts ¶
SearchParts searches for the parts matching the given search query and returns a list of them ordered by name
func (*DB) SearchStorageLocations ¶
SearchStorageLocations searches for storage locations matching the provided search term. The result is provided as paginated list