Documentation ¶
Index ¶
- func DeSerialize(str string, v interface{}) error
- func InitializeDatabaseConnection(ctx context.Context, dbName string) error
- func Serialize(v interface{}) (string, error)
- type DbInfo
- type DbSchema
- type DbSchemaKey
- type Key
- type MockDB
- func (m *MockDB) Find(ctx context.Context, table string, key Key, tag string) ([][]byte, error)
- func (m *MockDB) HealthCheck(ctx context.Context) error
- func (m *MockDB) Insert(ctx context.Context, table string, key Key, query interface{}, tag string, ...) error
- func (m *MockDB) Remove(ctx context.Context, table string, key Key) error
- func (m *MockDB) RemoveAll(ctx context.Context, table string, key Key) error
- func (m *MockDB) RemoveTag(ctx context.Context, table string, key Key, tag string) error
- func (m *MockDB) Unmarshal(inp []byte, out interface{}) error
- type MockMongoStore
- type MongoCollection
- type MongoStore
- func (m *MongoStore) Find(ctx context.Context, coll string, key Key, tag string) ([][]byte, error)
- func (m *MongoStore) HealthCheck(ctx context.Context) error
- func (m *MongoStore) Insert(ctx context.Context, coll string, key Key, query interface{}, tag string, ...) error
- func (m *MongoStore) ReadRefSchema(ctx context.Context)
- func (m *MongoStore) Remove(ctx context.Context, coll string, key Key) error
- func (m *MongoStore) RemoveAll(ctx context.Context, coll string, key Key) error
- func (m *MongoStore) RemoveTag(ctx context.Context, coll string, key Key, tag string) error
- func (m *MongoStore) Unmarshal(inp []byte, out interface{}) error
- type NewMockDB
- func (m *NewMockDB) Find(ctx context.Context, table string, key Key, tag string) ([][]byte, error)
- func (m *NewMockDB) HealthCheck(ctx context.Context) error
- func (m *NewMockDB) Insert(ctx context.Context, table string, key Key, query interface{}, tag string, ...) error
- func (m *NewMockDB) Remove(ctx context.Context, table string, key Key) error
- func (m *NewMockDB) RemoveAll(ctx context.Context, table string, key Key) error
- func (m *NewMockDB) RemoveTag(ctx context.Context, table string, key Key, tag string) error
- func (m *NewMockDB) Unmarshal(inp []byte, out interface{}) error
- type ReferenceEntry
- type ReferenceSchema
- type ReferentialSchema
- type ResourceSchema
- 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 DbInfo ¶
type DbInfo struct { StoreName string // name of the db collection to use for client documents TagMeta string // attribute key name for the json data of a client document TagState string // attribute key name for the resource state }
DbInfo holds the DB collection and attributes info
type DbSchema ¶
type DbSchema struct { Name string `json:"name"` Resources []ResourceSchema `json:"resources"` SegmentId string }
DbSchema is the top level structure for the referential schema.
type DbSchemaKey ¶
type DbSchemaKey struct {
SegmentId string
}
func (DbSchemaKey) String ¶
func (key DbSchemaKey) String() string
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 MockDB ¶
type MockMongoStore ¶
type MockMongoStore struct {
// contains filtered or unexported fields
}
func (*MockMongoStore) ReadRefSchema ¶
func (m *MockMongoStore) ReadRefSchema(ctx context.Context) error
ReadRefSchema reads the Referential Schema Segment file and creates the refSchemaMap.
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(ctx context.Context) error
HealthCheck verifies if the database is up and running
func (*MongoStore) Insert ¶
func (m *MongoStore) Insert(ctx context.Context, coll string, key Key, query interface{}, tag string, data interface{}) error
Insert is used to insert/add element to a document
func (*MongoStore) ReadRefSchema ¶
func (m *MongoStore) ReadRefSchema(ctx context.Context)
ReadRefSchema reads the Referential Schema Segment file and creates the refSchemaMap.
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 ¶
type ReferenceEntry ¶
type ReferenceSchema ¶
type ReferenceSchema struct { Name string `yaml:"name"` Type string `yaml:"type"` // can be not present or "map" or "many" CommonKey string `yaml:"commonKey"` // optional to disambiguate - part of reference key that is common Map string `yaml:"map"` // if Type is "map", this is JSON tag of the Map object FixedKv map[string]string `yaml:"fixedKv"` // Key/Values of referenced resource that are known at compile time FilterKeys []string `yaml:"filterKeys"` // if "map" type, list of keys to filter (not count as references) }
ReferenceSchema defines the structure of a reference entry in the referential schema.
type ReferentialSchema ¶
type ReferentialSchema struct {
// contains filtered or unexported fields
}
ReferentialSchema defines the structure that will be prepared for each element of the referential schema map.
type ResourceSchema ¶
type ResourceSchema struct { Name string `yaml:"name"` Parent string `yaml:"parent"` References []ReferenceSchema `yaml:"references"` // if present, overrides default resource id }
ResourceSchema defines the structure of a data resource in the referential schema.
type Store ¶
type Store interface { // Returns nil if db health is good HealthCheck(ctx context.Context) error // Unmarshal implements any unmarshalling 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(ctx context.Context, 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(ctx context.Context, coll string, key Key, tag string) ([][]byte, error) // Removes the document(s) matching the key if no child reference in collection Remove(ctx context.Context, coll string, key Key) error // Remove all the document(s) matching the key RemoveAll(ctx context.Context, coll string, key Key) error // Remove the specifiec tag from the document matching the key RemoveTag(ctx context.Context, 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