repos

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iface

type Iface interface {
	Sample() SampleRepo
}

Iface exposes the capabilities of persistent repositories.

Several repos may be exposed: just extend this with additional repo factories.

type Item

type Item struct {
	ID                string    `json:"id" db:"id"`                                // NOT NULL
	Name              string    `json:"name" db:"name"`                            // NOT NULL
	WarehouseLocation string    `json:"warehouseLocation" db:"warehouse_location"` // NOT NULL
	LastUpdated       time.Time `json:"lastUpdated" db:"last_updated"`             // NOT NULL
	Weight            float64   `json:"weight" db:"weight"`                        // NOT NULL

	Dimensions   pgtype.FlatArray[float64] `json:"dimensions" db:"dimensions"`                // NULL
	Attributes   map[string]interface{}    `json:"attributes,omitempty" db:"attributes"`      // NULL
	DeliveryTime *time.Duration            `json:"deliveryTime,omitempty" db:"delivery_time"` // NULL
	Description  *string                   `json:"description,omitempty" db:"description"`    // NULL
	Tags         map[string]string         `json:"tags,omitempty" db:"tags"`                  // NULL
}

Item represents a shippable item

type ItemOption

type ItemOption func(*itemOptions)

ItemOption lets the caller specify filters

func WithItemTags

func WithItemTags(enabled bool) ItemOption

WithItemTags instructs queries to join items against their tags

type ItemsIterator

type ItemsIterator = iterators.StructIterator[Item]

type RunnableRepo

type RunnableRepo interface {
	Iface

	Start() error
	Stop() error
	DB() *sqlx.DB
}

RunnableRepo serves repositories and is manageable by a runtime to start, monitor and stop the repo.

This version of the interface works against one single DB. Adopt DB(key string) to dispatch on multiple DBs.

type SampleRepo

type SampleRepo interface {
	Get(context.Context, string, ...ItemOption) (Item, error)
	Create(context.Context, Item) (string, error)
	Update(context.Context, Item) error
	Delete(context.Context, string) error
	List(context.Context, ...ItemOption) (ItemsIterator, error)
}

SampleRepo provides a simple CRUD database access to a table of shippable items.

type Validatable

type Validatable interface {
	Validate() error
}

Validatable knows how to validate a repo type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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