How can i detect table exist or not in database by table name? there is not like:
database.exist('some table name')
I write my function:
const queryTableExist = (tableName) => {
return {
sql: `SELECT t.table_name FROM information_schema.tables AS t WHERE t.table_catalog = '' and t.table_schema = '' and t.table_name='${tableName}'`
};
};
let tableExist = (tableName, cb) => {
const query = queryTableExist(tableName);
database.run(query, (err, rows) => {
if (err) {
console.log(`${err}\n${query}`);
cb(err);
}
cb(err, rows.length > 0);
})
};
is there any other idea?