mongo

package
v0.0.0-...-b7fba14 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const PlanetsCollection = "planets"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Ping(context.Context, *readpref.ReadPref) error
	Connect(context.Context) error
	Database(string) Database
	Disconnect(context.Context) error
}

type ClientWrapping

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

func (*ClientWrapping) Connect

func (c *ClientWrapping) Connect(ctx context.Context) error

func (*ClientWrapping) Database

func (c *ClientWrapping) Database(name string) Database

func (*ClientWrapping) Disconnect

func (c *ClientWrapping) Disconnect(ctx context.Context) error

func (*ClientWrapping) Ping

func (c *ClientWrapping) Ping(ctx context.Context, readpref *readpref.ReadPref) error

type Collection

type Collection interface {
	Find(context.Context, interface{}, ...*options.FindOptions) (Cursor, error)
	Count(context.Context, interface{}) (int64, error)
	FindOne(context.Context, interface{}) SingleResult
	InsertOne(context.Context, interface{}) (*mongo.InsertOneResult, error)
}

type CollectionWrapping

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

func (*CollectionWrapping) Count

func (c *CollectionWrapping) Count(ctx context.Context, filter interface{}) (int64, error)

func (*CollectionWrapping) Find

func (c *CollectionWrapping) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (Cursor, error)

func (*CollectionWrapping) FindOne

func (c *CollectionWrapping) FindOne(ctx context.Context, filter interface{}) SingleResult

func (*CollectionWrapping) InsertOne

func (c *CollectionWrapping) InsertOne(ctx context.Context, doc interface{}) (*mongo.InsertOneResult, error)

type Cursor

type Cursor interface {
	Next(context.Context) bool
	Decode(interface{}) error
	Close(context.Context) error
	Err() error
}

type CursorWrapping

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

func (*CursorWrapping) Close

func (c *CursorWrapping) Close(ctx context.Context) error

func (*CursorWrapping) Decode

func (c *CursorWrapping) Decode(v interface{}) error

func (*CursorWrapping) Err

func (c *CursorWrapping) Err() error

func (*CursorWrapping) Next

func (c *CursorWrapping) Next(ctx context.Context) bool

type Database

type Database interface {
	Collection(string) Collection
}

type DatabaseWrapping

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

func (*DatabaseWrapping) Collection

func (d *DatabaseWrapping) Collection(name string) Collection

type Planet

type Planet struct {
	ID          primitive.ObjectID `json:"id" bson:"_id"`
	Name        string             `json:"name" bson:"name"`
	Climate     string             `json:"climate" bson:"climate"`
	Terrain     string             `json:"terrain" bson:"terrain"`
	Appearances int                `json:"appearances" bson:"appearances"`
	CreatedAt   time.Time          `json:"created_at" bson:"created_at"`
}

Planet defines the storage form of a planet

type SingleResult

type SingleResult interface {
	Decode(interface{}) error
}

type Storage

type Storage struct {
	URI       *url.URL
	Client    Client
	TimeoutMS time.Duration
}

Storage handles MongoDB transactions and its connections and contexts

func NewStorage

func NewStorage(uri string) *Storage

NewStorage returns a new MongoDB Storage

func (*Storage) AddPlanet

func (s *Storage) AddPlanet(ctx context.Context, p adding.Planet) (string, error)

AddPlanet saves the given planet to the repository

func (*Storage) Connect

func (s *Storage) Connect(ctx context.Context)

func (*Storage) DatabaseName

func (s *Storage) DatabaseName() string

func (*Storage) Disconnect

func (s *Storage) Disconnect(ctx context.Context)

func (*Storage) GetPlanet

func (s *Storage) GetPlanet(ctx context.Context, id string) (listing.Planet, error)

Get returns a planet with the specified ID

func (*Storage) GetPlanets

func (s *Storage) GetPlanets(ctx context.Context, offset int64, limit int64) ([]listing.Planet, int64)

GetPlanets returns all planets

func (*Storage) WithTimeout

func (s *Storage) WithTimeout(timeout time.Duration) *Storage

Jump to

Keyboard shortcuts

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