@@ -120,7 +120,7 @@ connection.destroy();
120
120
121
121
Unlike ` end() ` the ` destroy() ` method does not take a callback argument.
122
122
123
- ## Escaping Query Values
123
+ ## Escaping query values
124
124
125
125
In order to avoid SQL Injection attacks, you should always escape any user
126
126
provided data before using it inside a SQL query. You can do so using the
@@ -170,7 +170,20 @@ console.log(query.sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQ
170
170
171
171
```
172
172
173
- ## Executing Queries in Parallel
173
+ ## Getting the id of an inserted row
174
+
175
+ If you are inserting a row into a table with an auto increment primary key, you
176
+ can retrieve the insert id like this:
177
+
178
+ ``` js
179
+ connection .query (' INSERT INTO posts SET ?' , {title: ' test' }, function (err , result ) {
180
+ if (err) throw err;
181
+
182
+ console .log (result .insertId );
183
+ });
184
+ ```
185
+
186
+ ## Executing queries in parallel
174
187
175
188
The MySQL protocol is sequential, this means that you need multiple connections
176
189
to execute queries in parallel. Future version of this module may ship with a
@@ -180,7 +193,7 @@ parallel.
180
193
181
194
One simple approach is to create one connection per incoming http request.
182
195
183
- ## Streaming Query Rows
196
+ ## Streaming query rows
184
197
185
198
Sometimes you may want to select large quantities of rows and process each of
186
199
them as they are received. This can be done like this:
@@ -220,7 +233,7 @@ stream individual row columns, they will always be buffered up entirely. If you
220
233
have a good use case for streaming large fields to and from MySQL, I'd love to
221
234
get your thoughts and conributions on this.
222
235
223
- ## Error Handling
236
+ ## Error handling
224
237
225
238
This module comes with a consistent approach to error handling that you should
226
239
review carefully in order to write solid applications.
@@ -297,7 +310,7 @@ this advice and suppress unhandled errors, you can do this:
297
310
connection .on (' error' , function () {});
298
311
```
299
312
300
- ## Type Casting
313
+ ## Type casting
301
314
302
315
For your convenience, this driver will cast mysql types into native JavaScript
303
316
types by default. The following mappings exist:
@@ -357,7 +370,7 @@ var query = connection.query('...'):
357
370
query .typeCast = false ;
358
371
```
359
372
360
- ## Debugging and Reporting Problems
373
+ ## Debugging and reporting problems
361
374
362
375
If you are running into problems, one thing that may help is enabling the
363
376
` debug ` mode for the connection:
0 commit comments