mysqldb

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 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"
	ProjectDetails = "project_details"
	ProjectAssets  = "project_assets"
)
View Source
const (
	ByEmail = iota
	ByID
)

Defines the possible user query key names

Variables

View Source
var AddAssetQuery = "INSERT INTO %s (id, data) VALUES (UUID_TO_BIN(?), ?)"
View Source
var AddProductQuery = "" /* 129-byte string literal not displayed */
View Source
var AddProductUsersQuery = "INSERT INTO users_products (users_id, products_id, privileges_id) VALUES (UUID_TO_BIN(?), UUID_TO_BIN(?), ?)"
View Source
var AddProjectQuery = "" /* 149-byte string literal not displayed */
View Source
var AddProjectUsersQuery = "INSERT INTO users_projects (users_id, projects_id, privileges_id) VALUES (UUID_TO_BIN(?), UUID_TO_BIN(?), ?)"
View Source
var AddProjectViewerQuery = "INSERT INTO users_viewers (users_id, viewer_id, projects_id) VALUES (UUID_TO_BIN(?), UUID_TO_BIN(?), UUID_TO_BIN(?))"
View Source
var AddUsersViewersQuery = "" /* 129-byte string literal not displayed */
View Source
var AddViewerQuery = "INSERT INTO viewers (id, owner_id) VALUES (UUID_TO_BIN(?), UUID_TO_BIN(?))"
View Source
var DeleteAssetQuery = "DELETE FROM %s WHERE id=UUID_TO_BIN(?)"
View Source
var DeleteProductQuery = "DELETE FROM products where id = UUID_TO_BIN(?)"
View Source
var DeleteProductUserQuery = "DELETE FROM users_products where products_id = UUID_TO_BIN(?) AND users_id = UUID_TO_BIN(?)"
View Source
var DeleteProductUsersByProductIDQuery = "DELETE FROM users_products where products_id = UUID_TO_BIN(?)"
View Source
var DeleteProjectQuery = "DELETE FROM projects where id = UUID_TO_BIN(?)"
View Source
var DeleteProjectUsersByProjectIDQuery = "DELETE FROM users_projects where projects_id = UUID_TO_BIN(?)"
View Source
var DeleteProjectViewerByProjectIDQuery = "DELETE FROM users_viewers where projects_id = UUID_TO_BIN(?)"
View Source
var DeleteProjectViewerByUserIDQuery = "DELETE FROM users_viewers where users_id = UUID_TO_BIN(?)"
View Source
var DeleteProjectViewerByViewerIDQuery = "DELETE FROM users_viewers where viewer_id = UUID_TO_BIN(?)"
View Source
var DeleteProjectsByProductIDQuery = "DELETE FROM projects where products_id = UUID_TO_BIN(?)"
View Source
var DeleteUserQuery = "DELETE FROM users WHERE id=UUID_TO_BIN(?)"
View Source
var DeleteViewerByOwnerQuery = "DELETE FROM viewers where owner_id = UUID_TO_BIN(?)"
View Source
var DeleteViewerIDsByUserIDQuery = "DELETE FROM users_viewers where users_id = UUID_TO_BIN(?)"
View Source
var ErrAssetMissing = "This %s is missing or old value is the same as new"
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 ErrNoProductUserAdded = errors.New("No product user relation has been added")
View Source
var ErrNoProjectDeleted = errors.New("No project was deleted")
View Source
var ErrNoProjectUserAdded = errors.New("No project user relation has been added")
View Source
var ErrNoProjectViewerDeleted = errors.New("No project viewer was deleted")
View Source
var ErrNoUserDeleted = errors.New("No user was deleted")
View Source
var ErrNoUserViewerAdded = errors.New("No data views have been added for this user")
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 ErrNoUserWithProject = errors.New("No user is associated to this project")
View Source
var ErrNoUsersProductUpdate = errors.New("No users product was updated")
View Source
var ErrNoUsersProjectUpdate = errors.New("No users project was updated")
View Source
var ErrNoViewForThisUser = errors.New("No data views associated with this user")
View Source
var ErrNoViewerDeleted = errors.New("No viewer was deleted")
View Source
var ErrSQLDuplicateEmailEntryString = "Error 1062: Duplicate entry '%s' for key 'users.email'"
View Source
var ErrSQLDuplicateProductNameEntryString = "Duplicate entry '%s' for key 'products.name'"
View Source
var ErrSQLDuplicateUserNameEntryString = "Error 1062: Duplicate entry '%s' for key 'users.name'"
View Source
var GetAssetQuery = "SELECT BIN_TO_UUID(id), data FROM %s WHERE id = UUID_TO_BIN(?)"
View Source
var GetAssetsQuery = "SELECT BIN_TO_UUID(id), data FROM %s WHERE id IN (UUID_TO_BIN(?)"
View Source
var GetPrivilegeQuery = "SELECT id, name, description from privileges where name = ?"
View Source
var GetPrivilegesQuery = "SELECT id, name, description from privileges"
View Source
var GetProductByIDQuery = "" /* 133-byte string literal not displayed */
View Source
var GetProductByNameQuery = "SELECT BIN_TO_UUID(id), name, BIN_TO_UUID(product_details_id), BIN_TO_UUID(product_assets_id) FROM products WHERE name = ?"
View Source
var GetProductProjectsQuery = "" /* 162-byte string literal not displayed */
View Source
var GetProductUserIDsQuery = "SELECT BIN_TO_UUID(users_id), privileges_id FROM users_products where products_id = UUID_TO_BIN(?)"
View Source
var GetProductsByIDsQuery = "" /* 135-byte string literal not displayed */
View Source
var GetProjectByIDQuery = "" /* 153-byte string literal not displayed */
View Source
var GetProjectViewerByUserIDQuery = "" /* 129-byte string literal not displayed */
View Source
var GetProjectViewerByViewerIDQuery = "" /* 130-byte string literal not displayed */
View Source
var GetProjectsByIDsQuery = "" /* 155-byte string literal not displayed */
View Source
var GetUserByEmailQuery = "" /* 132-byte string literal not displayed */
View Source
var GetUserByIDQuery = "" /* 142-byte string literal not displayed */
View Source
var GetUserIDsByViewerIDQuery = "SELECT BIN_TO_UUID(users_id), is_owner from users_viewers where viewer_id = UUID_TO_BIN(?)"
View Source
var GetUserProductIDsQuery = "SELECT BIN_TO_UUID(products_id), privileges_id FROM users_products where users_id = UUID_TO_BIN(?)"
View Source
var GetUserProjectIDsQuery = "SELECT BIN_TO_UUID(projects_id), privileges_id FROM users_projects where users_id = UUID_TO_BIN(?)"
View Source
var GetUsersByIDsQuery = "" /* 144-byte string literal not displayed */
View Source
var GetViewerIDsByUserIDQuery = "SELECT BIN_TO_UUID(viewer_id), is_owner, BIN_TO_UUID(projects_id) from users_viewers where users_id = UUID_TO_BIN(?)"
View Source
var InsertUserQuery = "" /* 144-byte string literal not displayed */
View Source
var UpdateAssetQuery = "UPDATE %s set data = ? where id = UUID_TO_BIN(?)"
View Source
var UpdateUsersProductsQuery = "UPDATE users_products set privileges_id = ? where users_id = UUID_TO_BIN(?) AND products_id = UUID_TO_BIN(?)"
View Source
var UpdateUsersProjectsQuery = "UPDATE users_projects set privileges_id = ? where users_id = UUID_TO_BIN(?) AND projects_id = UUID_TO_BIN(?)"

Functions

func AddUsersViewers added in v0.0.9

func AddUsersViewers(userID *uuid.UUID, userViewers models.ViewersList, tx *sql.Tx) error

func ConvertToJSONRaw added in v0.0.3

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

func DeleteViewerIDsByUserID added in v0.0.9

func DeleteViewerIDsByUserID(userID *uuid.UUID, tx *sql.Tx) error

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

Types

type ConnectorCommon added in v0.0.10

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

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

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)

func (DBConnectorMock) Rollback added in v0.0.9

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

type FunctionsCommon added in v0.0.10

type FunctionsCommon interface {
	GetUser(queryType int, keyValue interface{}, tx *sql.Tx) (*models.User, error)
	AddUser(user *models.User, tx *sql.Tx) error
	DeleteUser(userID *uuid.UUID, tx *sql.Tx) error
	GetProductUserIDs(productID *uuid.UUID, tx *sql.Tx) (*models.ProductUserIDs, error)
	GetUsersByIDs(IDs []uuid.UUID, tx *sql.Tx) ([]models.User, error)

	AddAsset(assetType string, asset *models.Asset, tx *sql.Tx) error
	DeleteAsset(assetType string, assetID *uuid.UUID, tx *sql.Tx) error
	GetAssets(assetType string, IDs []uuid.UUID, tx *sql.Tx) ([]models.Asset, error)
	GetAsset(assetType string, assetID *uuid.UUID) (*models.Asset, error)
	UpdateAsset(assetType string, asset *models.Asset) error

	UpdateUsersProducts(userID *uuid.UUID, productID *uuid.UUID, privilege int, tx *sql.Tx) error
	AddProductUsers(productID *uuid.UUID, productUsers *models.ProductUserIDs, tx *sql.Tx) error
	DeleteProductUsersByProductID(productID *uuid.UUID, tx *sql.Tx) error
	DeleteProductUser(productID *uuid.UUID, userID *uuid.UUID, tx *sql.Tx) error
	GetUserProductIDs(userID *uuid.UUID, tx *sql.Tx) (*models.UserProductIDs, 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
	GetProductsByIDs(IDs []uuid.UUID, tx *sql.Tx) ([]models.Product, error)

	AddProject(project *models.Project, tx *sql.Tx) error
	AddProjectUsers(projectID *uuid.UUID, projectUsers *models.ProjectUserIDs, tx *sql.Tx) error
	GetProjectByID(ID *uuid.UUID, tx *sql.Tx) (*models.Project, error)
	DeleteProjectUsersByProjectID(projectID *uuid.UUID, tx *sql.Tx) error
	DeleteProject(projectID *uuid.UUID, tx *sql.Tx) error
	DeleteProjectsByProductID(productID *uuid.UUID, tx *sql.Tx) error
	GetProjectsByIDs(IDs []uuid.UUID, tx *sql.Tx) ([]models.Project, error)
	GetProductProjects(productID *uuid.UUID, tx *sql.Tx) ([]models.Project, error)

	GetUserProjectIDs(userID *uuid.UUID, tx *sql.Tx) (*models.UserProjectIDs, error)
	UpdateUsersProjects(userID *uuid.UUID, projectID *uuid.UUID, privilege int, tx *sql.Tx) error
	AddProjectViewer(projectViewer *models.ProjectViewer, tx *sql.Tx) error
	DeleteProjectViewerByUserID(userID *uuid.UUID, tx *sql.Tx) error
	GetProjectViewersByUserID(userID *uuid.UUID, tx *sql.Tx) ([]models.ProjectViewer, error)
	GetProjectViewersByViewerID(viewerID *uuid.UUID, tx *sql.Tx) ([]models.ProjectViewer, error)
	DeleteProjectViewerByViewerID(viewerID *uuid.UUID, tx *sql.Tx) error
	DeleteProjectViewerByProjectID(projectID *uuid.UUID, tx *sql.Tx) error

	DeleteViewerByOwnerID(userID *uuid.UUID, tx *sql.Tx) error

	GetPrivileges() (models.Privileges, error)
	GetPrivilege(name string) (*models.Privilege, error)
}

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

type MYSQLConnector added in v0.0.7

type MYSQLConnector struct {
	DBConnection       string
	MigrationDirectory string
}

MYSQL database connector implementation

func (*MYSQLConnector) BootstrapSystem added in v0.0.7

func (c *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 (c *MYSQLConnector) ConnectSystem() (*sql.Tx, error)

func (*MYSQLConnector) Rollback added in v0.0.9

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

type MYSQLFunctions added in v0.0.7

type MYSQLFunctions struct {
	DBConnector ConnectorCommon
	UUIDImpl    models.UUIDCommon
}

MYSQLFunctions represents the implementation of MYSQL data manipulation functions.

var DBFunctions *MYSQLFunctions

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.ProductUserIDs, tx *sql.Tx) error

func (*MYSQLFunctions) AddProject added in v0.0.9

func (*MYSQLFunctions) AddProject(project *models.Project, tx *sql.Tx) error

func (*MYSQLFunctions) AddProjectUsers added in v0.0.9

func (*MYSQLFunctions) AddProjectUsers(projectID *uuid.UUID, projectUsers *models.ProjectUserIDs, tx *sql.Tx) error

func (*MYSQLFunctions) AddProjectViewer added in v0.0.21

func (*MYSQLFunctions) AddProjectViewer(projectViewer *models.ProjectViewer, 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) DeleteProductUser added in v0.0.9

func (MYSQLFunctions) DeleteProductUser(productID *uuid.UUID, userID *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) DeleteProject added in v0.0.9

func (*MYSQLFunctions) DeleteProject(projectID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) DeleteProjectUsersByProjectID added in v0.0.9

func (*MYSQLFunctions) DeleteProjectUsersByProjectID(projectID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) DeleteProjectViewerByProjectID added in v0.0.21

func (*MYSQLFunctions) DeleteProjectViewerByProjectID(projectID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) DeleteProjectViewerByUserID added in v0.0.21

func (f *MYSQLFunctions) DeleteProjectViewerByUserID(userID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) DeleteProjectViewerByViewerID added in v0.0.21

func (*MYSQLFunctions) DeleteProjectViewerByViewerID(viewerID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) DeleteProjectsByProductID added in v0.0.9

func (*MYSQLFunctions) DeleteProjectsByProductID(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) DeleteViewerByOwnerID added in v0.0.21

func (*MYSQLFunctions) DeleteViewerByOwnerID(userID *uuid.UUID, tx *sql.Tx) error

func (*MYSQLFunctions) EmailExists added in v0.0.10

func (f *MYSQLFunctions) EmailExists(email string) (bool, error)

func (*MYSQLFunctions) GetAsset added in v0.0.10

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

func (*MYSQLFunctions) GetAssets added in v0.0.9

func (*MYSQLFunctions) GetAssets(assetType string, IDs []uuid.UUID, tx *sql.Tx) ([]models.Asset, error)

func (*MYSQLFunctions) GetPrivilege added in v0.0.9

func (f *MYSQLFunctions) GetPrivilege(name string) (*models.Privilege, error)

func (*MYSQLFunctions) GetPrivileges added in v0.0.7

func (f *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) GetProductProjects added in v0.0.12

func (*MYSQLFunctions) GetProductProjects(productID *uuid.UUID, tx *sql.Tx) ([]models.Project, error)

func (MYSQLFunctions) GetProductUserIDs added in v0.0.9

func (MYSQLFunctions) GetProductUserIDs(productID *uuid.UUID, tx *sql.Tx) (*models.ProductUserIDs, error)

func (*MYSQLFunctions) GetProductsByIDs added in v0.0.9

func (*MYSQLFunctions) GetProductsByIDs(IDs []uuid.UUID, tx *sql.Tx) ([]models.Product, error)

func (*MYSQLFunctions) GetProjectByID added in v0.0.9

func (*MYSQLFunctions) GetProjectByID(ID *uuid.UUID, tx *sql.Tx) (*models.Project, error)

func (*MYSQLFunctions) GetProjectViewersByUserID added in v0.0.21

func (*MYSQLFunctions) GetProjectViewersByUserID(userID *uuid.UUID, tx *sql.Tx) ([]models.ProjectViewer, error)

func (*MYSQLFunctions) GetProjectViewersByViewerID added in v0.0.21

func (*MYSQLFunctions) GetProjectViewersByViewerID(viewerID *uuid.UUID, tx *sql.Tx) ([]models.ProjectViewer, error)

func (*MYSQLFunctions) GetProjectsByIDs added in v0.0.9

func (*MYSQLFunctions) GetProjectsByIDs(IDs []uuid.UUID, tx *sql.Tx) ([]models.Project, error)

func (*MYSQLFunctions) GetUser added in v0.0.7

func (*MYSQLFunctions) GetUser(queryType int, 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) GetUserIDsByViewerID added in v0.0.10

func (f *MYSQLFunctions) GetUserIDsByViewerID(viewerID *uuid.UUID) (*models.ViewUsers, error)

func (*MYSQLFunctions) GetUserProductIDs added in v0.0.7

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

func (*MYSQLFunctions) GetUserProjectIDs added in v0.0.9

func (*MYSQLFunctions) GetUserProjectIDs(userID *uuid.UUID, tx *sql.Tx) (*models.UserProjectIDs, error)

func (MYSQLFunctions) GetUsersByIDs added in v0.0.9

func (MYSQLFunctions) GetUsersByIDs(IDs []uuid.UUID, tx *sql.Tx) ([]models.User, error)

func (*MYSQLFunctions) GetViewerIDsByUserID added in v0.0.10

func (f *MYSQLFunctions) GetViewerIDsByUserID(userID *uuid.UUID) (models.ViewersList, error)

func (*MYSQLFunctions) UpdateAsset added in v0.0.10

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

func (*MYSQLFunctions) UpdateUsersProducts added in v0.0.7

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

func (*MYSQLFunctions) UpdateUsersProjects added in v0.0.9

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

func (*MYSQLFunctions) UserExists added in v0.0.10

func (f *MYSQLFunctions) UserExists(username string) (bool, error)

Jump to

Keyboard shortcuts

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