database

package
v0.0.0-...-0cfe5d7 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLackOfInfor = errors.New("lack of information")

Functions

func InitAndMigrateUpDatabase

func InitAndMigrateUpDatabase(databaseConfig configs.Database, logger *zap.Logger) (*sql.DB, func(), error)

Types

type Account

type Account struct {
	Id          uint64    `json:"id"`
	Username    string    `json:"username"`
	Fullname    string    `json:"fullname"`
	Email       string    `json:"email"`
	PhoneNumber string    `json:"phone_number"`
	RoleId      uint8     `json:"role_id"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type AccountAccessor

type AccountAccessor interface {
	CreateAccount(ctx context.Context, account Account) (uint64, error)

	GetAccount(ctx context.Context, id uint64) (Account, error)
	GetAccountByUsername(ctx context.Context, username string) (Account, error)

	UpdateAccount(ctx context.Context, account Account) error

	DeleteAccount(ctx context.Context, id uint64) error
	DeleteAccountByUsername(ctx context.Context, username string) error

	IsUsernameTaken(ctx context.Context, username string) (bool, error)

	GetAccountAll(ctx context.Context) ([]Account, error)
	GetAccountList(ctx context.Context, ids []uint64) ([]Account, error)

	WithExecutor(exec Executor) AccountAccessor
}

func NewAccountAccessor

func NewAccountAccessor(
	exec Executor,
	logger *zap.Logger,
) AccountAccessor

type AccountPassword

type AccountPassword struct {
	OfAccountId  uint64    `json:"of_account_id"`
	HashedString string    `json:"hashed_string"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

type AccountPasswordAccessor

type AccountPasswordAccessor interface {
	CreateAccountPassword(ctx context.Context, ap AccountPassword) error
	GetAccountPassword(ctx context.Context, id uint64) (AccountPassword, error)
	UpdateAccountPassword(ctx context.Context, ap AccountPassword) error
	DeleteAccountPassword(ctx context.Context, id uint64) error
	WithExecutor(exec Executor) AccountPasswordAccessor
}

func NewAccountPasswordAccessor

func NewAccountPasswordAccessor(
	exec Executor,
	logger *zap.Logger,
) AccountPasswordAccessor

type AccountRole

type AccountRole struct {
	Id   uint8  `json:"id"`
	Name string `json:"name"`
}

type AccountRoleAccessor

type AccountRoleAccessor interface {
	GetRoleById(ctx context.Context, id uint8) (AccountRole, error)
	GetRoleByName(ctx context.Context, name string) (AccountRole, error)
	WithExecutor(exec Executor) AccountRoleAccessor
}

func NewAccountRoleAccessor

func NewAccountRoleAccessor(
	exec Executor,
	logger *zap.Logger,
) AccountRoleAccessor

type Executor

type Executor interface {
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, 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

	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}

type Migration

type Migration interface {
	Up(ctx context.Context) error
	Down(ctx context.Context) error
}

func NewMigrator

func NewMigrator(
	db *sql.DB,
	logger *zap.Logger,
) Migration

Jump to

Keyboard shortcuts

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