db

package
v0.0.0-...-a204096 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockCollection = "lock"
	GlobalLockId   = "global"
	LockTimeout    = time.Minute * 8
)
View Source
const (
	GlobalsCollection = "globals"
)

Variables

View Source
var (
	NoProjection = bson.M{}
	NoSort       = []string{}
	NoSkip       = 0
	NoLimit      = 0
)

Functions

func AcquireGlobalLock

func AcquireGlobalLock(id string) (bool, error)

AcquireGlobalLock attempts to acquire the global lock if no one has it or it's timed out. Returns a boolean indicating whether the lock was acquired.

func Aggregate

func Aggregate(collection string, pipeline interface{}, out interface{}) error

Aggregate runs an aggregation pipeline on a collection and unmarshals the results to the given "out" interface (usually a pointer to an array of structs/bson.M)

func Clear

func Clear(collection string) error

Clear removes all documents from a specified collection.

func ClearCollections

func ClearCollections(collections ...string) error

ClearCollections clears all documents from all the specified collections, returning an error immediately if clearing any one of them fails.

func Count

func Count(collection string, query interface{}) (int, error)

Count run a count command with the specified query against the collection.

func CountQ

func CountQ(collection string, q Q) (int, error)

CountQ runs a Q count query against the given collection.

func FindAll

func FindAll(collection string, query interface{},
	projection interface{}, sort []string, skip int, limit int,
	out interface{}) error

FindAll finds the items from the specified collection and unmarshals them into the provided interface, which must be a slice.

func FindAllQ

func FindAllQ(collection string, q Q, out interface{}) error

FindAllQ runs a Q query against the given collection, applying the results to "out."

func FindAndModify

func FindAndModify(collection string, query interface{}, sort []string,
	change mgo.Change, out interface{}) (*mgo.ChangeInfo, error)

FindAndModify runs the specified query and change against the collection, unmarshaling the result into the specified interface.

func FindOne

func FindOne(collection string, query interface{},
	projection interface{}, sort []string, out interface{}) error

FindOne finds one item from the specified collection and unmarshals it into the provided interface, which must be a pointer.

func FindOneQ

func FindOneQ(collection string, q Q, out interface{}) error

FindOneQ runs a Q query against the given collection, applying the results to "out." Only reads one document from the DB.

func GetGridFile

func GetGridFile(fsPrefix, name string) (io.ReadCloser, error)

GetGridFile returns a ReadCloser for a file stored with the given name under the GridFS prefix.

func GetNewBuildVariantBuildNumber

func GetNewBuildVariantBuildNumber(buildVariant string) (uint64, error)

GetNewBuildVariantBuildNumber atomically gets a new number for a build, given its variant name.

func GetNewBuildVariantTaskNumber

func GetNewBuildVariantTaskNumber(buildVariant string) (uint64, error)

GetNewBuildVariantTaskNumber atomically gets a new number for a task, given its variant name.

func InitializeGlobalLock

func InitializeGlobalLock() error

InitializeGlobalLock should be called once, at program initialization.

func Insert

func Insert(collection string, item interface{}) error

Insert inserts the specified item into the specified collection.

func ReleaseGlobalLock

func ReleaseGlobalLock(id string) error

ReleaseGlobalLock relinquishes the global lock for the given id.

func Remove

func Remove(collection string, query interface{}) error

Remove removes one item matching the query from the specified collection.

func RemoveAll

func RemoveAll(collection string, query interface{}) error

RemoveAll removes all items matching the query from the specified collection.

func RemoveAllQ

func RemoveAllQ(collection string, q Q) error

RemoveAllQ removes all docs that satisfy the query

func SetGlobalSessionProvider

func SetGlobalSessionProvider(sessionProvider SessionProvider)

SetGlobalSessionProvider sets the global session provider.

func Update

func Update(collection string, query interface{},
	update interface{}) error

Update updates one matching document in the collection.

func UpdateAll

func UpdateAll(collection string, query interface{},
	update interface{}) (*mgo.ChangeInfo, error)

UpdateAll updates all matching documents in the collection.

func UpdateId

func UpdateId(collection string, id, update interface{}) error

UpdateId updates one _id-matching document in the collection.

func Upsert

func Upsert(collection string, query interface{},
	update interface{}) (*mgo.ChangeInfo, error)

Upsert run the specified update against the collection as an upsert operation.

func WaitTillAcquireGlobalLock

func WaitTillAcquireGlobalLock(id string, timeoutMS time.Duration) (bool, error)

WaitTillAcquireGlobalLock "spins" on acquiring the given database lock, for the process id, until timeoutMS. Returns whether or not the lock was acquired.

func WriteGridFile

func WriteGridFile(fsPrefix, name string, source io.Reader) error

WriteGridFile writes the data in the source Reader to a GridFS collection with the given prefix and filename.

Types

type Global

type Global struct {
	BuildVariant    string `bson:"_id"`
	LastBuildNumber uint64 `bson:"last_build_number"`
	LastTaskNumber  uint64 `bson:"last_task_number"`
}

Global stores internal tracking information.

type Lock

type Lock struct {
	Id       string    `bson:"_id"`
	Locked   bool      `bson:"locked"`
	LockedBy string    `bson:"locked_by"`
	LockedAt time.Time `bson:"locked_at"`
}

Lock represents a lock stored in the database, for synchronization.

type Q

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

Q holds all information necessary to execute a query

func Query

func Query(filter interface{}) Q

Query creates a db.Q for the given MongoDB query. The filter can be a struct, bson.D, bson.M, nil, etc.

func (Q) Filter

func (q Q) Filter(filter interface{}) Q

func (Q) Limit

func (q Q) Limit(limit int) Q

func (Q) Project

func (q Q) Project(projection interface{}) Q

func (Q) Skip

func (q Q) Skip(skip int) Q

func (Q) Sort

func (q Q) Sort(sort []string) Q

func (Q) WithFields

func (q Q) WithFields(fields ...string) Q

func (Q) WithoutFields

func (q Q) WithoutFields(fields ...string) Q

type SessionFactory

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

SessionFactory contains information for connecting to Evergreen's MongoDB instance. Implements SessionProvider.

func NewSessionFactory

func NewSessionFactory(url, db string, ssl bool, safety mgo.Safe, dialTimeout time.Duration) *SessionFactory

NewSessionFactory returns a new session factory pointed at the given URL/DB combo, with the supplied timeout and writeconcern settings.

func SessionFactoryFromConfig

func SessionFactoryFromConfig(settings *evergreen.Settings) *SessionFactory

SessionFactoryFromConfig creates a usable SessionFactory from the Evergreen settings.

func (*SessionFactory) GetSession

func (sf *SessionFactory) GetSession() (*mgo.Session, *mgo.Database, error)

type SessionProvider

type SessionProvider interface {
	GetSession() (*mgo.Session, *mgo.Database, error)
}

SessionProvider returns mgo Sessions for database interaction.

func GetGlobalSessionFactory

func GetGlobalSessionFactory() SessionProvider

GetGlobalSessionFactory returns the global session provider.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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