Documentation ¶
Overview ¶
Internal package for handling database methods by listening for changes and dispatching updates to clients with the internal websocket package.
This package is used in the following way:
- Create a new DB type with Connect().
- Listen for changes with Listen().
- Disconnect from the database with Disconnect().
No need to call these methods exclusively, they are automatically called and are executed synchronously in the socketeer.go file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateEvent ¶
type CreateEvent struct { OperationType string `bson:"operationType"` FullDocument bson.M `bson:"fullDocument"` }
CreateEvent is a struct for handling mongo create events from the database.
- OperationType is the type of operation, which is always "insert".
- FullDocument is a struct for handling the full document.
type DB ¶
DB is an interface for handling database methods.
- Client is a mongo client.
- DB is a mongo database.
- Coll is a mongo collection.
func Connect ¶
Connect returns a new DB type by connecting to the database with the uri, database name, and collection name provided.
This method is utilized to create a new DB type and is called internally when the socketeer is started.
Parameters: ¶
- uriString (string): the uri string to connect to the database, example: mongodb://localhost:27017
- dbName (string): the name of the database to connect to, example: mydb
- collName (string): the name of the collection to connect to, example: mycollection
Example: ¶
db.Connect("mongodb://localhost:27017", "mydb", "mycollection")
func (*DB) Disconnect ¶
Disconnect ends the connection to the database.
This method is called internally when the socketeer is stopped.
Example: ¶
db.Disconnect()
func (*DB) Listen ¶
Listen listens for changes in the database by the mongo watch & changeStream methods and dispatches updates to clients with the internal websocket package.
This method is called internally when the socketeer is started.
Parameters: ¶
- ws (WebSocket): the WebSocket type to dispatch updates to.
- keys ([]string): the keys in the documents of the collection to listen for changes on.
Example: ¶
db.Listen(ws, []string{"displayName", "email"})
type UpdateEvent ¶
type UpdateEvent struct { OperationType string `bson:"operationType"` UpdateDescription struct { UpdatedFields bson.M `bson:"updatedFields"` } `bson:"updateDescription"` }
UpdateEvent is a struct for handling mongo update events from the database.
- OperationType is the type of operation, which is always "update".
- UpdateDescription is a struct for handling the updated fields.