database

package
v0.0.0-...-83f8c3e Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestConnection

func TestConnection(host, username, password string) error

TestConnection attempts to connect to a MySQL server using the provided credentials

Types

type Manager

type Manager struct {
	DB             *sql.DB
	Tx             *sql.Tx
	Logger         *log.Logger
	PasswordPolicy auth.PasswordPolicy
	AuthPlugin     string // Optional override for authentication plugin
	Host           string // Add Host field for connection details
	Username       string // Add Username field for connection details
	Password       string // Add Password field for connection details
}

Manager handles database operations

func NewManager

func NewManager(db *sql.DB, host, username, password string) *Manager

NewManager creates a new database manager

func (*Manager) BeginTx

func (dm *Manager) BeginTx(ctx context.Context) error

BeginTx starts a transaction

func (*Manager) CheckUserExists

func (dm *Manager) CheckUserExists(username string) (bool, string, error)

CheckUserExists checks if a MySQL user exists and returns their host

func (*Manager) CommitTx

func (dm *Manager) CommitTx() error

CommitTx commits the current transaction

func (*Manager) CreateRole

func (dm *Manager) CreateRole(role string) error

CreateRole creates a new MySQL role

func (*Manager) CreateUser

func (dm *Manager) CreateUser(username, password string) (string, error)

CreateUser creates a new MySQL user

func (*Manager) GetMySQLVersion

func (dm *Manager) GetMySQLVersion() (int, error)

GetMySQLVersion returns MySQL version (57 for 5.7, 80 for 8.0+)

func (*Manager) GetUserHost

func (dm *Manager) GetUserHost(username string) (string, error)

GetUserHost returns the host for a given user

func (*Manager) GrantPrivileges

func (dm *Manager) GrantPrivileges(role, dbName, grants string) error

GrantPrivileges grants privileges to a role

func (*Manager) GrantPrivilegesToUser

func (dm *Manager) GrantPrivilegesToUser(username, dbName, grants string) error

GrantPrivilegesToUser grants privileges to a user

func (*Manager) GrantRoles

func (dm *Manager) GrantRoles(username, role string, isGCP bool) error

GrantRoles grants roles to a user

func (*Manager) RollbackTx

func (dm *Manager) RollbackTx() error

RollbackTx rolls back the current transaction

func (*Manager) SetDefaultRole

func (dm *Manager) SetDefaultRole(username, role string) error

SetDefaultRole sets the default role for a user

func (*Manager) ShowRoleGrants

func (dm *Manager) ShowRoleGrants(role string) error

ShowRoleGrants displays grants for a role

func (*Manager) ShowUserGrants

func (dm *Manager) ShowUserGrants(username string) error

ShowUserGrants displays grants for a user

type SQLFileExecutor

type SQLFileExecutor struct {
	Host     string
	User     string
	Password string
	Logger   *log.Logger
}

SQLFileExecutor handles creating and executing SQL files to avoid shell escaping issues

func NewSQLFileExecutor

func NewSQLFileExecutor(host, user, password string, logger *log.Logger) *SQLFileExecutor

NewSQLFileExecutor creates a new executor

func (*SQLFileExecutor) ExecuteUserCreation

func (e *SQLFileExecutor) ExecuteUserCreation(username, password, authPlugin string, roles []string, dbName, grants string) error

ExecuteUserCreation creates a SQL file with the user creation commands and executes it

Jump to

Keyboard shortcuts

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