Skip to content

meteor-mysql-1.7 #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# numtel:mysql [![Build Status](https://travis-ci.org/numtel/meteor-mysql.svg?branch=master)](https://travis-ci.org/numtel/meteor-mysql)
Reactive MySQL for Meteor
Reactive MySQL for Meteor <b>1.7</b>

Provides Meteor integration of the [`mysql-live-select` NPM module](https://github.com/numtel/mysql-live-select), bringing reactive `SELECT` statement result sets from MySQL >= 5.1.15.

Expand Down
5 changes: 5 additions & 0 deletions lib/LiveMysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var Future = Npm.require('fibers/future');

LiveMysql = Npm.require('mysql-live-select');

import _ from "lodash";


// Convert the LiveMysqlSelect object into a cursor
LiveMysql.LiveMysqlSelect.prototype._publishCursor = function(sub) {
var self = this;
Expand Down Expand Up @@ -71,3 +74,5 @@ LiveMysql.LiveMysqlSelect.prototype.fetch = function() {

return dataWithIds;
}

module.exports = LiveMysql;
24 changes: 19 additions & 5 deletions lib/MysqlSubscription.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// numtel:mysql
// MIT License, [email protected]
// lib/MysqlSubscription.js
import { Tracker } from 'meteor/tracker';
import _ from "lodash";

var selfConnection;
var buffer = [];



MysqlSubscription = function(connection, name /* arguments */){
var self = this;
var subscribeArgs;
Expand All @@ -20,6 +24,7 @@ MysqlSubscription = function(connection, name /* arguments */){
subscribeArgs = Array.prototype.slice.call(arguments, 0);
name = connection;
if(Meteor.isClient){

connection = Meteor.connection;
}else if(Meteor.isServer){
if(!selfConnection){
Expand All @@ -32,7 +37,9 @@ MysqlSubscription = function(connection, name /* arguments */){
subscribeArgs = Array.prototype.slice.call(arguments, 1);
}

Tracker.Dependency.call(self);
var _tracker = Tracker.Dependency.bind(self);
Object.assign(self, new _tracker());

// Y U No give me subscriptionId, Meteor?!
var subsBefore = _.keys(connection._subscriptions);
_.extend(self, connection.subscribe.apply(connection, subscribeArgs));
Expand All @@ -54,6 +61,7 @@ MysqlSubscription = function(connection, name /* arguments */){
}).length === 1){
connection.registerStore(name, {
update: function(msg){

var subBuffers = _.filter(buffer, function(sub){
return sub.subscriptionId === msg.id;
});
Expand All @@ -71,6 +79,7 @@ MysqlSubscription = function(connection, name /* arguments */){
msg.fields && msg.fields.reset === true){
// This message indicates a reset of a result set
if(subBuffer.resetOnDiff === false){

sub.dispatchEvent('reset', msg);
sub.splice(0, sub.length);
}
Expand All @@ -94,17 +103,21 @@ MysqlSubscription = function(connection, name /* arguments */){

// Emit event for application
sub.dispatchEvent('update', msg.fields.diff, sub);
}
sub.changed();

}
sub.changed(msg, newData);
}
});
}

};

// Inherit from Array and Tracker.Dependency
MysqlSubscription.prototype = new Array;
_.extend(MysqlSubscription.prototype, Tracker.Dependency.prototype);
MysqlSubscription.prototype = [];
//_.extend(MysqlSubscription.prototype, Tracker.Dependency.prototype);
MysqlSubscription.prototype.depend = Tracker.Dependency.prototype.depend; //Seems like the only dependency.



/*
* Change the arguments for the subscription. Publication name and connection
Expand Down Expand Up @@ -236,3 +249,4 @@ function applyDiff(data, diff) {
});
}

module.exports = MysqlSubscription;