sqladapter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientScriptRepository

type ClientScriptRepository interface {
	CreateClientTableScript() string
	DropClientTableScript() string
	CreateClientScript() string
	GetClientsScript() string
	GetClientByUIDScript() string
	UpdateClientScript() string
	DeleteClientScript() string
}

ClientScriptRepository is an interface for fetching client sql scripts.

type ContextFactory

type ContextFactory struct {
	Context context.Context
	Timeout int
}

func (ContextFactory) CreateStandardTimeoutContext

func (cf ContextFactory) CreateStandardTimeoutContext() (context.Context, context.CancelFunc)

CreateStandardTimeoutContext creates a context with the configured timeout. It is a child of the configured context and can be canceled by that context's cancel function. Returns the created context and its cancel function.

type MigrationScriptRepository

type MigrationScriptRepository interface {
	CreateMigrationTableScript() string
	SaveMigrationScript() string
	GetMigrationByTimestampScript() string
	GetLatestTimestampScript() string
	DeleteMigrationByTimestampScript() string
}

MigrationScriptRepository is an interface for fetching migration sql scripts.

type SQLAdapter

type SQLAdapter struct {
	database.DatabaseAdapter

	DB             *sql.DB
	SQLDriver      SQLDriver
	ContextFactory ContextFactory

	// DbKey is the key that will be used to resolve the database's connection string.
	DbKey string
	// contains filtered or unexported fields
}

func CreateSQLAdpater

func CreateSQLAdpater(dbKey string, driver SQLDriver) *SQLAdapter

CreateSQLAdpater creates a new SQLAdapter with the provided db key and driver.

func (*SQLAdapter) CloseConnection

func (a *SQLAdapter) CloseConnection() error

CloseConnection closes the connection to the SQL database server and resets its db instance. The adapter also calls its cancel function to cancel any child requests that may still be running. Niether the adapter's db instance or context should be used after calling this function. Returns any errors.

func (*SQLAdapter) GetExecutor

func (a *SQLAdapter) GetExecutor() data.DataExecutor

func (*SQLAdapter) OpenConnection

func (a *SQLAdapter) OpenConnection() error

OpenConnection opens the connection to SQL database server using the fields from the database config. Initializes the adapter's context and cancel function, as well as its db instance. Returns any errors.

func (*SQLAdapter) Ping

func (DB *SQLAdapter) Ping() error

Ping pings the SQL database server to verify it can still be reached. Returns an error if it cannot, or if any other errors are encountered.

type SQLCRUD

type SQLCRUD struct {
	Executor       contextExecutor
	SQLDriver      SQLDriver
	ContextFactory ContextFactory
}

func (*SQLCRUD) CreateClient

func (crud *SQLCRUD) CreateClient(client *models.Client) error

func (*SQLCRUD) CreateClientTable

func (crud *SQLCRUD) CreateClientTable() error

CreateClientTable creates the client table in the database. Returns any errors.

func (*SQLCRUD) CreateMigration

func (crud *SQLCRUD) CreateMigration(timestamp string) error

func (*SQLCRUD) CreateSessionTable

func (crud *SQLCRUD) CreateSessionTable() error

CreateSessionTable creates the session table in the database. Returns any errors.

func (*SQLCRUD) CreateUser

func (crud *SQLCRUD) CreateUser(user *models.User) error

func (*SQLCRUD) CreateUserRole

func (crud *SQLCRUD) CreateUserRole(role *models.UserRole) error

func (*SQLCRUD) CreateUserRoleTable

func (crud *SQLCRUD) CreateUserRoleTable() error

CreateUserRoleTable creates the user-role table in the database. Returns any errors.

func (*SQLCRUD) CreateUserTable

func (crud *SQLCRUD) CreateUserTable() error

CreateUserTable creates the user table in the database. Returns any errors.

func (*SQLCRUD) DeleteAllOtherUserSessions

func (crud *SQLCRUD) DeleteAllOtherUserSessions(username string, token uuid.UUID) error

func (*SQLCRUD) DeleteAllUserSessions

func (crud *SQLCRUD) DeleteAllUserSessions(username string) error

func (*SQLCRUD) DeleteClient

func (crud *SQLCRUD) DeleteClient(uid uuid.UUID) (bool, error)

func (*SQLCRUD) DeleteMigrationByTimestamp

func (crud *SQLCRUD) DeleteMigrationByTimestamp(timestamp string) error

func (*SQLCRUD) DeleteSession

func (crud *SQLCRUD) DeleteSession(token uuid.UUID) (bool, error)

func (*SQLCRUD) DeleteUser

func (crud *SQLCRUD) DeleteUser(username string) (bool, error)

func (*SQLCRUD) DeleteUserRole

func (crud *SQLCRUD) DeleteUserRole(username string, clientUID uuid.UUID) (bool, error)

func (*SQLCRUD) DropClientTable

func (crud *SQLCRUD) DropClientTable() error

DropClientTable drops the client table from the database. Returns any errors.

func (*SQLCRUD) DropSessionTable

func (crud *SQLCRUD) DropSessionTable() error

DropSessionTable drops the session table from the database. Returns any errors.

func (*SQLCRUD) DropUserRoleTable

func (crud *SQLCRUD) DropUserRoleTable() error

DropUserRoleTable drops the user-role table from the database. Returns any errors.

func (*SQLCRUD) DropUserTable

func (crud *SQLCRUD) DropUserTable() error

DropUserTable drops the user table from the database. Returns any errors.

func (*SQLCRUD) GetClientByUID

func (crud *SQLCRUD) GetClientByUID(uid uuid.UUID) (*models.Client, error)

func (*SQLCRUD) GetClients

func (crud *SQLCRUD) GetClients() ([]*models.Client, error)

func (*SQLCRUD) GetLatestTimestamp

func (crud *SQLCRUD) GetLatestTimestamp() (timestamp string, hasLatest bool, err error)

func (*SQLCRUD) GetMigrationByTimestamp

func (crud *SQLCRUD) GetMigrationByTimestamp(timestamp string) (*models.Migration, error)

func (*SQLCRUD) GetSessionByToken

func (crud *SQLCRUD) GetSessionByToken(token uuid.UUID) (*models.Session, error)

func (*SQLCRUD) GetUserByUsername

func (crud *SQLCRUD) GetUserByUsername(username string) (*models.User, error)

func (*SQLCRUD) GetUserRoleByClientUIDAndUsername

func (crud *SQLCRUD) GetUserRoleByClientUIDAndUsername(clientUID uuid.UUID, username string) (*models.UserRole, error)

func (*SQLCRUD) GetUserRolesWithLesserRankByClientUID

func (crud *SQLCRUD) GetUserRolesWithLesserRankByClientUID(uid uuid.UUID, rank int) ([]*models.UserRole, error)

func (*SQLCRUD) GetUsersWithLesserRank

func (crud *SQLCRUD) GetUsersWithLesserRank(rank int) ([]*models.User, error)

func (*SQLCRUD) SaveSession

func (crud *SQLCRUD) SaveSession(session *models.Session) error

func (*SQLCRUD) Setup

func (crud *SQLCRUD) Setup() error

Setup creates the migration table if it does not already exist.

func (*SQLCRUD) UpdateClient

func (crud *SQLCRUD) UpdateClient(client *models.Client) (bool, error)

func (*SQLCRUD) UpdateUser

func (crud *SQLCRUD) UpdateUser(user *models.User) (bool, error)

func (*SQLCRUD) UpdateUserPassword

func (crud *SQLCRUD) UpdateUserPassword(username string, hash []byte) (bool, error)

func (*SQLCRUD) UpdateUserRole

func (crud *SQLCRUD) UpdateUserRole(role *models.UserRole) (bool, error)

type SQLDriver

type SQLDriver interface {
	SQLScriptRepository

	// GetDriverName returns the name for the driver.
	GetDriverName() string
}

type SQLExecutor

type SQLExecutor struct {
	DB *sql.DB
	SQLCRUD
}

func (*SQLExecutor) CreateTransaction

func (exec *SQLExecutor) CreateTransaction() (data.Transaction, error)

type SQLScriptRepository

SQLScriptRepository is an interface for encapsulating other sql script repositories.

type SQLTransaction

type SQLTransaction struct {
	*sql.Tx
	SQLCRUD
}

type SessionScriptRepository

type SessionScriptRepository interface {
	CreateSessionTableScript() string
	DropSessionTableScript() string
	SaveSessionScript() string
	GetSessionByTokenScript() string
	DeleteSessionScript() string
	DeleteAllUserSessionsScript() string
	DeleteAllOtherUserSessionsScript() string
}

SessionScriptRepository is an interface for fetching session sql scripts.

type UserRoleScriptRepository

type UserRoleScriptRepository interface {
	CreateUserRoleTableScript() string
	DropUserRoleTableScript() string
	CreateUserRoleScript() string
	GetUserRolesWithLesserRankByClientUIDScript() string
	GetUserRoleByClientUIDAndUsernameScript() string
	UpdateUserRoleScript() string
	DeleteUserRoleScript() string
}

UserRoleScriptRepository is an interface for fetching user-role sql scripts.

type UserScriptRepository

type UserScriptRepository interface {
	CreateUserTableScript() string
	DropUserTableScript() string
	CreateUserScript() string
	GetUsersWithLesserRankScript() string
	GetUserByUsernameScript() string
	UpdateUserScript() string
	UpdateUserPasswordScript() string
	DeleteUserScript() string
}

UserScriptRepository is an interface for fetching user sql scripts.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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