A Sails chat room application that uses the sails-mysql-live-select NPM package wrapper in order to provide live (real time) result sets for models.
This example uses AngularJS as a front-end framework. The original inspiration for this example was provided by Maanga Labs' Sockets in Sails example application. Also, a tutorial is available for the original Maanga Labs socket example.
The following instructions assume that you already have Node.js installed.
# Clone the repository
git clone git://github.com/numtel/sails-mysql-live-select-chat-example.git
# Switch to new directory
cd sails-mysql-live-select-chat-example
# Install dependencies
npm install
# Update MySQL connection settings in editor
vim config/connections.js
# Lift Sails (or simply 'sails lift' if installed)
node app.js-
The
sails-mysql-live-selectadapter is configured inconfig/connections.jsin addition to thesails-mysqladapter. View Source -
Models are configured by default to use both the
mysqlandliveMysqlconnections. View Source -
A method called
liveStreamis added to theChatControllerto enable subscribing and unsubscribing from the chat message stream. TheliveFindmethod added to each model accepts two arguments: the find query options, and an optional data invalidation callback as defined in mysql-live-select. View Source -
The Angular controller performs a socket
GETrequest on initialization to/chat/liveStream. On unsubscribing, aPOSTrequest containing a parameterunsubscribeset totrueis performed to stop receiving updates. View Source -
Result set differences arrive on the client in the format provided by
mysql-live-selectand are applied to the data cache array using theapplyDifffunction copied from the server-side code for client-side usage. View Source
Unlicense