Skip to content

Commit bfd3ce5

Browse files
committed
trying to cleanup the readme changes
2 parents 9e54839 + f924d91 commit bfd3ce5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ A good way to handle such unexpected disconnects is shown below:
363363
```js
364364
var db_config = {
365365
host: 'localhost',
366+
<<<<<<< HEAD
366367
user: 'root',
368+
=======
369+
user: 'root',
370+
>>>>>>> f924d913fc53cbc7d19d9b7199517acbb0827b95
367371
password: '',
368372
database: 'example'
369373
};
@@ -498,6 +502,18 @@ connection.query('SELECT * FROM ?? WHERE id = ?', ['users', userId], function(er
498502

499503
When you pass an Object to `.escape()` or `.query()`, `.escapeId()` is used to avoid SQL injection in object keys.
500504

505+
### Preparing Queries
506+
507+
You can use mysql.format to prepare a query with multiple insertion points, utilizing the proper escaping for ids and values. A simple example of this follows:
508+
509+
```js
510+
var sql = "SELECT * FROM ?? WHERE ?? = ?";
511+
var inserts = ['users', 'id', userId];
512+
sql = mysql.format(sql, inserts);
513+
```
514+
515+
Following this you then have a valid, escaped query that you can then send to the database safely. This is useful if you are looking to prepare the query before actually sending it to the database. As mysql.format is exposed from SqlString.format you also have the option (but are not required) to pass in stringifyObject and timezone, allowing you provide a custom means of turning objects into strings, as well as a location-specific/timezone-aware Date.
516+
501517
### Custom format
502518

503519
If you prefer to have another type of query escape format, there's a connection configuration option you can use to define a custom format function. You can access the connection object if you want to use the built-in `.escape()` or any other connection function.
@@ -1011,4 +1027,8 @@ For example, if you have an installation of mysql running on localhost:3306 and
10111027

10121028
* Prepared statements
10131029
* setTimeout() for Connection / Query
1030+
<<<<<<< HEAD
1031+
* Support for encodings other than UTF-8 / ASCII
1032+
=======
10141033
* Support for encodings other than UTF-8 / ASCII
1034+
>>>>>>> f924d913fc53cbc7d19d9b7199517acbb0827b95

0 commit comments

Comments
 (0)