one-numan / node-express-sqlite3-REST-API

Node JS , Express and SQLite3 Database
MIT License
0 stars 0 forks source link

Await is not Working with Sqlite3 in Node Js and Express JS #1

Closed one-numan closed 8 hours ago

one-numan commented 1 week ago

Goal : I am trying Build accessing DB with raw Query and Goal is to MVC & Not used ORM

Issue : Write an Raw Quer to getting Data from SQLite3 Database But Issue I get but response is {} empty and After Some time get data in console.log

Get Request , End Point : api/v1/emp/all

image

db_getAll() is Function Using In Model Section , That get Data from DB

Its give Data but await is not working here... image

Console Output

image

one-numan commented 1 week ago

After Multiple Search I get something from Stack overflow Article URL : https://stackoverflow.com/questions/62456867/cannot-await-for-sqlite3-database-get-function-completion-in-node-js

Line From StackOverFlow users and Its Correct working..

Since you want to use async/await, and the node-sqlite3 (sqlite3) library does not support the Promise API, you need to use the node-sqlite (sqlite) library, which is a wrapper over sqlite3 and adds support for the Promise API. I install SQLite and get

I after Followed this Its Working.

one-numan commented 1 week ago

After have Query and Still not satisfied this answer ⬆️ .

So Let's go to official NPM document of SQLite & Github's Code Snippet URL NPM URL : https://www.npmjs.com/package/sqlite Library Github URL : https://github.com/kriasoft/node-sqlite

image

one-numan commented 1 week ago

My Issue is Resolve and Your's

URL : https://github.com/one-numan/node-express-sqlite3-REST-API/commit/f767bf1fdc449386a130ef740aa4a124f8a05311

image