繁体   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