document

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 9 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count added in v1.3.0

func Count(ctx context.Context, collectionName string, query bson.M) (int, error)

func CountUnscoped added in v1.3.0

func CountUnscoped(ctx context.Context, collectionName string, query bson.M) (int, error)

func Create

func Create(ctx context.Context, collectionName string, doc document) error

Create inserts the document in the database, returns an error if document already exists and set CreatedAt timestamp

func Destroy

func Destroy(ctx context.Context, collectionName string, doc destroyable) error

Destroy really deletes

func EnsureParanoidIndices

func EnsureParanoidIndices(ctx context.Context, collectionNames ...string)

func Find

func Find(ctx context.Context, collectionName string, id bson.ObjectId, doc scopable, sortFields ...SortField) error

Find is finding the model with objectid id in the collection name, with its default scope for paranoid documents, it won't look at documents tagged as deleted

func FindOne

func FindOne(ctx context.Context, collectionName string, query bson.M, doc scopable, sortFields ...SortField) error

func FindOneUnscoped

func FindOneUnscoped(ctx context.Context, collectionName string, query bson.M, doc interface{}) error

func FindUnscoped

func FindUnscoped(ctx context.Context, collectionName string, id bson.ObjectId, doc interface{}, sortFields ...SortField) error

FindUnscoped is similar as Find but does not care of the default scope of the document.

func ReallyDestroy

func ReallyDestroy(ctx context.Context, collectionName string, doc document) error

func Restore

func Restore(ctx context.Context, collectionName string, doc document) error

func Save

func Save(ctx context.Context, collectionName string, doc document) error

func Update

func Update(ctx context.Context, collectionName string, update bson.M, doc document) error

func Where

func Where(ctx context.Context, collectionName string, query bson.M, data interface{}, sortFields ...SortField) error

func WhereIter

func WhereIter(ctx context.Context, collectionName string, query bson.M, fun func(*mgo.Iter) error, sortFields ...SortField) error

func WhereIterUnscoped

func WhereIterUnscoped(ctx context.Context, collectionName string, query bson.M, fun func(*mgo.Iter) error, sortFields ...SortField) error

func WhereUnscoped

func WhereUnscoped(ctx context.Context, collectionName string, query bson.M, data interface{}, sortFields ...SortField) error

Types

type Base

type Base struct {
	ID        bson.ObjectId `bson:"_id" json:"id"`
	CreatedAt time.Time     `bson:"created_at" json:"created_at"`
	UpdatedAt time.Time     `bson:"updated_at" json:"updated_at"`
}

func (Base) IsPersisted

func (d Base) IsPersisted() bool

func (*Base) Validate

func (d *Base) Validate(ctx context.Context) *ValidationErrors

type Closer

type Closer interface {
	Close()
}

func WhereQuery

func WhereQuery(ctx context.Context, collectionName string, query bson.M, sortFields ...SortField) (*mgo.Query, Closer)

func WhereUnscopedQuery

func WhereUnscopedQuery(ctx context.Context, collectionName string, query bson.M, sortFields ...SortField) (*mgo.Query, Closer)

type Paranoid

type Paranoid struct {
	Base      `bson:",inline"`
	DeletedAt *time.Time `bson:"deleted_at,omitempty" json:"deleted_at,omitempty"`
}

func (Paranoid) IsDeleted

func (p Paranoid) IsDeleted() bool

type SortField

type SortField string

type Validable

type Validable interface {
	Validate(ctx context.Context) *ValidationErrors
}

type ValidationErrors

type ValidationErrors = errors.ValidationErrors

ValidationErrors is a type alias of errors.ValidationErrors. It is defined to keep retro-compatibility

type ValidationErrorsBuilder

type ValidationErrorsBuilder = errors.ValidationErrorsBuilder

ValidationErrorsBuilder is a type alias of errors.ValidationErrorsBuilder. It is defined to keep retro-compatibility

func NewValidationErrorsBuilder

func NewValidationErrorsBuilder() *ValidationErrorsBuilder

NewValidationErrors return an empty ValidationErrors struct

Jump to

Keyboard shortcuts

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