Some checks failed
Linting and tests / Linting (push) Failing after 37s
45 lines
1.7 KiB
Go
45 lines
1.7 KiB
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io/fs"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
// ServiceNameDatabase is a name for database service.
|
|
const ServiceNameDatabase = "core/database"
|
|
|
|
var (
|
|
// ErrDatabase indicates that error appeared somewhere in database service.
|
|
ErrDatabase = errors.New("database service")
|
|
// ErrDatabaseIsInvalid indicates that database service implementation is invalid.
|
|
ErrDatabaseIsInvalid = errors.New("database service implementation is invalid")
|
|
)
|
|
|
|
// Database is an interface for database service.
|
|
type Database interface {
|
|
// Exec is a proxy for ExecContext from sqlx.
|
|
Exec(ctx context.Context, query string, params ...interface{}) error
|
|
// Get is a proxy for GetContext from sqlx.
|
|
Get(ctx context.Context, target interface{}, query string, params ...interface{}) error
|
|
// NamedExec is a proxy for NamedExecContext from sqlx.
|
|
NamedExec(ctx context.Context, query string, param interface{}) error
|
|
// RegisterMigrations registers migrations for applying from other services. Migrations should reside
|
|
// in "migrations" directory in passed filesystem.
|
|
RegisterMigrations(moduleName string, fs fs.FS) error
|
|
// Select is a proxy for SelectContext from sqlx.
|
|
Select(ctx context.Context, target interface{}, query string, params ...interface{}) error
|
|
// Transaction is a wrapper for transactions processing which wraps sqlx's transactions.
|
|
Transaction(ctx context.Context) (DatabaseTransaction, error)
|
|
}
|
|
|
|
// DatabaseTransaction is an interface for database transactions controllers implementations.
|
|
type DatabaseTransaction interface {
|
|
Apply(steps ...TransactionFunc) error
|
|
}
|
|
|
|
// TransactionFunc is a function that is used in transactions to mangle with data.
|
|
type TransactionFunc func(*sqlx.Tx) error
|