database

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = errors.New("no rows")

Functions

func GenerateDelete

func GenerateDelete(entity Entity) (string, map[string]any, error)

func GenerateInsert

func GenerateInsert(entity Entity) (string, map[string]any, error)

func GenerateSave

func GenerateSave(entity Entity) (string, map[string]any, error)

func GenerateUpdate

func GenerateUpdate(entity Entity) (string, map[string]any, error)

func Prepare

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

Types

type Config added in v0.0.2

type Config struct {
	Hostname string
	Port     int
	Username string
	Password string
	Name     string
}

func (Config) DSN added in v0.0.2

func (c Config) DSN() string

type DBAL

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

func NewDBAL

func NewDBAL(config Config, logger *log.Logger) (*DBAL, error)

func (*DBAL) Ping added in v0.0.2

func (dbal *DBAL) Ping() error

func (*DBAL) RawExecute

func (dbal *DBAL) RawExecute(
	ctx context.Context,
	query string,
	parameters map[string]any,
) (sql.Result, error)

func (*DBAL) RawSelect

func (dbal *DBAL) RawSelect(
	ctx context.Context,
	query string,
	parameters map[string]any,
	targetPointer any,
) error

type Entity

type Entity interface {
	EntityInformation() EntityInformation
}

type EntityInformation

type EntityInformation struct {
	TableName string
}

type Query

type Query struct {
	Select  []string
	From    string
	Joins   []string
	Where   string
	GroupBy string
	OrderBy string
	Limit   struct {
		Count  int
		Offset int
	}
	Parameters map[string]any
}

func GenerateSelect

func GenerateSelect(entity Entity) (Query, error)

func ParseQuery

func ParseQuery(query string) (Query, error)

func (Query) String

func (q Query) String() string

type QueryModifier

type QueryModifier func(query Query) Query

func WithAdditionalWhere added in v0.0.2

func WithAdditionalWhere(where string, parameters map[string]any) QueryModifier

func WithLimitOverride

func WithLimitOverride(size int, offset int) QueryModifier

type Repository

type Repository[ID ~uint64, T Entity] struct {
	Selector[T]
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[ID ~uint64, T Entity](dbal *DBAL) Repository[ID, T]

func (*Repository[ID, T]) Insert

func (q *Repository[ID, T]) Insert(ctx context.Context, entity T) (ID, error)

func (*Repository[ID, T]) Save

func (q *Repository[ID, T]) Save(ctx context.Context, entity T) error

func (*Repository[ID, T]) Update

func (q *Repository[ID, T]) Update(ctx context.Context, entity T) error

type Selector

type Selector[T any] struct {
	// contains filtered or unexported fields
}

func NewSelector

func NewSelector[T any](connection *DBAL, query Query) Selector[T]

func (*Selector[T]) SelectMultiple

func (q *Selector[T]) SelectMultiple(ctx context.Context, mods ...QueryModifier) ([]T, error)

func (*Selector[T]) SelectSingle

func (q *Selector[T]) SelectSingle(ctx context.Context, mods ...QueryModifier) (T, error)

Jump to

Keyboard shortcuts

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