mysqldb

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAssets     = "user_assets"
	ProductAssets  = "product_assets"
	ProductDetails = "product_details"
	UserSettings   = "user_settings"
)
View Source
const (
	ByEmail = "email"
	ByID    = "id"
)

Defines the possible user query key names

Variables

View Source
var AddAssetQuery = "INSERT INTO ? (id, data) VALUES (UUID_TO_BIN(?), ?)"
View Source
var AddProductQuery = "INSERT INTO products (id, name, public, product_details_id, product_assets_id) VALUES (UUID_TO_BIN(?), ?, ?, ?, ?)"
View Source
var AddProductUsersQuery = "INSERT INTO users_products (users_id, products_id, privilege) VALUES (UUID_TO_BIN(?), UUID_TO_BIN(?), ?)"
View Source
var DBConnection = ""
View Source
var DeleteAssetQuery = "DELETE FROM ? WHERE id=UUID_TO_BIN(?)"
View Source
var DeleteProductQuery = "DELETE FROM products where id = UUID_TO_BIN(?)"
View Source
var DeleteProductUsersByProductIDQuery = "DELETE FROM users_products where products_id = UUID_TO_BIN(?)"
View Source
var DeleteUserQuery = "DELETE FROM users WHERE id=UUID_TO_BIN(?)"
View Source
var ErrAssetMissing = "This %s is missing"
View Source
var ErrDuplicateProductNameEntry = errors.New("Product with this name already exists")
View Source
var ErrDuplicateUserNameEntry = errors.New("User with this name already exists")
View Source
var ErrNoProductDeleted = errors.New("No product was deleted")
View Source
var ErrNoProductsForUser = errors.New("This user has no products")
View Source
var ErrNoUserDeleted = errors.New("No user was deleted")
View Source
var ErrNoUserWithEmail = errors.New("There is no user associated with this email")
View Source
var ErrNoUserWithProduct = errors.New("No user is associated to this product")
View Source
var ErrNoUsersProductUpdate = errors.New("No users product was updated")
View Source
var ErrSQLDuplicateEmailEntryString = "Duplicate entry '%s' for key 'users.email'"
View Source
var ErrSQLDuplicateProductNameEntryString = "Duplicate entry '%s' for key 'products.name'"
View Source
var ErrSQLDuplicateUserNameEntryString = "Duplicate entry '%s' for key 'users.name'"
View Source
var GetPrivilegesQuery = "SELECT id, name, description from privileges"
View Source
var GetProductByIDQuery = "SELECT BIN_TO_UUID(id), name, public, details, BIN_TO_UUID(product_assets_id) FROM products WHERE id = UUID_TO_BIN(?)"
View Source
var GetProductByNameQuery = "SELECT BIN_TO_UUID(id), name, public, details, BIN_TO_UUID(product_assests_id) FROM products WHERE name = ?"
View Source
var GetUserByEmailQuery = "" /* 132-byte string literal not displayed */
View Source
var GetUserByIDQuery = "" /* 142-byte string literal not displayed */
View Source
var GetUserProductIDsQuery = "SELECT BIN_TO_UUID(products_id), privilege FROM users_products where users_id = UUID_TO_BIN(?)"
View Source
var InsertUserQuery = "" /* 144-byte string literal not displayed */
View Source
var MigrationDirectory = ""
View Source
var UpdateUsersProductsQuery = "UPDATE users_products set privilege = ? where users_id = UUID_TO_BIN(?) AND products_id = UUID_TO_BIN(?)"

Functions

func AddProject added in v0.0.3

func AddProject(project models.Project) error

AddProject adds a new project to the database.

func ConvertToJSONRaw added in v0.0.3

func ConvertToJSONRaw(references interface{}) (*json.RawMessage, error)

func EmailExists

func EmailExists(email string) (bool, error)

func GetAsset added in v0.0.3

func GetAsset(assetType string, assetID *uuid.UUID) (*models.Asset, error)

func GetProjectByName added in v0.0.3

func GetProjectByName(name string) (*models.Project, error)

GetProjectByName returns the project by name.

func IsPasswordCorrect added in v0.0.3

func IsPasswordCorrect(password string, user *models.User) bool

CheckPassword compares the password entered by the user with the stored password.

func RollbackWithErrorStack added in v0.0.6

func RollbackWithErrorStack(tx *sql.Tx, errorStack error) error

func UpdateAsset added in v0.0.3

func UpdateAsset(assetType string, asset *models.Asset) error

func UpdateProject added in v0.0.3

func UpdateProject(project models.Project) error

UpdateProject updates the selected project.

func UserExists

func UserExists(username string) (bool, error)

Types

type DBConnectorCommon added in v0.0.7

type DBConnectorCommon interface {
	BootstrapSystem() error
	ConnectSystem() (*sql.Tx, error)
	Commit(tx *sql.Tx) error
}

Common interface for DB connection. Needed in order to allow mock and custom DB interface implementation.

var DBConnector DBConnectorCommon

type DBConnectorMock added in v0.0.7

type DBConnectorMock struct {
	Mock sqlmock.Sqlmock
	DB   *sql.DB
}

func (*DBConnectorMock) BootstrapSystem added in v0.0.7

func (*DBConnectorMock) BootstrapSystem() error

func (*DBConnectorMock) Commit added in v0.0.7

func (*DBConnectorMock) Commit(tx *sql.Tx) error

func (*DBConnectorMock) ConnectSystem added in v0.0.7

func (i *DBConnectorMock) ConnectSystem() (*sql.Tx, error)

type FunctionCommonInterface added in v0.0.7

type FunctionCommonInterface interface {
	GetUser(queryString string, keyValue interface{}, tx *sql.Tx) (*models.User, error)
	AddUser(user *models.User, tx *sql.Tx) error
	DeleteUser(userID *uuid.UUID, tx *sql.Tx) error

	AddAsset(assetType string, asset *models.Asset, tx *sql.Tx) error
	DeleteAsset(assetType string, assetID *uuid.UUID, tx *sql.Tx) error

	GetProductsByUserID(userID uuid.UUID) ([]models.Product, error)
	UpdateUsersProducts(userID *uuid.UUID, productID *uuid.UUID, privilege int, tx *sql.Tx) error
	AddProductUsers(productID *uuid.UUID, productUsers models.ProductUsers, tx *sql.Tx) error
	DeleteProductUsersByProductID(productID *uuid.UUID, tx *sql.Tx) error
	GetUserProductIDs(userID uuid.UUID, tx *sql.Tx) (*models.UserProducts, error)

	GetProductByID(ID uuid.UUID, tx *sql.Tx) (*models.Product, error)
	GetProductByName(name string, tx *sql.Tx) (*models.Product, error)
	AddProduct(product *models.Product, tx *sql.Tx) error
	DeleteProduct(productID *uuid.UUID, tx *sql.Tx) error

	GetPrivileges() (models.Privileges, error)
}

Data handling common function interface. Needed in order to allow mock and custom functionality implementations.

var Functions FunctionCommonInterface

type MYSQLConnector added in v0.0.7

type MYSQLConnector struct {
}

MYSQL Interface implementation

func (*MYSQLConnector) BootstrapSystem added in v0.0.7

func (*MYSQLConnector) BootstrapSystem() error

func (*MYSQLConnector) Commit added in v0.0.7

func (*MYSQLConnector) Commit(tx *sql.Tx) error

func (*MYSQLConnector) ConnectSystem added in v0.0.7

func (*MYSQLConnector) ConnectSystem() (*sql.Tx, error)

type MYSQLFunctions added in v0.0.7

type MYSQLFunctions struct {
}

MYSQL Interface implementation

func (*MYSQLFunctions) AddAsset added in v0.0.7

func (*MYSQLFunctions) AddAsset(assetType string, asset *models.Asset, tx *sql.Tx) error

func (*MYSQLFunctions) AddProduct added in v0.0.7

func (*MYSQLFunctions) AddProduct(product *models.Product, tx *sql.Tx) error

func (MYSQLFunctions) AddProductUsers added in v0.0.7

func (MYSQLFunctions) AddProductUsers(productID *uuid.UUID, productUsers models.ProductUsers, tx *sql.Tx) error

func (*MYSQLFunctions) AddUser added in v0.0.7

func (*MYSQLFunctions) AddUser(user *models.User, tx *sql.Tx) error

AddUser creates a new user entry in the DB. Whitespaces in the email are automatically deleted Email/Name are unique in DB. Duplicates will return error.

func (*MYSQLFunctions) DeleteAsset added in v0.0.7

func (*MYSQLFunctions) DeleteAsset(assetType string, assetID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) DeleteProduct added in v0.0.7

func (*MYSQLFunctions) DeleteProduct(productID *uuid.UUID, tx *sql.Tx) error

func (MYSQLFunctions) DeleteProductUsersByProductID added in v0.0.7

func (MYSQLFunctions) DeleteProductUsersByProductID(productID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) DeleteUser added in v0.0.7

func (*MYSQLFunctions) DeleteUser(ID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) GetPrivileges added in v0.0.7

func (*MYSQLFunctions) GetPrivileges() (models.Privileges, error)

func (*MYSQLFunctions) GetProductByID added in v0.0.7

func (*MYSQLFunctions) GetProductByID(ID uuid.UUID, tx *sql.Tx) (*models.Product, error)

func (*MYSQLFunctions) GetProductByName added in v0.0.7

func (*MYSQLFunctions) GetProductByName(name string, tx *sql.Tx) (*models.Product, error)

func (*MYSQLFunctions) GetProductsByUserID added in v0.0.7

func (*MYSQLFunctions) GetProductsByUserID(userID uuid.UUID) ([]models.Product, error)

GetProductsByUserID returns all products belonging to the selected user. The function first gets all rows matching with the user DI from users_products table, then gets all products based on the product ids from the first query result.

func (*MYSQLFunctions) GetUser added in v0.0.7

func (*MYSQLFunctions) GetUser(queryString string, keyValue interface{}, tx *sql.Tx) (*models.User, error)

GetUser returns the user defined by the key name and key value. Key name can be either id or email.

func (*MYSQLFunctions) GetUserProductIDs added in v0.0.7

func (*MYSQLFunctions) GetUserProductIDs(userID uuid.UUID, tx *sql.Tx) (*models.UserProducts, error)

func (MYSQLFunctions) UpdateUsersProducts added in v0.0.7

func (MYSQLFunctions) UpdateUsersProducts(userID *uuid.UUID, productID *uuid.UUID, privilege int, tx *sql.Tx) error

Jump to

Keyboard shortcuts

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