File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,26 @@ async function main() {
168168main ();
169169```
170170
171+ #### Getting the ID of the Row You Inserted
172+
173+ ``` js
174+ const sqlite = require (' sqlite' );
175+ const SQL = require (' sql-template-strings' );
176+
177+ async function main () {
178+ const db = await sqlite .open (" ./my-db.sqlite" );
179+ const firstName = ' Tamika' ;
180+ const lastName = ' Washington' ;
181+ // First value is auto-incrementing primary key
182+ const statement = await db .run (SQL ` insert into People values (NULL , ${ firstName} , ${ lastName} )` );
183+ // Get access to the primary key of the inserted row:
184+ console .log (statement .lastID );
185+ await sqlite .close (db);
186+ }
187+
188+ main ();
189+ ```
190+
171191### References
172192
173193* [ Using SQLite with Node.js for Rapid Prototyping] ( https://medium.com/@tarkus/node-js-and-sqlite-for-rapid-prototyping-bc9cf1f26f10 ) on Medium.com
You can’t perform that action at this time.
0 commit comments