From 05f7aa19f5f2aef043976047b503369192e439be Mon Sep 17 00:00:00 2001 From: Mark Voorberg Date: Sun, 31 Mar 2019 09:30:11 -0700 Subject: [PATCH] removing sql-string --- lib/index.js | 2 +- lib/sql-string.js | 106 ------------------------------------------ lib/ts-helper.js | 4 +- test/generate.test.js | 3 -- 4 files changed, 2 insertions(+), 113 deletions(-) delete mode 100644 lib/sql-string.js diff --git a/lib/index.js b/lib/index.js index fbe67919..da5ecfdc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,7 +5,7 @@ var path = require('path'); var mkdirp = require('mkdirp'); var dialects = require('./dialects'); var _ = require('lodash'); -var SqlString = require('./sql-string'); +var SqlString = require('../node_modules/sequelize/lib/sql-string'); var tsHelper = require('./ts-helper'); var CLIEngine = require('eslint').CLIEngine; diff --git a/lib/sql-string.js b/lib/sql-string.js deleted file mode 100644 index 367e276c..00000000 --- a/lib/sql-string.js +++ /dev/null @@ -1,106 +0,0 @@ - -// https://github.com/sequelize/sequelize/blob/master/lib/sql-string.js -'use strict'; - -/* jshint -W110 */ -var dataTypes = require('sequelize').DataTypes; -var _ = require('sequelize').Utils._; - -function escape(val, timeZone, dialect, format) { - var prependN = false; - if (val === undefined || val === null) { - return 'NULL'; - } - switch (typeof val) { - case 'boolean': - // SQLite doesn't have true/false support. MySQL aliases true/false to 1/0 - // for us. Postgres actually has a boolean type with true/false literals, - // but sequelize doesn't use it yet. - if (dialect === 'sqlite' || dialect === 'mssql') { - return +!!val; - } - return '' + !!val; - case 'number': - return val + ''; - case 'string': - // In mssql, prepend N to all quoted vals which are originally a string (for - // unicode compatibility) - prependN = dialect === 'mssql'; - break; - } - - if (val instanceof Date) { - val = dataTypes[dialect].DATE.prototype.stringify(val, { timezone: timeZone }); - } - - if (Buffer.isBuffer(val)) { - if (dataTypes[dialect].BLOB) { - return dataTypes[dialect].BLOB.prototype.stringify(val); - } - - return dataTypes.BLOB.prototype.stringify(val); - } - - if (Array.isArray(val)) { - var partialEscape = _.partial(escape, _, timeZone, dialect, format); - if (dialect === 'postgres' && !format) { - return dataTypes.ARRAY.prototype.stringify(val, {escape: escape}); - } - return val.map(partialEscape); - } - - if (!val.replace) { - throw new Error('Invalid value ' + val); - } - - if (dialect === 'postgres' || dialect === 'sqlite' || dialect === 'mssql') { - // http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS - // http://stackoverflow.com/q/603572/130598 - val = val.replace(/'/g, "''"); - } else { - val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) { - switch (s) { - case '\0': return '\\0'; - case '\n': return '\\n'; - case '\r': return '\\r'; - case '\b': return '\\b'; - case '\t': return '\\t'; - case '\x1a': return '\\Z'; - default: return '\\' + s; - } - }); - } - return (prependN ? "N'" : "'") + val + "'"; -} -exports.escape = escape; - -function format(sql, values, timeZone, dialect) { - values = [].concat(values); - - if (typeof sql !== 'string') { - throw new Error('Invalid SQL string provided: ' + sql); - } - return sql.replace(/\?/g, function(match) { - if (!values.length) { - return match; - } - - return escape(values.shift(), timeZone, dialect, true); - }); -} -exports.format = format; - -function formatNamedParameters(sql, values, timeZone, dialect) { - return sql.replace(/\:+(?!\d)(\w+)/g, function(value, key) { - if ('postgres' === dialect && '::' === value.slice(0, 2)) { - return value; - } - - if (values[key] !== undefined) { - return escape(values[key], timeZone, dialect, true); - } else { - throw new Error('Named parameter "' + value + '" has no value in the given object.'); - } - }); -} -exports.formatNamedParameters = formatNamedParameters; diff --git a/lib/ts-helper.js b/lib/ts-helper.js index 69d2cc32..4177e192 100644 --- a/lib/ts-helper.js +++ b/lib/ts-helper.js @@ -1,8 +1,6 @@ // put in seperate file to keep main sequelize-auto clean 'use strict'; - -var Sequelize = require('sequelize'); -var _ = Sequelize.Utils._; +const _ = require('lodash'); function getModelFileStart(indentation, spaces, tableName) { var fileStart = "/* jshint indent: " + indentation + " */\n"; diff --git a/test/generate.test.js b/test/generate.test.js index 5c038c15..8ed830b4 100644 --- a/test/generate.test.js +++ b/test/generate.test.js @@ -99,7 +99,6 @@ describe(helpers.getTestDialectTeaser('sequelize-auto'), function() { describe('should be able to generate', function() { it('the model files.', function(done) { this.timeout(10000); // failing on Node 8 + 10 at 2000. - console.log('A------------'); try { const self = this; const db = self.sequelize.config.database; @@ -150,14 +149,12 @@ describe(helpers.getTestDialectTeaser('sequelize-auto'), function() { debug('mysql queryPos:', queryPos, 'query:', query); expect(queryPos).to.be.at.above(-1); }); - debug('***'); } } catch (err) { console.log("Error checking stdout:", err); throw err; } done(); - console.log('B------------'); }); } catch (err) { console.log("Ack:", err);