countersEngine.js 848 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. *
  3. *
  4. */
  5. function MySQLBackendCountersEngine() {
  6. var self = this;
  7. }
  8. /**
  9. *
  10. *
  11. */
  12. MySQLBackendCountersEngine.prototype.buildQuerries = function(userCounters, time_stamp) {
  13. var querries = [];
  14. // Iterate on each userCounter
  15. for(var userCounterName in userCounters) {
  16. var counterValue = userCounters[userCounterName];
  17. if(counterValue === 0) {
  18. continue;
  19. } else {
  20. querries.push("insert into `counters_statistics` (`timestamp`,`name`,`value`) values(" + time_stamp + ",'" + escape(userCounterName) +"'," + counterValue + ") on duplicate key update value = value + " + counterValue + ", timestamp = " + time_stamp);
  21. }
  22. }
  23. return querries;
  24. }
  25. /**
  26. *
  27. *
  28. */
  29. exports.init = function() {
  30. var instance = new MySQLBackendCountersEngine();
  31. return instance;
  32. };