Skip to content

Commit 97a30b9

Browse files
authored
Merge pull request #98 from airportyh/patch-1
Update README.md
2 parents 548bc60 + 51ec573 commit 97a30b9

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
@@ -168,6 +168,26 @@ async function main() {
168168
main();
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

0 commit comments

Comments
 (0)