testingdb

package
v1.0.31 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 14 Imported by: 0

README

A testing DB

This database is mainly for running within tests, it implements db.Connection

To understand the code it's best to read the *_test.go files

Filters

Supported:

  • Key has value filters ({foo: 'bar'})
  • Numeric filters $gt, $gte, $lt, $lte
  • Logical filters $eq, $ne, $not, $and, $or
  • Array filters $size
  • Others $type (only some types)

Noteworthy Unsupported:

  • Nested keys ({'foo.bar.bas': 'example'})
  • Array filters $in

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

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

Collection contains all the data for a collection

type TestConnection

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

TestConnection is the struct that implements db.Connection

func NewDB

func NewDB() *TestConnection

NewDB returns a testing database connection that is compatible with db.Connection

func (*TestConnection) Count

func (c *TestConnection) Count(entry db.Entry, filter bson.M) (uint64, error)

Count returns the number of documents in the collection of entity

func (*TestConnection) DeleteByID

func (c *TestConnection) DeleteByID(entry db.Entry, ids ...primitive.ObjectID) error

DeleteByID deletes a document by it's ID

func (*TestConnection) Dump

func (c *TestConnection) Dump(shouldPanic bool)

Dump prints the full database contents in the console This can be used in tests to dump the contents of the database might something fail or to debug

shouldPanic controls if the output is only printed or also should panic

func (*TestConnection) DumpCollection

func (c *TestConnection) DumpCollection(entry db.Entry, shouldPanic bool)

DumpCollection prints a full database collection it's contents in the console This can be used in tests to dump the contents of the database might something fail or to debug

shouldPanic controls if the output is only printed or also should panic

func (*TestConnection) Find

func (c *TestConnection) Find(base db.Entry, results any, filters bson.M, optionalOpts ...db.FindOptions) error

Find finds documents in the collection of the base The results can be filtered using filters The filters should work equal to MongoDB filters (https://docs.mongodb.com/manual/tutorial/query-documents/) tough this might miss features compared to mongoDB's filters

func (*TestConnection) FindOne

func (c *TestConnection) FindOne(placeInto db.Entry, filters bson.M, optionalOpts ...db.FindOptions) error

FindOne finds one document in the collection of placeInto The result can be filtered using filters The filters should work equal to MongoDB filters (https://docs.mongodb.com/manual/tutorial/query-documents/) tough this might miss features compared to mongoDB's filters

func (*TestConnection) Insert

func (c *TestConnection) Insert(data ...db.Entry) error

Insert inserts an item into the database Implements db.Connection

func (*TestConnection) RegisterEntries

func (*TestConnection) RegisterEntries(...db.Entry)

RegisterEntries implements db.Connection We don't need to implement this function

func (*TestConnection) UnsafeInsert

func (c *TestConnection) UnsafeInsert(entries ...db.Entry) error

UnsafeInsert inserts data directly into the database !!Be aware!!: - Not thread safe - Assumes the all entries are of same type / collection

func (*TestConnection) UpdateByID

func (c *TestConnection) UpdateByID(updateData db.Entry) error

UpdateByID updates a document in the database by its ID

Jump to

Keyboard shortcuts

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