-
-
Save ondrejhlavacek/6ebe05261c4b24ca14b1ab5c65d81529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Taken and modified from | |
* http://stackoverflow.com/questions/4747808/split-mysql-queries-in-array-each-queries-separated-by/5610067#5610067 | |
*/ | |
const regex = /\s*((?:'[^'\\]*(?:\\.[^'\\]*)*'|"[^"\\]*(?:\\.[^"\\]*)*"|\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\/|#.*|--.*|[^"';#])+(?:;|$))/g; | |
const re = new RegExp(regex, 'g'); | |
self.addEventListener('message', function(e) { | |
var data = e.data; | |
if (data.queries === '') { | |
postMessage([]); | |
return; | |
} | |
const matches = data.queries.match(re); | |
const response = matches | |
.filter((line) => line.trim() !== '') | |
.map((line) => line.trim()); | |
postMessage(response); | |
}, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const maxSqlExecutionTime = 2000; | |
import Promise from 'bluebird'; | |
export default function(queries) { | |
var promise = new Promise(function(resolve, reject) { | |
// worker-loader webpack plugin | |
const worker = require('worker-loader?inline!./worker.js')(); | |
var success = false; | |
worker.onmessage = function(e) { | |
success = true; | |
resolve(e.data); | |
}; | |
worker.postMessage({ | |
queries: queries | |
}); | |
setTimeout(function() { | |
if (!success) { | |
reject(); | |
} | |
worker.terminate(); | |
}, maxSqlExecutionTime); | |
}); | |
return promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment