database

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is a struct that represents a database connection.

func New

func New() *DB

New creates a new DB instance. Call Connect() to establish a connection.

func (*DB) AutoMigrate

func (db *DB) AutoMigrate(ctx context.Context, appVersion string) error

AutoMigrate runs the database migration.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Connect

func (db *DB) Connect(_ context.Context, dsn string) (*DB, error)

Connect establishes a connection to the database. It uses the sync.Once.Do function to ensure that the connection is only established once.

func (*DB) Count

func (db *DB) Count(ctx context.Context, options ...QueryOption) (uint64, error)

Count returns the count of benchmarks in the database.

func (*DB) CountAll

func (db *DB) CountAll(ctx context.Context) (uint64, error)

CountAll returns the count of all records in the database.

func (*DB) Fetch

func (db *DB) Fetch(ctx context.Context, options ...QueryOption) ([]*models.Benchmark, error)

Fetch fetches benchmarks from the database.

func (*DB) FetchByGroupIDs

func (db *DB) FetchByGroupIDs(ctx context.Context, ids []string, options ...QueryOption) ([]*ent.Benchmark, error)

FetchByGroupIDs fetches benchmarks by their group IDs.

func (*DB) FetchByIDs

func (db *DB) FetchByIDs(ctx context.Context, ids []string, options ...QueryOption) ([]*ent.Benchmark, error)

FetchByIDs fetches benchmarks by their IDs.

func (*DB) FetchGroupIDs

func (db *DB) FetchGroupIDs(ctx context.Context, options ...QueryOption) ([]string, error)

FetchGroupIDs fetches group IDs from the database.

func (*DB) RemoveByGroupIDs

func (db *DB) RemoveByGroupIDs(ctx context.Context, ids []string) error

RemoveByGroupIDs removes benchmarks by their group IDs.

func (*DB) RemoveByIDs

func (db *DB) RemoveByIDs(ctx context.Context, ids []string) error

RemoveByIDs removes benchmarks by their IDs.

func (*DB) Save

func (db *DB) Save(ctx context.Context, bmark *models.Benchmark) (*models.Benchmark, error)

Save saves a benchmark to the database.

func (*DB) SaveMany

func (db *DB) SaveMany(ctx context.Context, bmarks []*models.Benchmark) ([]*models.Benchmark, error)

SaveMany saves multiple benchmarks to the database.

func (*DB) ShouldMigrate

func (db *DB) ShouldMigrate(ctx context.Context, appVersion string) (bool, error)

ShouldMigrate checks if the database needs to be migrated.

type FilterFunc

type FilterFunc func(query *ent.BenchmarkQuery) *ent.BenchmarkQuery

FilterFunc is a type that defines a function that modifies a BenchmarkQuery.

type QueryOption

type QueryOption func(*QueryOptions)

QueryOption is a type that defines a function that modifies a QueryOptions.

func WithFilter

func WithFilter(filterFunc FilterFunc) QueryOption

WithFilter is a function that returns a QueryOption that adds a FilterFunc to the Filters field of a QueryOptions.

func WithLimit

func WithLimit(limit int) QueryOption

WithLimit is a function that returns a QueryOption that sets the Limit field of a QueryOptions.

func WithOffset

func WithOffset(offset int) QueryOption

WithOffset is a function that returns a QueryOption that sets the Offset field of a QueryOptions.

func WithOrderBy

func WithOrderBy(orderFunc func(query *ent.BenchmarkQuery) *ent.BenchmarkQuery) QueryOption

WithOrderBy is a function that returns a QueryOption that sets the OrderBy field of a QueryOptions.

type QueryOptions

type QueryOptions struct {
	OrderBy func(query *ent.BenchmarkQuery) *ent.BenchmarkQuery
	Filters []FilterFunc
	Limit   int
	Offset  int
}

QueryOptions is a struct that holds options for a query.

type Store

type Store interface {
	Save(ctx context.Context, res *models.Benchmark) (*models.Benchmark, error)
	SaveMany(ctx context.Context, res []*models.Benchmark) ([]*models.Benchmark, error)

	Fetch(ctx context.Context, options ...QueryOption) ([]*models.Benchmark, error)
	FetchByIDs(ctx context.Context, ids []string, options ...QueryOption) ([]*models.Benchmark, error)
	FetchByGroupIDs(ctx context.Context, ids []string, options ...QueryOption) ([]*models.Benchmark, error)
	FetchGroupIDs(ctx context.Context, options ...QueryOption) ([]string, error)
	Count(ctx context.Context, options ...QueryOption) (uint64, error)
	CountAll(ctx context.Context) (uint64, error)

	RemoveByIDs(ctx context.Context, ids []string) error
	RemoveByGroupIDs(ctx context.Context, ids []string) error
}

Store is an interface that defines the methods that a dbench store should implement.

Jump to

Keyboard shortcuts

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