Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection interface {
// RegisterEntries tells the database to register the given entries
// In the case of the mongodb database this means we'll create a collection for each entry
RegisterEntries(entries ...Entry)
// FindOne finds one entry inside the database
// Returns err == mongo.ErrNoDocuments if no documents where found
FindOne(result Entry, filters bson.M, opts ...FindOptions) error
// Find finds multiple entries in the database
// The entry argument is to determain on which collection we execute the query
Find(entry Entry, results any, filters bson.M, opts ...FindOptions) error
// Insert inserts an entry into the database
Insert(data ...Entry) error
// UpdateID updates an entry in the database
UpdateByID(data Entry) error
// DeleteByID deletes an entry from the database
DeleteByID(entry Entry, ids ...primitive.ObjectID) error
// Count counts the number of documents in the database for the specific filter
// If filter is nil the number of all the documents is returned
Count(entry Entry, filter bson.M) (uint64, error)
}
Connection is a abstract interface for a database connection There are 2 main implementations of this: - MongoConnection (For the MongoDB driver) - TestConnection (For a fake temp database)
type Entry ¶
type Entry interface {
// Get the _id field of the entry
GetID() primitive.ObjectID
// Set the _id field of the entry
SetID(primitive.ObjectID)
// CollectionName should yield the collection name for the entry
CollectionName() string
// DefaultFindFilters can return a default filter used in find queries
// If nil is returned this is not used
DefaultFindFilters() bson.M
// Indexes returns the indexes for the entry
// If nil is returned no more indexes will be set
// Note that by default the there is always an index of the _id field
Indexes() []mongo.IndexModel
}
Entry are the functions required to put/get things in/from the database To implement use:
type User struct {
// Adds the _id field and implements the remaining functions from Entry
M `bson:",inline"`
Username string
}
func (*User) CollectionName() {
return "users"
}
type FindOptions ¶
type FindOptions struct {
// NoDefaultFilters does not include the default filters for the entry provided
NoDefaultFilters bool
}
FindOptions are options for the find operator in Connection
type M ¶
M is a struct that adds an _id field and implements from dbInterfaces.Entry: - GetID - SetID - DefaultFindFilters
func (*M) DefaultFindFilters ¶
DefaultFindFilters implements Entry
Click to show internal directories.
Click to hide internal directories.