Skip to content

Instantly share code, notes, and snippets.

@dentropy
Last active July 9, 2023 01:53
Show Gist options
  • Save dentropy/277f5b99b18ea14580c27613fc72e0f4 to your computer and use it in GitHub Desktop.
Save dentropy/277f5b99b18ea14580c27613fc72e0f4 to your computer and use it in GitHub Desktop.
Read table names from SQLite in NodeJS
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