mysql-live-select
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -19,2 +19,9 @@ /* mysql-live-select, MIT License ben@latenightsketches.com | ||
self.zongjiSettings = { | ||
serverId: settings.serverId, | ||
startAtEnd: true, | ||
includeEvents: [ 'tablemap', 'writerows', 'updaterows', 'deleterows' ], | ||
includeSchema: {} | ||
}; | ||
db.connect(); | ||
@@ -55,7 +62,3 @@ | ||
zongji.start({ | ||
serverId: settings.serverId, | ||
startAtEnd: true, | ||
includeEvents: [ 'tablemap', 'writerows', 'updaterows', 'deleterows' ] | ||
}); | ||
zongji.start(self.zongjiSettings); | ||
} | ||
@@ -65,2 +68,22 @@ | ||
var self = this; | ||
if(!(triggers instanceof Array) || | ||
triggers.length === 0) | ||
throw new Error('triggers array required'); | ||
var includeSchema = self.zongjiSettings.includeSchema; | ||
for(var i = 0; i < triggers.length; i++){ | ||
var triggerDatabase = triggers[i].database || self.settings.database; | ||
if(triggerDatabase === undefined){ | ||
throw new Error('no database selected on trigger'); | ||
} | ||
if(!(triggerDatabase in includeSchema)){ | ||
includeSchema[triggerDatabase] = [ triggers[i].table ]; | ||
}else if(includeSchema[triggerDatabase].indexOf(triggers[i].table) === -1){ | ||
includeSchema[triggerDatabase].push(triggers[i].table); | ||
} | ||
} | ||
self.zongji.set(self.zongjiSettings); | ||
var newSelect = new LiveMysqlSelect(query, triggers, this); | ||
@@ -67,0 +90,0 @@ self._select.push(newSelect); |
{ | ||
"name": "mysql-live-select", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Live updating MySQL SELECT statements", | ||
@@ -5,0 +5,0 @@ "main": "lib/LiveMysql.js", |
@@ -117,2 +117,21 @@ /* mysql-live-select, MIT License ben@latenightsketches.com | ||
error_no_db_selected: function(test){ | ||
server.on('ready', function(conn, esc, escId, queries){ | ||
test.throws(function(){ | ||
conn.select('SELECT 1+1', [ { table: 'fake_table' } ]); | ||
}, /no database selected on trigger/); | ||
test.throws(function(){ | ||
conn.select('SELECT 1+1'); | ||
}, /triggers array required/); | ||
test.throws(function(){ | ||
conn.select('SELECT 1+1', []); | ||
}, /triggers array required/); | ||
test.done(); | ||
}); | ||
}, | ||
error_invalid_query: function(test){ | ||
var table = 'error_no_db'; | ||
@@ -126,16 +145,10 @@ server.on('ready', function(conn, esc, escId, queries){ | ||
conn.select('SELECT * FROM ' + escId(table), [ { | ||
table: table | ||
conn.select('SELECT notcol FROM ' + escId(table), [ { | ||
table: table, | ||
database: server.database | ||
} ]).on('error', function(error){ | ||
test.equal(error.toString(), | ||
'Error: no database selected on trigger'); | ||
test.ok(error.toString().match(/ER_BAD_FIELD_ERROR/)); | ||
test.done(); | ||
}); | ||
querySequence(conn.db, [ | ||
'UPDATE ' + escId(table) + | ||
' SET `col` = 15' | ||
], function(results){ | ||
// ... | ||
}); | ||
}); | ||
@@ -142,0 +155,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74475
1814