How to get reactive time (mysql database)?


#1

Hello,

I use Meteor with mysql and moment.
I can not seem to display the “reactive” time between the connection date and current date.

I have a published query that sends me X rows like this :
id | name | description | connection date
1 | Dave | First user | 2015-03-08 07:53:15 AM
2 | John | Second user | 2015-03-08 10:15:32 AM

I would like the client shows me the period between the date of connection and current reactive date

Connection time in minutes
Dave | 03:45
John | 02:15

Is this possible and how ?

Thanks a lot


#2

I am not aware of any call which return reactive time. I would use Meteor.setTimer to invalidate ReactiveVar variable to force helper recalculation


#3

You should calculate this on the fly within a helper. Updating it every second could prove problematic.


#4

Thanks for your answer but i’m very noob, could you post an exemple of this ?
How to calculate within a helper ?

My helper is like this :

Template.DisplayFirstTab.helpers({
calls: function () {
	return myCalls.reactive();
}
}});

And my query on the server like this :

Meteor.publish('allCallsTabOne', function(tvNumber){
  return liveDb.select(
    'SELECT calls.ShortReference, calls.StockLocation, calls.Priority, calls.CreationDate, calls.State FROM calls ' +
    'WHERE calls.State IN (0, 1) ' +
    'ORDER BY containers.Priority ASC ' +
    'LIMIT 5;',
    [ { table: 'calls' } ]
  );
});

#5

I’d like to provide an example but its better if you learn something. I’m happy to help further but here’s some pointers.

Assuming collection helpers work for mysql collections:

Users.helpers({
connectionTime: function() {
//return current app/server/client time - this.connection_date
});

I’d look at momentjs for the actual calculation perhaps using twix for ease of use


#6

You could also take a look at glasser:reactive-fromnow from one of the MDG core team.


#7

Awesome sounding package. Thanks!