db

package
v0.0.0-...-8f08b9d Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Code generated by db/gen/gen.go; DO NOT EDIT.

Index

Constants

View Source
const (
	// OK is for all OK
	OK = 0

	// UnknownError - errors that is not classified
	UnknownError = 2

	// NoMatchingDocument - error for no documents
	NoMatchingDocument = 47

	// DuplicateKey - Duplicate key
	DuplicateKey = 11000
)

Variables

This section is empty.

Functions

func Match

func Match(err error, codes ...int) bool

Types

type DB

type DB struct {
	// Collections _ connected collections from model
	Users *UserModel
}

func Connect

func Connect(opt Options) *DB

ConnectAll -- connect to mongo tables

type DBError

type DBError struct {
	Msg         string
	Code        int
	WriteErrors []mongo.WriteError
}

DBError - Database errors

func ParseError

func ParseError(err error) *DBError

ParseError - Parse db error from Error message

func (*DBError) Error

func (e *DBError) Error() string

func (*DBError) IsNoMatchingDocError

func (e *DBError) IsNoMatchingDocError() bool

type GeoSpatial

type GeoSpatial struct {
	Type        string    `bson:"type"`
	Coordinates []float64 `bson:"coordinates"`
	Location    string    `bson:"-"`
}

GeoSpatial - For location coordinates

func NewGeoPoint

func NewGeoPoint(longitude, latitude float64) *GeoSpatial

NewGeoPoint - Create a geo point

func (GeoSpatial) GetLatitude

func (t GeoSpatial) GetLatitude() float64

GetLatitude - to get longitude from geo spatial coordinate

func (GeoSpatial) GetLongitude

func (t GeoSpatial) GetLongitude() float64

GetLongitude - to get longitude from geo spatial coordinate

type MongoTransaction

type MongoTransaction struct {
	Cancel         context.CancelFunc
	Session        mongo.Session
	SessionContext mongo.SessionContext
	// contains filtered or unexported fields
}

MongoTransaction -

func NewTransaction

func NewTransaction(client *mongo.Client) (*MongoTransaction, error)

NewTransaction - Start mongo transaction

func (*MongoTransaction) AbortTransaction

func (t *MongoTransaction) AbortTransaction() error

AbortTransaction -

func (*MongoTransaction) CommitOrAbort

func (t *MongoTransaction) CommitOrAbort() error

CommitOrAbort -

func (*MongoTransaction) CommitTransaction

func (t *MongoTransaction) CommitTransaction() error

CommitTransaction -

func (*MongoTransaction) EndSession

func (t *MongoTransaction) EndSession()

EndSession -

func (*MongoTransaction) SetErr

func (t *MongoTransaction) SetErr(err error)

SetError -

type Options

type Options struct {
	Client *mongo.Client
	DB     string // db name to connect
}

type UserModel

type UserModel struct {
	ID     *primitive.ObjectID `bson:"_id,omitempty"`
	UserID *primitive.ObjectID `bson:"user_id,omitempty"`

	// fields
	DeletedAt *time.Time `bson:"deleted_at,omitempty"`
	UpdatedAt *time.Time `bson:"updated_at,omitempty"`
	CreatedAt *time.Time `bson:"created_at,omitempty"`
	// contains filtered or unexported fields
}

UserModel is the model for base table

func (*UserModel) Aggregate

func (model *UserModel) Aggregate(pipeline interface{}, opts ...*options.AggregateOptions) ([]UserModel, error)

Aggregate - mongodb aggregate

func (*UserModel) AggregateStream

func (model *UserModel) AggregateStream(pipeline interface{}, resultChan chan<- struct {
	Val UserModel
	Err error
}, opts ...*options.AggregateOptions)

Aggregate - mongodb aggregate

func (*UserModel) BulkWrite

func (model *UserModel) BulkWrite(models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)

func (UserModel) CreatedAtTag

func (model UserModel) CreatedAtTag() string

func (*UserModel) DeleteMany

func (model *UserModel) DeleteMany(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteMany -

func (*UserModel) DeleteManyTxn

func (model *UserModel) DeleteManyTxn(sc mongo.SessionContext, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteOneTxn - to DeleteOne

func (*UserModel) DeleteOne

func (model *UserModel) DeleteOne(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteOne - to DeleteOne

func (*UserModel) DeleteOneTxn

func (model *UserModel) DeleteOneTxn(sc mongo.SessionContext, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteOneTxn - to DeleteOne

func (UserModel) DeletedAtTag

func (model UserModel) DeletedAtTag() string

func (*UserModel) Distinct

func (model *UserModel) Distinct(fieldName string, query interface{}, opts ...*options.DistinctOptions) ([]interface{}, error)

func (*UserModel) Find

func (model *UserModel) Find(query interface{}, opts ...*options.FindOptions) ([]*UserModel, error)

Find - to find

func (*UserModel) FindOne

func (model *UserModel) FindOne(query interface{}, opts ...*options.FindOneOptions) (*UserModel, error)

FindOne - to findOne

func (*UserModel) FindOneAndUpdate

func (model *UserModel) FindOneAndUpdate(query interface{}, value interface{}, options ...*options.FindOneAndUpdateOptions) (*UserModel, error)

FindOneAndUpdate -

func (*UserModel) FindOneAndUpdateTxn

func (model *UserModel) FindOneAndUpdateTxn(sc mongo.SessionContext, query interface{}, value interface{}, options ...*options.FindOneAndUpdateOptions) (*UserModel, error)

FindOneAndUpdateTxn -

func (*UserModel) FindOneTxn

func (model *UserModel) FindOneTxn(sc mongo.SessionContext, query interface{}, opts ...*options.FindOneOptions) (*UserModel, error)

FindOne - to findOne

func (*UserModel) FindStream

func (model *UserModel) FindStream(query interface{}, result chan<- struct {
	Val UserModel
	Err error
}, opts ...*options.FindOptions)

Find - to find

func (*UserModel) GetCollectionName

func (model *UserModel) GetCollectionName() string

GetCollectionName - get collection name

func (UserModel) IDTag

func (model UserModel) IDTag() string

func (*UserModel) InsertOne

func (model *UserModel) InsertOne(value UserModel, opts ...*options.InsertOneOptions) (primitive.ObjectID, error)

InsertOne -

func (*UserModel) InsertOneTxn

func (model *UserModel) InsertOneTxn(sc mongo.SessionContext, value UserModel, opts ...*options.InsertOneOptions) (primitive.ObjectID, error)

InsertOneTxn -

func (*UserModel) SetUpdatedAt

func (model *UserModel) SetUpdatedAt()

SetUpdatedAt - Set updated at

func (*UserModel) UpdateMany

func (model *UserModel) UpdateMany(query interface{}, value interface{}, options ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateMany -

func (*UserModel) UpdateManyTxn

func (model *UserModel) UpdateManyTxn(sc mongo.SessionContext, query interface{}, value interface{}, options ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateManyTxn -

func (*UserModel) UpdateOne

func (model *UserModel) UpdateOne(query interface{}, value interface{}, options ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOne -

func (*UserModel) UpdateOneTxn

func (model *UserModel) UpdateOneTxn(sc mongo.SessionContext, query interface{}, value interface{}, options ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOneTxn -

func (UserModel) UpdatedAtTag

func (model UserModel) UpdatedAtTag() string

func (UserModel) UserIDTag

func (model UserModel) UserIDTag() string

func (*UserModel) Watch

func (model *UserModel) Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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