Skip to content

Commit 5d139b2

Browse files
committed
Update sqlstring to 2.3.0
1 parent f483720 commit 5d139b2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ you spot any mistakes.
1010
* Fix "changedRows" to work on non-English servers #1819
1111
* Fix typo in insecure auth error message
1212
* Support `mysql_native_password` auth switch request for Azure #1396 #1729 #1730
13+
* Update `sqlstring` to 2.3.0
14+
- Add `.toSqlString()` escape overriding
15+
- Small performance improvement on `escapeId`
1316
* Update `bignumber.js` to 4.0.4
1417

1518
## v2.14.1 (2017-08-01)

Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ Different value types are escaped differently, here is how:
707707
* Arrays are turned into list, e.g. `['a', 'b']` turns into `'a', 'b'`
708708
* Nested arrays are turned into grouped lists (for bulk inserts), e.g. `[['a',
709709
'b'], ['c', 'd']]` turns into `('a', 'b'), ('c', 'd')`
710+
* Objects that have a `toSqlString` method will have `.toSqlString()` called
711+
and the returned value is used as the raw SQL.
710712
* Objects are turned into `key = 'val'` pairs for each enumerable property on
711713
the object. If the property's value is a function, it is skipped; if the
712714
property's value is an object, toString() is called on it and the returned
@@ -725,7 +727,14 @@ var query = connection.query('INSERT INTO posts SET ?', post, function (error, r
725727
// Neat!
726728
});
727729
console.log(query.sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQL'
730+
```
731+
732+
And the `toSqlString` method allows you to form complex queries with functions:
728733

734+
```js
735+
var CURRENT_TIMESTAMP = { toSqlString: function() { return 'CURRENT_TIMESTAMP()'; } };
736+
var sql = mysql.format('UPDATE posts SET modified = ? WHERE id = ?', [CURRENT_TIMESTAMP, 42]);
737+
console.log(sql); // UPDATE posts SET modified = CURRENT_TIMESTAMP() WHERE id = 42
729738
```
730739

731740
If you feel the need to escape queries by yourself, you can also use the escaping

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"bignumber.js": "4.0.4",
1717
"readable-stream": "2.3.3",
1818
"safe-buffer": "5.1.1",
19-
"sqlstring": "2.2.0"
19+
"sqlstring": "2.3.0"
2020
},
2121
"devDependencies": {
2222
"after": "0.8.2",

0 commit comments

Comments
 (0)