簡體   English   中英

sqlite3 sql 在我的 express API 項目的其他文件夾中使用時,特定文件夾中的查詢功能不起作用

[英]sqlite3 sql query functions in specific folder not working when used in other folders of my express API project

SQLite 在一個文件夾中進行查詢,該文件夾具有指向數據庫的鏈接。 將這些函數導入到要使用的位置時,他們試圖將它們應用到當前存儲庫中的數據庫,其中 function 正在運行。

我之前已經說明了 db 在文件中使用查詢的位置,但是,這條路線似乎沒有被使用。

在第一個文件夾中我有一個文件試圖運行導入的 SQL 查詢 function... sqlite 位於此文件夾中。

 // this is my exported function with route to data.sqlite const sqlite3 = require('sqlite3'); const db = new sqlite3.Database('./data.sqlite'); const getData = (data) => { db.all(`SELECT title, desc, details FROM "${data}"`, (err, rows) => { if (err){ console.log(err); } else { console.log(rows); } }); } // this is the file importing and trying to run that function: getData('foo'); /* The error code: [Error: SQLITE_ERROR: no such table: foo] { errno: 1, code: 'SQLITE_ERROR' } It also creates a new table in the same directory as the importing file */

我已經弄清楚出了什么問題,到數據庫的路徑是從根目錄,而不是從 function 所在的當前目錄!

希望這可以幫助任何有類似問題的人。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM