dimanche 27 décembre 2015

Get list of tables from SQLite in Node.js

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

Aucun commentaire:

Enregistrer un commentaire