Current Size:
Chakra BreakPoints
base0px
sm480px
md768px
lg992px
xl1280px
2xl1536px
Current Height:Width
widthpx
heightpx

Subjects

Notes on Node SQLite

Date Created: 2023/08/22

Last Update: 2023/08/22

#sql #sqlite #notes #reference

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 = {}
// all
db.all(stmt, (error, data) => {
logger.info('---all');
console.log(`${JSON.stringify(data)} `);
});
return res;
};
const read = async ({ table }) => {
const stmt = `SELECT * FROM ${table}`
// all
let res = {}
db.each(stmt, (error, row) => {
logger.info('--each');
// This will be printed everytime a row is returned
console.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;
};
//....

Understaing

Resources and Reference

More Notes

All Notes
HomeProjects

Links

Home Articles Notes Projects About Style Guide Site Credits

Contact

 [email protected]

Location

🌎 Earth