Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Don't parse/stringify default configs every time (Performance improvement) #382

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 40 additions & 44 deletions dist/squel-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,41 +190,43 @@ function _buildSquel() {
};

// default query builder options
cls.DefaultQueryBuilderOptions = {
// If true then table names will be rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteTableNames: false,
// If true then field names will rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteFieldNames: false,
// If true then alias names will rendered inside quotes. The quote character used is configurable via the `tableAliasQuoteCharacter` and `fieldAliasQuoteCharacter` options.
autoQuoteAliasNames: true,
// If true then table alias names will rendered after AS keyword.
useAsForTableAliasNames: false,
// The quote character used for when quoting table and field names
nameQuoteCharacter: '`',
// The quote character used for when quoting table alias names
tableAliasQuoteCharacter: '`',
// The quote character used for when quoting table alias names
fieldAliasQuoteCharacter: '"',
// Custom value handlers where key is the value type and the value is the handler function
valueHandlers: [],
// Character used to represent a parameter value
parameterCharacter: '?',
// Numbered parameters returned from toParam() as $1, $2, etc.
numberedParameters: false,
// Numbered parameters prefix character(s)
numberedParametersPrefix: '$',
// Numbered parameters start at this number.
numberedParametersStartAt: 1,
// If true then replaces all single quotes within strings. The replacement string used is configurable via the `singleQuoteReplacement` option.
replaceSingleQuotes: false,
// The string to replace single quotes with in query strings
singleQuoteReplacement: '\'\'',
// String used to join individual blocks in a query when it's stringified
separator: ' ',
// Function for formatting string values prior to insertion into query string
stringFormatter: null,
// Whether to prevent the addition of brackets () when nesting this query builder's output
rawNesting: false
cls.getDefaultQueryBuilderOptions = function () {
return {
// If true then table names will be rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteTableNames: false,
// If true then field names will rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteFieldNames: false,
// If true then alias names will rendered inside quotes. The quote character used is configurable via the `tableAliasQuoteCharacter` and `fieldAliasQuoteCharacter` options.
autoQuoteAliasNames: true,
// If true then table alias names will rendered after AS keyword.
useAsForTableAliasNames: false,
// The quote character used for when quoting table and field names
nameQuoteCharacter: '`',
// The quote character used for when quoting table alias names
tableAliasQuoteCharacter: '`',
// The quote character used for when quoting table alias names
fieldAliasQuoteCharacter: '"',
// Custom value handlers where key is the value type and the value is the handler function
valueHandlers: [],
// Character used to represent a parameter value
parameterCharacter: '?',
// Numbered parameters returned from toParam() as $1, $2, etc.
numberedParameters: false,
// Numbered parameters prefix character(s)
numberedParametersPrefix: '$',
// Numbered parameters start at this number.
numberedParametersStartAt: 1,
// If true then replaces all single quotes within strings. The replacement string used is configurable via the `singleQuoteReplacement` option.
replaceSingleQuotes: false,
// The string to replace single quotes with in query strings
singleQuoteReplacement: '\'\'',
// String used to join individual blocks in a query when it's stringified
separator: ' ',
// Function for formatting string values prior to insertion into query string
stringFormatter: null,
// Whether to prevent the addition of brackets () when nesting this query builder's output
rawNesting: false
};
};

// Global custom value handlers for all instances of builder
Expand Down Expand Up @@ -286,13 +288,7 @@ function _buildSquel() {

var _this = _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).call(this));

var defaults = JSON.parse(JSON.stringify(cls.DefaultQueryBuilderOptions));
// for function values, etc we need to manually copy
['stringFormatter'].forEach(function (p) {
defaults[p] = cls.DefaultQueryBuilderOptions[p];
});

_this.options = _extend({}, defaults, options);
_this.options = _extend({}, cls.getDefaultQueryBuilderOptions(), options);
return _this;
}

Expand Down Expand Up @@ -985,7 +981,7 @@ function _buildSquel() {
_this5._fieldName = _this5._sanitizeField(fieldName);
}

_this5.options = _extend({}, cls.DefaultQueryBuilderOptions, options);
_this5.options = _extend({}, cls.getDefaultQueryBuilderOptions(), options);

_this5._cases = [];
_this5._elseValue = null;
Expand Down Expand Up @@ -2976,7 +2972,7 @@ function _buildSquel() {
}(cls.QueryBuilder);

var _squel = {
VERSION: '5.12.2',
VERSION: '5.13.0',
flavour: flavour,
expr: function expr(options) {
return new cls.Expression(options);
Expand Down
4 changes: 2 additions & 2 deletions dist/squel-basic.min.js

Large diffs are not rendered by default.

167 changes: 116 additions & 51 deletions dist/squel.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,41 +190,43 @@ function _buildSquel() {
};

// default query builder options
cls.DefaultQueryBuilderOptions = {
// If true then table names will be rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteTableNames: false,
// If true then field names will rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteFieldNames: false,
// If true then alias names will rendered inside quotes. The quote character used is configurable via the `tableAliasQuoteCharacter` and `fieldAliasQuoteCharacter` options.
autoQuoteAliasNames: true,
// If true then table alias names will rendered after AS keyword.
useAsForTableAliasNames: false,
// The quote character used for when quoting table and field names
nameQuoteCharacter: '`',
// The quote character used for when quoting table alias names
tableAliasQuoteCharacter: '`',
// The quote character used for when quoting table alias names
fieldAliasQuoteCharacter: '"',
// Custom value handlers where key is the value type and the value is the handler function
valueHandlers: [],
// Character used to represent a parameter value
parameterCharacter: '?',
// Numbered parameters returned from toParam() as $1, $2, etc.
numberedParameters: false,
// Numbered parameters prefix character(s)
numberedParametersPrefix: '$',
// Numbered parameters start at this number.
numberedParametersStartAt: 1,
// If true then replaces all single quotes within strings. The replacement string used is configurable via the `singleQuoteReplacement` option.
replaceSingleQuotes: false,
// The string to replace single quotes with in query strings
singleQuoteReplacement: '\'\'',
// String used to join individual blocks in a query when it's stringified
separator: ' ',
// Function for formatting string values prior to insertion into query string
stringFormatter: null,
// Whether to prevent the addition of brackets () when nesting this query builder's output
rawNesting: false
cls.getDefaultQueryBuilderOptions = function () {
return {
// If true then table names will be rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteTableNames: false,
// If true then field names will rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteFieldNames: false,
// If true then alias names will rendered inside quotes. The quote character used is configurable via the `tableAliasQuoteCharacter` and `fieldAliasQuoteCharacter` options.
autoQuoteAliasNames: true,
// If true then table alias names will rendered after AS keyword.
useAsForTableAliasNames: false,
// The quote character used for when quoting table and field names
nameQuoteCharacter: '`',
// The quote character used for when quoting table alias names
tableAliasQuoteCharacter: '`',
// The quote character used for when quoting table alias names
fieldAliasQuoteCharacter: '"',
// Custom value handlers where key is the value type and the value is the handler function
valueHandlers: [],
// Character used to represent a parameter value
parameterCharacter: '?',
// Numbered parameters returned from toParam() as $1, $2, etc.
numberedParameters: false,
// Numbered parameters prefix character(s)
numberedParametersPrefix: '$',
// Numbered parameters start at this number.
numberedParametersStartAt: 1,
// If true then replaces all single quotes within strings. The replacement string used is configurable via the `singleQuoteReplacement` option.
replaceSingleQuotes: false,
// The string to replace single quotes with in query strings
singleQuoteReplacement: '\'\'',
// String used to join individual blocks in a query when it's stringified
separator: ' ',
// Function for formatting string values prior to insertion into query string
stringFormatter: null,
// Whether to prevent the addition of brackets () when nesting this query builder's output
rawNesting: false
};
};

// Global custom value handlers for all instances of builder
Expand Down Expand Up @@ -286,13 +288,7 @@ function _buildSquel() {

var _this = _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).call(this));

var defaults = JSON.parse(JSON.stringify(cls.DefaultQueryBuilderOptions));
// for function values, etc we need to manually copy
['stringFormatter'].forEach(function (p) {
defaults[p] = cls.DefaultQueryBuilderOptions[p];
});

_this.options = _extend({}, defaults, options);
_this.options = _extend({}, cls.getDefaultQueryBuilderOptions(), options);
return _this;
}

Expand Down Expand Up @@ -985,7 +981,7 @@ function _buildSquel() {
_this5._fieldName = _this5._sanitizeField(fieldName);
}

_this5.options = _extend({}, cls.DefaultQueryBuilderOptions, options);
_this5.options = _extend({}, cls.getDefaultQueryBuilderOptions(), options);

_this5._cases = [];
_this5._elseValue = null;
Expand Down Expand Up @@ -2976,7 +2972,7 @@ function _buildSquel() {
}(cls.QueryBuilder);

var _squel = {
VERSION: '5.12.2',
VERSION: '5.13.0',
flavour: flavour,
expr: function expr(options) {
return new cls.Expression(options);
Expand Down Expand Up @@ -3067,9 +3063,44 @@ squel.useFlavour = function () {
squel.flavours['mssql'] = function (_squel) {
var cls = _squel.cls;

cls.DefaultQueryBuilderOptions.replaceSingleQuotes = true;
cls.DefaultQueryBuilderOptions.autoQuoteAliasNames = false;
cls.DefaultQueryBuilderOptions.numberedParametersPrefix = '@';
cls.getDefaultQueryBuilderOptions = function () {
return {
// If true then table names will be rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteTableNames: false,
// If true then field names will rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteFieldNames: false,
// If true then alias names will rendered inside quotes. The quote character used is configurable via the `tableAliasQuoteCharacter` and `fieldAliasQuoteCharacter` options.
autoQuoteAliasNames: false,
// If true then table alias names will rendered after AS keyword.
useAsForTableAliasNames: false,
// The quote character used for when quoting table and field names
nameQuoteCharacter: '`',
// The quote character used for when quoting table alias names
tableAliasQuoteCharacter: '`',
// The quote character used for when quoting table alias names
fieldAliasQuoteCharacter: '"',
// Custom value handlers where key is the value type and the value is the handler function
valueHandlers: [],
// Character used to represent a parameter value
parameterCharacter: '?',
// Numbered parameters returned from toParam() as $1, $2, etc.
numberedParameters: false,
// Numbered parameters prefix character(s)
numberedParametersPrefix: '@',
// Numbered parameters start at this number.
numberedParametersStartAt: 1,
// If true then replaces all single quotes within strings. The replacement string used is configurable via the `singleQuoteReplacement` option.
replaceSingleQuotes: true,
// The string to replace single quotes with in query strings
singleQuoteReplacement: '\'\'',
// String used to join individual blocks in a query when it's stringified
separator: ' ',
// Function for formatting string values prior to insertion into query string
stringFormatter: null,
// Whether to prevent the addition of brackets () when nesting this query builder's output
rawNesting: false
};
};

_squel.registerValueHandler(Date, function (date) {
return '\'' + date.getUTCFullYear() + '-' + (date.getUTCMonth() + 1) + '-' + date.getUTCDate() + ' ' + date.getUTCHours() + ':' + date.getUTCMinutes() + ':' + date.getUTCSeconds() + '\'';
Expand Down Expand Up @@ -3593,10 +3624,44 @@ squel.flavours['mysql'] = function (_squel) {
squel.flavours['postgres'] = function (_squel) {
var cls = _squel.cls;

cls.DefaultQueryBuilderOptions.numberedParameters = true;
cls.DefaultQueryBuilderOptions.numberedParametersStartAt = 1;
cls.DefaultQueryBuilderOptions.autoQuoteAliasNames = false;
cls.DefaultQueryBuilderOptions.useAsForTableAliasNames = true;
cls.getDefaultQueryBuilderOptions = function () {
return {
// If true then table names will be rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteTableNames: false,
// If true then field names will rendered inside quotes. The quote character used is configurable via the nameQuoteCharacter option.
autoQuoteFieldNames: false,
// If true then alias names will rendered inside quotes. The quote character used is configurable via the `tableAliasQuoteCharacter` and `fieldAliasQuoteCharacter` options.
autoQuoteAliasNames: false,
// If true then table alias names will rendered after AS keyword.
useAsForTableAliasNames: true,
// The quote character used for when quoting table and field names
nameQuoteCharacter: '`',
// The quote character used for when quoting table alias names
tableAliasQuoteCharacter: '`',
// The quote character used for when quoting table alias names
fieldAliasQuoteCharacter: '"',
// Custom value handlers where key is the value type and the value is the handler function
valueHandlers: [],
// Character used to represent a parameter value
parameterCharacter: '?',
// Numbered parameters returned from toParam() as $1, $2, etc.
numberedParameters: true,
// Numbered parameters prefix character(s)
numberedParametersPrefix: '$',
// Numbered parameters start at this number.
numberedParametersStartAt: 1,
// If true then replaces all single quotes within strings. The replacement string used is configurable via the `singleQuoteReplacement` option.
replaceSingleQuotes: false,
// The string to replace single quotes with in query strings
singleQuoteReplacement: '\'\'',
// String used to join individual blocks in a query when it's stringified
separator: ' ',
// Function for formatting string values prior to insertion into query string
stringFormatter: null,
// Whether to prevent the addition of brackets () when nesting this query builder's output
rawNesting: false
};
};

cls.PostgresOnConflictKeyUpdateBlock = function (_cls$AbstractSetField4) {
_inherits(_class49, _cls$AbstractSetField4);
Expand Down
4 changes: 2 additions & 2 deletions dist/squel.min.js

Large diffs are not rendered by default.

Loading