Last active
July 9, 2023 01:53
-
-
Save dentropy/277f5b99b18ea14580c27613fc72e0f4 to your computer and use it in GitHub Desktop.
Read table names from SQLite in NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sqlite3 = require('sqlite3').verbose(); | |
// Open a database connection | |
const db = new sqlite3.Database('pkm.sqlite'); | |
// Query to retrieve table names | |
const query = "SELECT name FROM sqlite_master WHERE type='table'"; | |
// Execute the query | |
db.all(query, [], (err, rows) => { | |
if (err) { | |
console.error(err); | |
} else { | |
// Extract and display table names | |
rows.forEach((row) => { | |
console.log(row.name); | |
}); | |
} | |
// Close the database connection | |
db.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment