sds

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 1 Imported by: 0

README

Simple Data Store

Go Report Card Go Reference LICENSE

Simple Data Store (sds) is a simple storage interface I use that allows me to focus on my domain model instead of writing database logic. Additionally, this interface supports my testing workflows by providing different storage backends for different types of tests. This means I never need to mock a database for a test, I always have the real thing.

The data interface is small and opinionated. The goal is to support 90% of database needs, and allow the more complicated data models to be implemented with a more sophisticated library.

I have been building implementations for this interface as the need arises. Currently there are implementations for an in memory data base, bbolt, and mongodb. If you are interested in adding another database there is a test suite to ensure your implementation works correctly. I plan to write implementations for Firestore and Dynamo in the future, but only as the need arises. If you would like a database to be supported please leave a comment.

I recommending quickly reading the "how to" notes for any implementation you plan to use. They are in the how to directory.

More Information

Feedback

Please feel free to raise issues with any feedback. Questions, suggestions, improvements, and comments are all welcome.

Run the tests

The full test requires docker to be installed. Docker images for the databases will be started, and tests take a few seconds to run.

If you do not wish to have these tests included use the -short flag.

go test ./... -count=1 -short

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor = *string

Cursor is a way to keep track of what to fetch next.

type Entity

type Entity interface {
	GetID() string
}

Entity is an interface that some implementations will need to support to index items in a database.

type Options

type Options interface {
	Descending() bool
	Limit() int
	Cursor() Cursor
}

Options is a set of query parameters.

func MakeOpts

func MakeOpts(opts []QueryOption) Options

MakeOpts returns a set of query parameters.

type QueryOption

type QueryOption = func(*opt)

QueryOption provides a way to supply a cursor or a limit to a query.

func Descending

func Descending() QueryOption

Desending returns the query results in desending order based on creation time.

func WithCursor

func WithCursor(cursor Cursor) QueryOption

WithCursor adds a cursor to a query.

func WithLimit

func WithLimit(n int) QueryOption

WithLimit limits the number of items returned in a query.

type Repo

type Repo[A any] interface {
	Find(ctx context.Context, id string) (A, error)
	Save(ctx context.Context, item A) error
	Query(ctx context.Context, opts ...QueryOption) ([]A, Cursor, error)
	Delete(ctx context.Context, id string) error
}

Repo provides a way of storeing a generic Go item in a database.

Directories

Path Synopsis
lib
ei
sm

Jump to

Keyboard shortcuts

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