Skip to content

Instantly share code, notes, and snippets.

@gngeorgiev
Created August 9, 2015 19:51
Show Gist options
  • Save gngeorgiev/baba5fad9373f6901a7c to your computer and use it in GitHub Desktop.
Save gngeorgiev/baba5fad9373f6901a7c to your computer and use it in GitHub Desktop.
package realbase
import (
// "fmt"
// "gopkg.in/igm/sockjs-go.v2/sockjs"
// "net/http"
"gopkg.in/mgo.v2/bson"
)
func constructMessage(doc bson.M, operation string) bson.M {
message := make(map[string]interface{})
message["origin"] = "db"
message["data"] = doc
message["operation"] = operation
return message
}
type DbService struct {
DataStore DataStore
}
func GetDbService(connectionString, dbName, colName string) *DbService {
dataStore := DataStore{connectionString, dbName, colName}
return &DbService{dataStore}
}
func (dbService *DbService) Insert(doc bson.M) error {
err := dbService.DataStore.GetCollection().Insert(doc)
message := constructMessage(doc, "insert")
GetMessageService().BroadcastJSON(message)
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment