Below code returns only the name of first table, how to get list of all available table names in existing sqlite?
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('path/to/mydb.sqlite');
db.serialize(function () {
db.get("select name from sqlite_master where type='table'", function (err, table) {
console.log(table);
});
});
Output
{name: "meta"}
When opened in sqlite3 command-line
sqlite> .tables
downloads meta urls
downloads_url_chains segment_usage visit_source
keyword_search_terms segments visits
From the get()'s doc:
Runs the SQL query with the specified parameters and calls the callback with the first result row afterwards.
You have to use db.all():
db.serialize(function () {
db.all("select name from sqlite_master where type='table'", function (err, tables) {
console.log(tables);
});
});
Or db.each() if you want to call the callback for every row:
db.serialize(function () {
db.each("select name from sqlite_master where type='table'", function (err, table) {
console.log(table);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With