sqlutils

package
v0.0.0-...-80236ea Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sqlutils is a generated GoMock package.

Index

Constants

View Source
const (
	DESC = "DESC" // Descending order.
	ASC  = "ASC"  // Ascending order.
)

Variables

This section is empty.

Functions

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation check if error is a unique constraint violation error

func IsUniqueViolationByField

func IsUniqueViolationByField(err error, field string) bool

IsUniqueViolationByField check if error is a unique constraint violation error by field

func Sorting

func Sorting(field, direction string) string

Sorting constructs an SQL sorting clause for the specified field and direction.

func WithTx

func WithTx[R any](ctx context.Context, db SQLDB, f func(q SQLTX) (R, error)) (R, error)

WithTx manages a database transaction, handling commit or rollback based on the function's success.

Types

type MockQuerier

type MockQuerier struct {
	// contains filtered or unexported fields
}

MockQuerier is a mock of Querier interface.

func NewMockQuerier

func NewMockQuerier(ctrl *gomock.Controller) *MockQuerier

NewMockQuerier creates a new mock instance.

func (*MockQuerier) EXPECT

func (m *MockQuerier) EXPECT() *MockQuerierMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockQuerier) Exec

func (m *MockQuerier) Exec(query string, args ...any) (sql.Result, error)

Exec mocks base method.

func (*MockQuerier) ExecContext

func (m *MockQuerier) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext mocks base method.

func (*MockQuerier) Prepare

func (m *MockQuerier) Prepare(query string) (*sql.Stmt, error)

Prepare mocks base method.

func (*MockQuerier) PrepareContext

func (m *MockQuerier) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

PrepareContext mocks base method.

func (*MockQuerier) Query

func (m *MockQuerier) Query(query string, args ...any) (*sql.Rows, error)

Query mocks base method.

func (*MockQuerier) QueryContext

func (m *MockQuerier) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext mocks base method.

func (*MockQuerier) QueryRow

func (m *MockQuerier) QueryRow(query string, args ...any) *sql.Row

QueryRow mocks base method.

func (*MockQuerier) QueryRowContext

func (m *MockQuerier) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext mocks base method.

type MockQuerierMockRecorder

type MockQuerierMockRecorder struct {
	// contains filtered or unexported fields
}

MockQuerierMockRecorder is the mock recorder for MockQuerier.

func (*MockQuerierMockRecorder) Exec

func (mr *MockQuerierMockRecorder) Exec(query any, args ...any) *gomock.Call

Exec indicates an expected call of Exec.

func (*MockQuerierMockRecorder) ExecContext

func (mr *MockQuerierMockRecorder) ExecContext(ctx, query any, args ...any) *gomock.Call

ExecContext indicates an expected call of ExecContext.

func (*MockQuerierMockRecorder) Prepare

func (mr *MockQuerierMockRecorder) Prepare(query any) *gomock.Call

Prepare indicates an expected call of Prepare.

func (*MockQuerierMockRecorder) PrepareContext

func (mr *MockQuerierMockRecorder) PrepareContext(ctx, query any) *gomock.Call

PrepareContext indicates an expected call of PrepareContext.

func (*MockQuerierMockRecorder) Query

func (mr *MockQuerierMockRecorder) Query(query any, args ...any) *gomock.Call

Query indicates an expected call of Query.

func (*MockQuerierMockRecorder) QueryContext

func (mr *MockQuerierMockRecorder) QueryContext(ctx, query any, args ...any) *gomock.Call

QueryContext indicates an expected call of QueryContext.

func (*MockQuerierMockRecorder) QueryRow

func (mr *MockQuerierMockRecorder) QueryRow(query any, args ...any) *gomock.Call

QueryRow indicates an expected call of QueryRow.

func (*MockQuerierMockRecorder) QueryRowContext

func (mr *MockQuerierMockRecorder) QueryRowContext(ctx, query any, args ...any) *gomock.Call

QueryRowContext indicates an expected call of QueryRowContext.

type MockResult

type MockResult struct {
	// contains filtered or unexported fields
}

MockResult is a mock of Result interface.

func NewMockResult

func NewMockResult(ctrl *gomock.Controller) *MockResult

NewMockResult creates a new mock instance.

func (*MockResult) EXPECT

func (m *MockResult) EXPECT() *MockResultMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockResult) LastInsertId

func (m *MockResult) LastInsertId() (int64, error)

LastInsertId mocks base method.

func (*MockResult) RowsAffected

func (m *MockResult) RowsAffected() (int64, error)

RowsAffected mocks base method.

type MockResultMockRecorder

type MockResultMockRecorder struct {
	// contains filtered or unexported fields
}

MockResultMockRecorder is the mock recorder for MockResult.

func (*MockResultMockRecorder) LastInsertId

func (mr *MockResultMockRecorder) LastInsertId() *gomock.Call

LastInsertId indicates an expected call of LastInsertId.

func (*MockResultMockRecorder) RowsAffected

func (mr *MockResultMockRecorder) RowsAffected() *gomock.Call

RowsAffected indicates an expected call of RowsAffected.

type MockSQLDB

type MockSQLDB struct {
	// contains filtered or unexported fields
}

MockSQLDB is a mock of SQLDB interface.

func MockSQLDBHelper

func MockSQLDBHelper(ctrl *gomock.Controller) *MockSQLDB

func NewMockSQLDB

func NewMockSQLDB(ctrl *gomock.Controller) *MockSQLDB

NewMockSQLDB creates a new mock instance.

func (*MockSQLDB) BeginTx

func (m *MockSQLDB) BeginTx(ctx context.Context, opts *sql.TxOptions) (SQLTX, error)

BeginTx mocks base method.

func (*MockSQLDB) Close

func (m *MockSQLDB) Close() error

Close mocks base method.

func (*MockSQLDB) EXPECT

func (m *MockSQLDB) EXPECT() *MockSQLDBMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSQLDB) Exec

func (m *MockSQLDB) Exec(query string, args ...any) (sql.Result, error)

Exec mocks base method.

func (*MockSQLDB) ExecContext

func (m *MockSQLDB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext mocks base method.

func (*MockSQLDB) Ping

func (m *MockSQLDB) Ping() error

Ping mocks base method.

func (*MockSQLDB) Prepare

func (m *MockSQLDB) Prepare(query string) (*sql.Stmt, error)

Prepare mocks base method.

func (*MockSQLDB) PrepareContext

func (m *MockSQLDB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

PrepareContext mocks base method.

func (*MockSQLDB) Query

func (m *MockSQLDB) Query(query string, args ...any) (*sql.Rows, error)

Query mocks base method.

func (*MockSQLDB) QueryContext

func (m *MockSQLDB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext mocks base method.

func (*MockSQLDB) QueryRow

func (m *MockSQLDB) QueryRow(query string, args ...any) *sql.Row

QueryRow mocks base method.

func (*MockSQLDB) QueryRowContext

func (m *MockSQLDB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext mocks base method.

type MockSQLDBMockRecorder

type MockSQLDBMockRecorder struct {
	// contains filtered or unexported fields
}

MockSQLDBMockRecorder is the mock recorder for MockSQLDB.

func (*MockSQLDBMockRecorder) BeginTx

func (mr *MockSQLDBMockRecorder) BeginTx(ctx, opts any) *gomock.Call

BeginTx indicates an expected call of BeginTx.

func (*MockSQLDBMockRecorder) Close

func (mr *MockSQLDBMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockSQLDBMockRecorder) Exec

func (mr *MockSQLDBMockRecorder) Exec(query any, args ...any) *gomock.Call

Exec indicates an expected call of Exec.

func (*MockSQLDBMockRecorder) ExecContext

func (mr *MockSQLDBMockRecorder) ExecContext(ctx, query any, args ...any) *gomock.Call

ExecContext indicates an expected call of ExecContext.

func (*MockSQLDBMockRecorder) Ping

func (mr *MockSQLDBMockRecorder) Ping() *gomock.Call

Ping indicates an expected call of Ping.

func (*MockSQLDBMockRecorder) Prepare

func (mr *MockSQLDBMockRecorder) Prepare(query any) *gomock.Call

Prepare indicates an expected call of Prepare.

func (*MockSQLDBMockRecorder) PrepareContext

func (mr *MockSQLDBMockRecorder) PrepareContext(ctx, query any) *gomock.Call

PrepareContext indicates an expected call of PrepareContext.

func (*MockSQLDBMockRecorder) Query

func (mr *MockSQLDBMockRecorder) Query(query any, args ...any) *gomock.Call

Query indicates an expected call of Query.

func (*MockSQLDBMockRecorder) QueryContext

func (mr *MockSQLDBMockRecorder) QueryContext(ctx, query any, args ...any) *gomock.Call

QueryContext indicates an expected call of QueryContext.

func (*MockSQLDBMockRecorder) QueryRow

func (mr *MockSQLDBMockRecorder) QueryRow(query any, args ...any) *gomock.Call

QueryRow indicates an expected call of QueryRow.

func (*MockSQLDBMockRecorder) QueryRowContext

func (mr *MockSQLDBMockRecorder) QueryRowContext(ctx, query any, args ...any) *gomock.Call

QueryRowContext indicates an expected call of QueryRowContext.

type MockSQLTX

type MockSQLTX struct {
	// contains filtered or unexported fields
}

MockSQLTX is a mock of SQLTX interface.

func NewMockSQLTX

func NewMockSQLTX(ctrl *gomock.Controller) *MockSQLTX

NewMockSQLTX creates a new mock instance.

func (*MockSQLTX) Commit

func (m *MockSQLTX) Commit() error

Commit mocks base method.

func (*MockSQLTX) EXPECT

func (m *MockSQLTX) EXPECT() *MockSQLTXMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSQLTX) Exec

func (m *MockSQLTX) Exec(query string, args ...any) (sql.Result, error)

Exec mocks base method.

func (*MockSQLTX) ExecContext

func (m *MockSQLTX) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext mocks base method.

func (*MockSQLTX) Prepare

func (m *MockSQLTX) Prepare(query string) (*sql.Stmt, error)

Prepare mocks base method.

func (*MockSQLTX) PrepareContext

func (m *MockSQLTX) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

PrepareContext mocks base method.

func (*MockSQLTX) Query

func (m *MockSQLTX) Query(query string, args ...any) (*sql.Rows, error)

Query mocks base method.

func (*MockSQLTX) QueryContext

func (m *MockSQLTX) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext mocks base method.

func (*MockSQLTX) QueryRow

func (m *MockSQLTX) QueryRow(query string, args ...any) *sql.Row

QueryRow mocks base method.

func (*MockSQLTX) QueryRowContext

func (m *MockSQLTX) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext mocks base method.

func (*MockSQLTX) Rollback

func (m *MockSQLTX) Rollback() error

Rollback mocks base method.

type MockSQLTXMockRecorder

type MockSQLTXMockRecorder struct {
	// contains filtered or unexported fields
}

MockSQLTXMockRecorder is the mock recorder for MockSQLTX.

func (*MockSQLTXMockRecorder) Commit

func (mr *MockSQLTXMockRecorder) Commit() *gomock.Call

Commit indicates an expected call of Commit.

func (*MockSQLTXMockRecorder) Exec

func (mr *MockSQLTXMockRecorder) Exec(query any, args ...any) *gomock.Call

Exec indicates an expected call of Exec.

func (*MockSQLTXMockRecorder) ExecContext

func (mr *MockSQLTXMockRecorder) ExecContext(ctx, query any, args ...any) *gomock.Call

ExecContext indicates an expected call of ExecContext.

func (*MockSQLTXMockRecorder) Prepare

func (mr *MockSQLTXMockRecorder) Prepare(query any) *gomock.Call

Prepare indicates an expected call of Prepare.

func (*MockSQLTXMockRecorder) PrepareContext

func (mr *MockSQLTXMockRecorder) PrepareContext(ctx, query any) *gomock.Call

PrepareContext indicates an expected call of PrepareContext.

func (*MockSQLTXMockRecorder) Query

func (mr *MockSQLTXMockRecorder) Query(query any, args ...any) *gomock.Call

Query indicates an expected call of Query.

func (*MockSQLTXMockRecorder) QueryContext

func (mr *MockSQLTXMockRecorder) QueryContext(ctx, query any, args ...any) *gomock.Call

QueryContext indicates an expected call of QueryContext.

func (*MockSQLTXMockRecorder) QueryRow

func (mr *MockSQLTXMockRecorder) QueryRow(query any, args ...any) *gomock.Call

QueryRow indicates an expected call of QueryRow.

func (*MockSQLTXMockRecorder) QueryRowContext

func (mr *MockSQLTXMockRecorder) QueryRowContext(ctx, query any, args ...any) *gomock.Call

QueryRowContext indicates an expected call of QueryRowContext.

func (*MockSQLTXMockRecorder) Rollback

func (mr *MockSQLTXMockRecorder) Rollback() *gomock.Call

Rollback indicates an expected call of Rollback.

type PaginationResult

type PaginationResult struct {
	Limit  int32
	Offset int32
}

PaginationResult represents pagination parameters with limit and offset values.

func Pagination

func Pagination(page, perPage string) PaginationResult

Pagination calculates and returns the pagination limit and offset based on the page and perPage parameters.

type Querier

type Querier interface {
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Querier defines an interface for executing SQL queries and statements. It abstracts the basic database operations to support flexibility for various implementations.

type SQLDB

type SQLDB interface {
	Querier
	BeginTx(ctx context.Context, opts *sql.TxOptions) (SQLTX, error)
	Close() error
	Ping() error
}

SQLDB represents an SQL database client, extending the Querier interface with methods for transaction management and connection lifecycle.

type SQLTX

type SQLTX interface {
	Querier
	Commit() error
	Rollback() error
}

SQLTX represents an SQL transaction, extending the Querier interface with methods to manage transaction lifecycle.

type Storage

type Storage struct {
	Client SQLDB
}

Storage encapsulates a SQL database client, providing methods for managing connection cleanup and interacting with the database.

func New

func New(client SQLDB) *Storage

New initializes and returns a new Storage instance with the given SQL client.

func (*Storage) Cleanup

func (s *Storage) Cleanup() error

Cleanup closes the SQL database connection, releasing all allocated resources.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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