Notes and Reference SQL Language
Callback Pattern Sqlite queries
//....import db from './config/db'//....//..../*** Read all records and all their columns from some given table.*/const read = async ({ table }) => {const stmt = `SELECT * FROM ${table}`let res = {}// alldb.all(stmt, (error, data) => {logger.info('---all');console.log(`${JSON.stringify(data)} `);});return res;};const read = async ({ table }) => {const stmt = `SELECT * FROM ${table}`// alllet res = {}db.each(stmt, (error, row) => {logger.info('--each');// This will be printed everytime a row is returnedconsole.log(`${JSON.stringify(row)} `);});return res;};
Async Await Pattern with Sqlite queries
//....import db from './config/db'import { promisify } from "util";//....// Use the promise pattern for SQLite so we don't end up in callback hell.const query = promisify(db.all).bind(db);//..../*** Read all records and all their columns from some given table.*/const read = async ({ table }) => {const stmt = `SELECT * FROM ${table}`const res = await query(stmt);return res;};//....