Ecosyste.ms: Packages

An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 8.2% on proxy.golang.org

proxy.golang.org : github.com/ddspog/mongo

Package mongo mask the connection to MongoDB using mgo package. This is made with function Connect, that saves Session and Mongo object which will be used later from other packages. Also, I've embedded the Collection, Database and Query types, to allow mocking via interfaces. The embedded was necessary for the functions to use the interfaces as return values, that way, the code can use the original, or generate a mock of them for testing purposes. The package can be used like this: Other option of usage is through the use of mongo.DatabaseSocket: Or even through the concept of LinkedHandlers, as described later: Further usage it's the same way mgo package is used. Look into mgo docs page: https://godoc.org/github.com/globalsign/mgo The Connect function tries to connect to a MONGODB_URL environment variable, but when it's not defined, it uses a default URL: You can mock some functions of this package, by mocking the mgo called functions mgo.ParseURL and mgo.Dial. Use the MockMongoSetup presented on this package (only in test environment), like: Mongo package also contain utility functions to help modeling documents. The package contains a interface Documenter which contain getters for important attributes to any document on MongoDB: _id, created_on and updated_on. It also contains functions that generates correctly the created_on and updated_on attributes. The Documenter can be used like this: You can also mock some other functions of this package, by mocking some called functions time.Now and NewObjectId. Use the MockModelSetup presented on this package (only in test environment), like: Mongo package also enable creation of Handle, a type that connects to database collections and do some operations. The Handle were made to be imported on embedding type, and through overriding of some methods, to implement an adequate Handler for a desired type of Document. The Handle type assumes to operate on a Documenter type, that will contain information about the operation to made with Handle. The package should be used to create new types. Use the Handler type for creating embedding types. For each new type, a constructor may be needed, and for that Handler has a basic constructor. All functions were made to be overridden and rewrite. First thing to do it's creating the Link method, as it follows: The creation of Insert, Remove and RemoveAll are trivial. Call it with a Document getter function defined like: The Clean function is simple and helps a lot: The Update function uses an id as an argument: The complicated functions are Find and FindAll which requires casting for the Document type: For all functions written, verification it's advisable.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/ddspog/mongo
Keywords: embedded, go, golang, mgo, mocking, mongo, mongodb, package
License: MIT
Latest release: about 6 years ago
First release: over 6 years ago
Namespace: github.com/ddspog
Stars: 2 on GitHub
Forks: 1 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 21 days ago

    Loading...
    Readme
    Loading...