db

package
v0.0.0-...-d4285bb Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2014 License: BSD-2-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package db provides an interface to mgo which allows us to store and retrieve Impendulo data from mongodb.

Index

Constants

View Source
const (
	//Mongodb collection name.
	USERS       = "users"
	SUBMISSIONS = "submissions"
	FILES       = "files"
	RESULTS     = "results"
	TESTS       = "tests"
	PROJECTS    = "projects"
	SKELETONS   = "skeletons"
	JPF         = "jpf"
	PMD         = "pmd"
	MAKE        = "make"
	//Mongodb command
	SET    = "$set"
	OR     = "$or"
	AND    = "$and"
	NOT    = "$not"
	NOR    = "$nor"
	LT     = "$lt"
	LTE    = "$lte"
	GT     = "$gt"
	GTE    = "$gte"
	IN     = "$in"
	NE     = "$ne"
	NIN    = "$nin"
	EXISTS = "$exists"
	ISTYPE = "$type"
	//Mongodb connection and db names
	ADDRESS      = "mongodb://localhost/"
	DEFAULT_DB   = "impendulo"
	DEBUG_DB     = "impendulo_debug"
	TEST_DB      = "impendulo_test"
	BACKUP_DB    = "impendulo_backup"
	DEFAULT_CONN = ADDRESS + DEFAULT_DB
	DEBUG_CONN   = "mongodb://localhost/impendulo_debug"
	TEST_CONN    = "mongodb://localhost/impendulo_test"
	//Field names
	TARGET      = "target"
	ID          = "_id"
	PROJECTID   = "projectid"
	PROJECT     = "project"
	USER        = "user"
	TIME        = "time"
	TYPE        = "type"
	TEST        = "test"
	NAME        = "name"
	PKG         = "package"
	LANG        = "lang"
	SUBID       = "subid"
	INFO        = "info"
	DATA        = "data"
	FILEID      = "fileid"
	TESTID      = "testid"
	SKELETON    = "skeleton"
	REPORT      = "report"
	STATUS      = "status"
	PWORD       = "password"
	SALT        = "salt"
	ACCESS      = "access"
	DESCRIPTION = "description"
	COMMENTS    = "comments"
)
View Source
const (
	GRIDFS_NAME = "fs"
)

Variables

View Source
var (
	DuplicateFile = errors.New("db already contains this file")
)

Functions

func Add

func Add(n string, i interface{}) error

Add adds a document to the specified collection.

func AddFileResult

func AddFileResult(fid bson.ObjectId, n string, v interface{}) error

AddFileResult adds or updates a result in a file's results.

func AddGridFile

func AddGridFile(id, data interface{}) error

AddGridFile creates a new GridFile and stores the provided data structure in it via gob.

func AddJPFConfig

func AddJPFConfig(cfg *jpf.Config) error

AddJPF overwrites a project's JPF configuration with the provided configuration.

func AddJUnitTest

func AddJUnitTest(t *junit.Test) error

AddJUnitTest overwrites one of a project's JUnit tests with the new JUnit test if it has the same name as the new test. Otherwise the new test is just added to the project's tests.

func AddMakefile

func AddMakefile(mf *mk.Makefile) error

func AddPMDRules

func AddPMDRules(r *pmd.Rules) error

AddPMDRules overwrites a project's current PMD rules with the provided rules.

func AddResult

func AddResult(r result.Tooler, n string) error

AddResult adds a new result to the active database.

func AddUsers

func AddUsers(users ...*user.User) error

AddUsers adds new users to the active database.

func Charter

func Charter(m, sl bson.M) (result.Charter, error)

func Charters

func Charters(fid bson.ObjectId) ([]result.Charter, error)

func CheckstyleResult

func CheckstyleResult(m, sl bson.M) (*checkstyle.Result, error)

CheckstyleResult retrieves a Result matching the given interface from the active database.

func CloneCollection

func CloneCollection(o, c string) error

CloneCollection

func CloneData

func CloneData(o string) error

CloneData

func Close

func Close()

Close shuts down the current session.

func Coder

func Coder(m, sl bson.M) (result.Coder, error)

func Collections

func Collections(db string) ([]string, error)

func Contains

func Contains(n string, m interface{}) bool

Contains checks whether the collection n contains any items matching m.

func CopyDB

func CopyDB(f, t string) error

CopyDB is used to copy the contents of one database to a new location.

func Count

func Count(n string, m interface{}) (int, error)

Count calculates the amount of items in the collection col which match matcher.

func Databases

func Databases() ([]string, error)

func DeleteDB

func DeleteDB(db string) error

DeleteDB removes a db.

func Displayer

func Displayer(m, sl bson.M) (result.Displayer, error)

func File

func File(m, sl interface{}) (*project.File, error)

File retrieves a file matching m from the active database.

func FileCount

func FileCount(sid bson.ObjectId, t project.Type) (int, error)

func FileNames

func FileNames(m interface{}) ([]string, error)

FileNames retrieves names of files matching the given interface from the active database.

func FileResultId

func FileResultId(sid bson.ObjectId, fname, rtipe, rname string) (bson.ObjectId, error)

func Files

func Files(m, sl interface{}, limit int, sort ...string) ([]*project.File, error)

Files retrieves files matching m from the active database.

func FindbugsResult

func FindbugsResult(m, sl bson.M) (*findbugs.Result, error)

FindbugsResult retrieves a Result matching the given interface from the active database.

func FirstFile

func FirstFile(m, sl interface{}) (*project.File, error)

func GCCResult

func GCCResult(m, sl bson.M) (*gcc.Result, error)

func GridFile

func GridFile(id, ret interface{}) error

GridFile loads a GridFile matching id into a provided data structure from GridFS.

func HasGridFile

func HasGridFile(r result.Tooler, sl bson.M) bool

HasGridFile checks whether this query needs to get data from GridFS

func JPFConfig

func JPFConfig(m, sl interface{}) (*jpf.Config, error)

JPFConfig retrieves a JPF configuration matching m from the active database.

func JPFResult

func JPFResult(m, sl bson.M) (*jpf.Result, error)

JPFResult retrieves a Result matching the given interface from the active database.

func JUnitResult

func JUnitResult(m, sl bson.M) (*junit.Result, error)

JUnitResult retrieves aResult matching the given interface from the active database.

func JUnitTest

func JUnitTest(m, sl interface{}) (*junit.Test, error)

JUnitTest retrieves a test matching the m from the active database.

func JUnitTests

func JUnitTests(m, sl interface{}) ([]*junit.Test, error)

JUnitTests retrieves all tests matching m from the active database.

func JacocoResult

func JacocoResult(m, sl bson.M) (*jacoco.Result, error)

func JavacResult

func JavacResult(m, sl bson.M) (*javac.Result, error)

JavacResult retrieves a JavacResult matching the given interface from the active database.

func LastFile

func LastFile(m, sl interface{}) (*project.File, error)

func Makefile

func Makefile(m, sl interface{}) (*mk.Makefile, error)

func PMDResult

func PMDResult(m, sl bson.M) (*pmd.Result, error)

PMDResult retrieves a Result matching the given interface from the active database.

func PMDRules

func PMDRules(m, sl interface{}) (*pmd.Rules, error)

PMDRules retrieves PMD rules matching m from the db.

func Project

func Project(m, sl interface{}) (*project.Project, error)

Project retrieves a project matching m from the active database.

func ProjectFileNames

func ProjectFileNames(id bson.ObjectId) ([]string, error)

func ProjectName

func ProjectName(i interface{}) (string, error)

func ProjectResults

func ProjectResults(pid bson.ObjectId) []string

func ProjectUsernames

func ProjectUsernames(pid bson.ObjectId) ([]string, error)

func Projects

func Projects(m, sl interface{}, sort ...string) ([]*project.Project, error)

Projects retrieves projects matching m from the active database.

func RemoveById

func RemoveById(n string, id interface{}) error

RemoveById removes a document matching the given id in collection n from the active database.

func RemoveFileById

func RemoveFileById(id interface{}) error

RemoveFileById removes a file matching the given id from the active database.

func RemoveProjectById

func RemoveProjectById(id interface{}) error

RemoveProjectById removes a project matching the given id from the active database.

func RemoveSubmissionById

func RemoveSubmissionById(id interface{}) error

RemoveSubmissionById removes a submission matching the given id from the active database.

func RemoveUserById

func RemoveUserById(id string) error

RemoveUserById removes a user matching the given id from the active database.

func RenameUser

func RenameUser(o, n string) error

func ResultNames

func ResultNames(sid bson.ObjectId, fname string) (map[string]map[string][]interface{}, error)

AllResultNames retrieves all result names for a given project.

func Session

func Session() (*mgo.Session, error)

Session retrieves the current active session.

func Setup

func Setup(c string) error

Setup creates a mongodb session. This must be called before using any other db functions.

func Skeleton

func Skeleton(m, sl interface{}) (*project.Skeleton, error)

func Skeletons

func Skeletons(m, sl interface{}, sort ...string) ([]*project.Skeleton, error)

func Snapshots

func Snapshots(sid bson.ObjectId, n string) ([]*project.File, error)

Snapshots retrieves snapshots of a given file in a submission.

func Submission

func Submission(m, sl interface{}) (*project.Submission, error)

Submission retrieves a submission matching m from the active database.

func Submissions

func Submissions(m, sl interface{}, sort ...string) ([]*project.Submission, error)

Submissions retrieves submissions matching m from the active database.

func Tooler

func Tooler(m, sl bson.M) (result.Tooler, error)

func TypeCounts

func TypeCounts(id interface{}) []int

func Update

func Update(n string, m, c interface{}) error

Update updates documents from the collection n matching m with the changes specified by c.

func UpdateAll

func UpdateAll(n string, m, c interface{}) error

func UpdateTime

func UpdateTime(sub *project.Submission) error

func User

func User(id string) (*user.User, error)

User retrieves a user matching the given id from the active database.

func UserResults

func UserResults(u string) []string

func Usernames

func Usernames(m interface{}) ([]string, error)

func Users

func Users(m interface{}, sort ...string) ([]*user.User, error)

Users retrieves users matching the given interface from the active database.

Types

type AddError

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

AddError represents errors encountered when adding data.

func (*AddError) Error

func (a *AddError) Error() string

Error

type FileInfo

type FileInfo struct {
	Name  string
	Count int
	Type  project.Type
}

FileInfo

func FileInfos

func FileInfos(m bson.M) ([]*FileInfo, error)

FileInfos retrieves names of file information.

func (*FileInfo) HasCharts

func (f *FileInfo) HasCharts() bool

type GetError

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

GetError represents errors encountered when retrieving data.

func (*GetError) Error

func (g *GetError) Error() string

type RemoveError

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

RemoveError represents errors encountered when removing data.

func (*RemoveError) Error

func (r *RemoveError) Error() string

Error

type TypeHolder

type TypeHolder struct {
	Type string `bson:"type"`
}

Jump to

Keyboard shortcuts

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