mongo

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustOpen

func MustOpen(name string) *mongo.Database

func Open

func Open(name string) (*mongo.Database, error)

Types

type Table

type Table[T, K any] struct {
	*mongo.Collection
}

func NewTable

func NewTable[T, K any](db *mongo.Database, name string, opts ...*options.CollectionOptions) *Table[T, K]

func (*Table[T, K]) Create

func (t *Table[T, K]) Create(ctx context.Context, doc *T) (err error)

Create insert a new document to database.

func (*Table[T, K]) Delete

func (t *Table[T, K]) Delete(ctx context.Context, id K) (err error)

Delete deletes document by ID.

func (*Table[T, K]) Fetch

func (t *Table[T, K]) Fetch(ctx context.Context, filter, sorter any) (records []*T, err error)

Fetch returns all qualified records.

func (*Table[T, K]) FetchByPage

func (t *Table[T, K]) FetchByPage(ctx context.Context, pageIndex, pageSize int64, filter, sorter any) (records []*T, count int64, err error)

FetchByPage returns qualified records with paging.

func (*Table[T, K]) Query

func (t *Table[T, K]) Query(ctx context.Context, id K) (r *T, err error)

func (*Table[T, K]) QueryByFilter

func (t *Table[T, K]) QueryByFilter(ctx context.Context, filter any) (r *T, err error)

func (*Table[T, K]) Update

func (t *Table[T, K]) Update(ctx context.Context, id K, update any) (err error)

Update updates document by ID.

func (*Table[T, K]) Upsert

func (t *Table[T, K]) Upsert(ctx context.Context, id K, update any) (err error)

Upsert updates document by ID if found, otherwise insert document.

Jump to

Keyboard shortcuts

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