Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mysql-live-select

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-live-select - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

test/fixtures/multipleQueries.js

17

lib/differ.js

@@ -12,3 +12,5 @@ /* mysql-live-select, MIT License ben@latenightsketches.com

var curHashes2 = curHashes.slice();
var addedRows = newData.map(function(row) {
var addedRows = newData.filter(function(row) {
return oldHashes.indexOf(row._hash) === -1;
}).map(function(row) {
// Prepare row meta-data

@@ -78,2 +80,7 @@ row._index = curHashes2.indexOf(row._hash) + 1;

exports.apply = function(data, diff) {
data = _.clone(data, true).map(function(row, index) {
row._index = index + 1;
return row;
});
var newResults = data.slice();

@@ -103,3 +110,9 @@

return newResults.filter(function(row) { return row !== undefined; });
var result = newResults.filter(function(row) { return row !== undefined; });
return result.map(function(row) {
row = _.clone(row);
delete row._index;
return row;
});
}

2

lib/QueryCache.js

@@ -114,3 +114,3 @@ /* mysql-live-select, MIT License ben@latenightsketches.com, wj32.64@gmail.com

if(self.needUpdate) update();
if(self.needUpdate === true) update();
});

@@ -117,0 +117,0 @@ }

{
"name": "mysql-live-select",
"version": "1.0.0",
"version": "1.0.1",
"description": "Live updating MySQL SELECT statements",

@@ -5,0 +5,0 @@ "main": "lib/LiveMysql.js",

/* mysql-live-select, MIT License ben@latenightsketches.com
test/index.js - Test Suite */
var _ = require('lodash');
var LiveMysql = require('../');

@@ -7,2 +8,3 @@ var settings = require('./settings/mysql');

var Connector = require('./helpers/connector');
var multipleQueriesData = require('./fixtures/multipleQueries');
var server = new Connector(settings);

@@ -152,6 +154,73 @@

},
pauseAndResume: function(test){
// Cases specified in test/fixtures/multipleQueries.js
multipleQueries: function(test) {
var tablePrefix = 'multiple_queries_';
// Milliseconds between each query execution
var queryWaitTime = 100;
server.on('ready', function(conn, esc, escId, queries) {
Object.keys(multipleQueriesData).forEach(function(queryName) {
var table = tablePrefix + queryName;
var tableEsc = escId(table);
var details = multipleQueriesData[queryName];
var columnDefStr = _.map(details.columns, function(typeStr, name) {
return escId(name) + ' ' + typeStr;
}).join(', ');
var columnList = Object.keys(details.columns);
var initDataStr = details.initial.map(function(rowData) {
return '(' + columnList.map(function(column) {
return esc(rowData[column]);
}).join(', ') + ')';
}).join(', ');
var replaceTable = function(query) {
return query.replace(/\$table\$/g, tableEsc);
};
querySequence(conn.db, [
'DROP TABLE IF EXISTS ' + tableEsc,
'CREATE TABLE ' + tableEsc + ' (' + columnDefStr + ')',
'INSERT INTO ' + tableEsc + ' (' + columnList.map(escId).join(', ') +
') VALUES ' + initDataStr,
], function(results) {
var actualDiffs = [];
var actualDatas = [];
var curQuery = 0;
var oldData = [];
conn.select(replaceTable(details.select), [ {
table: table,
database: server.database,
condition: details.condition
} ]).on('update', function(diff, rows) {
actualDiffs.push(diff);
actualDatas.push(LiveMysql.applyDiff(oldData, diff));
oldData = rows;
if(curQuery < details.queries.length) {
setTimeout(function() {
querySequence(conn.db,
[ replaceTable(details.queries[curQuery++]) ],
function(results){ /* do nothing with results */ });
}, queryWaitTime);
}
if(actualDiffs.length === details.expectedDiffs.length) {
test.deepEqual(actualDiffs, details.expectedDiffs,
'Diff Mismatch on ' + queryName);
if(details.expectedDatas) {
test.deepEqual(actualDatas, details.expectedDatas,
'Data Mismatch on ' + queryName);
}
test.done();
}
});
});
});
});
},
pauseAndResume: function(test) {
var waitTime = 500;
var table = 'pause_resume';
server.on('ready', function(conn, esc, escId, queries){
server.on('ready', function(conn, esc, escId, queries) {
querySequence(conn.db, [

@@ -161,3 +230,3 @@ 'DROP TABLE IF EXISTS ' + escId(table),

'INSERT INTO ' + escId(table) + ' (col) VALUES (10)',
], function(results){
], function(results) {
var pauseTime = Date.now();

@@ -164,0 +233,0 @@ conn.select('SELECT * FROM ' + escId(table), [ {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc