Documentation ¶
Index ¶
- func DeSerialize(str string, v interface{}) error
- func InitializeDatabaseConnection(dbName string) error
- func Serialize(v interface{}) (string, error)
- type Key
- type MockDB
- func (m *MockDB) Find(table string, key Key, tag string) ([][]byte, error)
- func (m *MockDB) HealthCheck() error
- func (m *MockDB) Insert(table string, key Key, query interface{}, tag string, data interface{}) error
- func (m *MockDB) Remove(table string, key Key) error
- func (m *MockDB) RemoveAll(table string, key Key) error
- func (m *MockDB) RemoveTag(table string, key Key, tag string) error
- func (m *MockDB) Unmarshal(inp []byte, out interface{}) error
- type MongoCollection
- type MongoStore
- func (m *MongoStore) Find(coll string, key Key, tag string) ([][]byte, error)
- func (m *MongoStore) HealthCheck() error
- func (m *MongoStore) Insert(coll string, key Key, query interface{}, tag string, data interface{}) error
- func (m *MongoStore) Remove(coll string, key Key) error
- func (m *MongoStore) RemoveAll(coll string, key Key) error
- func (m *MongoStore) RemoveTag(coll string, key Key, tag string) error
- func (m *MongoStore) Unmarshal(inp []byte, out interface{}) error
- type NewMockDB
- func (m *NewMockDB) Find(table string, key Key, tag string) ([][]byte, error)
- func (m *NewMockDB) HealthCheck() error
- func (m *NewMockDB) Insert(table string, key Key, query interface{}, tag string, data interface{}) error
- func (m *NewMockDB) Remove(table string, key Key) error
- func (m *NewMockDB) RemoveAll(table string, key Key) error
- func (m *NewMockDB) RemoveTag(table string, key Key, tag string) error
- func (m *NewMockDB) Unmarshal(inp []byte, out interface{}) error
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeSerialize ¶
DeSerialize converts string to a json object specified by type
func InitializeDatabaseConnection ¶
InitializeDatabaseConnection sets up the connection to the configured database to allow the application to talk to it.
Types ¶
type Key ¶
type Key interface { }
Key is an interface that will be implemented by anypackage that wants to use the Store interface. This allows various db backends and key types.
type MongoCollection ¶
type MongoCollection interface { InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error) }
MongoCollection defines the a subset of MongoDB operations Note: This interface is defined mainly for mock testing
type MongoStore ¶
type MongoStore struct {
// contains filtered or unexported fields
}
MongoStore is an implementation of the db.Store interface
func (*MongoStore) Find ¶
Find method returns the data stored for this key and for this particular tag
func (*MongoStore) HealthCheck ¶
func (m *MongoStore) HealthCheck() error
HealthCheck verifies if the database is up and running
func (*MongoStore) Insert ¶
func (m *MongoStore) Insert(coll string, key Key, query interface{}, tag string, data interface{}) error
Insert is used to insert/add element to a document
func (*MongoStore) Remove ¶
func (m *MongoStore) Remove(coll string, key Key) error
Remove method to remove the documet by key if no child references
func (*MongoStore) RemoveAll ¶
func (m *MongoStore) RemoveAll(coll string, key Key) error
RemoveAll method to removes all the documet matching key
func (*MongoStore) RemoveTag ¶
func (m *MongoStore) RemoveTag(coll string, key Key, tag string) error
RemoveTag is used to remove an element from a document
func (*MongoStore) Unmarshal ¶
func (m *MongoStore) Unmarshal(inp []byte, out interface{}) error
Unmarshal implements an unmarshaler for bson data that is produced from the mongo database
type NewMockDB ¶
func (*NewMockDB) HealthCheck ¶
type Store ¶
type Store interface { // Returns nil if db health is good HealthCheck() error // Unmarshal implements any unmarshaling needed for the database Unmarshal(inp []byte, out interface{}) error // Inserts and Updates a tag with key and also adds query fields if provided Insert(coll string, key Key, query interface{}, tag string, data interface{}) error // Find the document(s) with key and get the tag values from the document(s) Find(coll string, key Key, tag string) ([][]byte, error) // Removes the document(s) matching the key if no child reference in collection Remove(coll string, key Key) error // Remove all the document(s) matching the key RemoveAll(coll string, key Key) error // Remove the specifiec tag from the document matching the key RemoveTag(coll string, key Key, tag string) error }
Store is an interface for accessing the database
var DBconn Store
DBconn interface used to talk a concrete Database connection