mysql-live-select
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -21,2 +21,3 @@ /* mysql-live-select, MIT License ben@latenightsketches.com | ||
self.data = []; | ||
self.initialized = false; | ||
@@ -121,4 +122,10 @@ if(self.query in base._resultsBuffer){ | ||
} | ||
}else if(self.initialized === false){ | ||
// If the result set initializes to 0 rows, it still needs to output an | ||
// update event. | ||
self.emit('update', rows); | ||
} | ||
self.initialized = true; | ||
self.lastUpdate = Date.now(); | ||
@@ -125,0 +132,0 @@ }; |
{ | ||
"name": "mysql-live-select", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "Live updating MySQL SELECT statements", | ||
@@ -5,0 +5,0 @@ "main": "lib/LiveMysql.js", |
@@ -143,2 +143,31 @@ /* mysql-live-select, MIT License ben@latenightsketches.com | ||
}, | ||
emptyResults: function(test){ | ||
var waitTime = 500; | ||
var table = 'empty_results'; | ||
server.on('ready', function(conn, esc, escId, queries){ | ||
querySequence(conn.db, [ | ||
'DROP TABLE IF EXISTS ' + escId(table), | ||
'CREATE TABLE ' + escId(table) + ' (col INT UNSIGNED)', | ||
], function(results){ | ||
var pauseTime = Date.now(); | ||
conn.select('SELECT * FROM ' + escId(table), [ { | ||
table: table, | ||
database: server.database | ||
} ]).on('update', function(rows){ | ||
if(rows.length === 0) { | ||
// Initialized with no rows, so add one | ||
querySequence(conn.db, [ | ||
'INSERT INTO ' + escId(table) + ' (col) VALUES (10)' | ||
], function(results){ | ||
// ... | ||
}); | ||
}else if(rows.length > 0 && rows[0].col === 10){ | ||
// Row was added, all done | ||
test.done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, | ||
pauseAndResume: function(test){ | ||
@@ -145,0 +174,0 @@ var waitTime = 500; |
35897
656