The very basic client app, not adapted for mobiles.
This commit is contained in:
44
client/internal/services/core/database.go
Normal file
44
client/internal/services/core/database.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
Reference in New Issue
Block a user