Skip to content

Commit a0888ca

Browse files
committed
Merge pull request #286 from danrzeppa/dan-placeholder
Use ? for placeholder in mssql dialect
2 parents d85807f + f41c5f5 commit a0888ca

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/dialect/mssql.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
var util = require('util');
77
var assert = require('assert');
88

9+
/**
10+
* Config can contain:
11+
*
12+
* questionMarkParameterPlaceholder:true which will use a "?" for the parameter placeholder instead of the @index.
13+
*
14+
* @param config
15+
* @constructor
16+
*/
917
var Mssql = function(config) {
1018
this.output = [];
1119
this.params = [];
@@ -23,6 +31,7 @@ Mssql.prototype._quoteCharacter = '[';
2331
Mssql.prototype._arrayAggFunctionName = '';
2432

2533
Mssql.prototype._getParameterPlaceholder = function(index, value) {
34+
if (this.config.questionMarkParameterPlaceholder) return '?';
2635
return '@' + index;
2736
};
2837

test/index-tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,20 @@ suite('index', function() {
195195
});
196196
});
197197

198+
test('mssql default parameter place holder is @index', function() {
199+
var Sql = sql.Sql;
200+
var mssql = new Sql('mssql');
201+
var query = mssql.select(user.id).from(user).where(user.email.equals('[email protected]')).toQuery();
202+
assert.equal(query.text, 'SELECT [user].[id] FROM [user] WHERE ([user].[email] = @1)');
203+
assert.equal(query.values[0], '[email protected]');
204+
});
205+
206+
test('mssql override default parameter placeholder with ?', function() {
207+
var Sql = sql.Sql;
208+
var mssql = new Sql('mssql',{questionMarkParameterPlaceholder:true});
209+
var query = mssql.select(user.id).from(user).where(user.email.equals('[email protected]')).toQuery();
210+
assert.equal(query.text, 'SELECT [user].[id] FROM [user] WHERE ([user].[email] = ?)');
211+
assert.equal(query.values[0], '[email protected]');
212+
});
213+
198214
});

0 commit comments

Comments
 (0)