database

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

func NewConnection

func NewConnection(
	db *sqlx.DB,
	configOptions ...ConnectionConfigurator,
) *Connection

func (*Connection) Execute

func (c *Connection) Execute(ctx context.Context, statement string, parameters map[string]any) (sql.Result, error)

func (*Connection) Select

func (c *Connection) Select(ctx context.Context, target any, statement string, parameters map[string]any) error

type ConnectionConfigurator added in v0.0.2

type ConnectionConfigurator func(connection *Connection)

func WithPreRunHook added in v0.0.2

func WithPreRunHook(preRunHook PreRunHook) ConnectionConfigurator

type Entity

type Entity interface {
	TableName() string
	Joins() string
}

type PreRunHook added in v0.0.2

type PreRunHook func(statement string, parameters map[string]any) error

type Query

type Query struct {
	Select     string
	From       string
	Join       string
	Where      string
	OrderBy    string
	GroupBy    string
	Having     string
	Limit      string
	PrimaryKey string
}

func GenerateQuery

func GenerateQuery(e Entity) Query

func (Query) String

func (q Query) String() string

type ReadOnlyRepository

type ReadOnlyRepository[T Entity] struct {
	// contains filtered or unexported fields
}

func NewReadOnlyRepository

func NewReadOnlyRepository[T Entity](connection *Connection) *ReadOnlyRepository[T]

func (ReadOnlyRepository[T]) Find

func (repo ReadOnlyRepository[T]) Find(ctx context.Context, query Query, parameters map[string]any) ([]T, error)

func (ReadOnlyRepository[T]) FindOne

func (repo ReadOnlyRepository[T]) FindOne(ctx context.Context, query Query, parameters map[string]any) (T, error)

type Repository

type Repository[T Entity] struct {
	*ReadOnlyRepository[T]
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[T Entity](connection *Connection) *Repository[T]

func (Repository[T]) Delete

func (repo Repository[T]) Delete(ctx context.Context, entity T) error

func (Repository[T]) Insert

func (repo Repository[T]) Insert(ctx context.Context, entity T) (uint64, error)

func (Repository[T]) Save

func (repo Repository[T]) Save(ctx context.Context, entity T) error

func (Repository[T]) Update

func (repo Repository[T]) Update(ctx context.Context, entity T) error

Jump to

Keyboard shortcuts

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