Skip to content

Commit

Permalink
Fixing Issue 1 | await is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
one-numan committed May 5, 2024
1 parent 5a97f9f commit f767bf1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
37 changes: 10 additions & 27 deletions api/v1/db/db_code.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// const { query } = require("express");

const { query } = require("express");

const { open } = require("sqlite");
const sqlite = require("sqlite3").verbose();

const DB_FILE_NAME = "db.sqlite3";
Expand All @@ -19,18 +16,15 @@ async function db_check() {
}

async function db_check2() {
try {
db = await new sqlite.Database(DB_FILE_NAME);
return db;
} catch (err) {
console.log(err);
return err;
}
return open({
filename: DB_FILE_NAME,
driver: sqlite.Database,
});
}

async function getUsers() {
const db = await db_check2();
console.log(db);
// console.log(db);
try {
d = await db.all("SELECT * FROM employee_V1 LIMIT 10");
console.log(d);
Expand Down Expand Up @@ -68,22 +62,11 @@ async function db_getAll(
return false;
} else {
console.log("Connected");
const query = `SELECT ${columns} FROM ${table_name} LIMIT ${limit}`;
const datac = await db.all(query);
// console.log(datac, "datac");

const query_str = `SELECT ${columns} FROM ${table_name} LIMIT ${limit}`;
const datac = await db.all(query_str);
console.log(datac);
console.log(typeof datac);
return await datac;
// db.all(query, async (err, rows) => {
// console.log(err, rows);
// if (err) {
// console.log(err);
// return await false;
// } else {
// console.log("Send Data", rows);
// return await rows;
// }
// });
// return true;
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1/routes/emp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ empRoutes.get("/", async (req, res) => {

empRoutes.get("/", empController.listUsers);

empRoutes.get("/a", empController.empGetAll);
empRoutes.get("/all", empController.empGetAll);

exports.empRoutes = empRoutes;
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"homepage": "https://github.com/one-numan/node-express-sqlite3-stack#readme",
"dependencies": {
"express": "^4.19.2",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7"
},
"devDependencies": {
Expand Down

0 comments on commit f767bf1

Please sign in to comment.