Created
August 9, 2015 19:51
-
-
Save gngeorgiev/baba5fad9373f6901a7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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