gpt4 book ai didi

mysql - 问 :Bookshelf. js :How to query by bookshelfjs?

转载 作者:行者123 更新时间:2023-11-29 11:39:29 26 4
gpt4 key购买 nike

我使用Bookshelfjs.org的方法来查询一些数据。但有一个错误!这是我的代码。

var Defray = db.Model.extend({
tableName: 'defray',
idAttribute: 'id'
});
new Defray.query('where', 'purchaseId', '=', '2').fetch().then(function(model) {
console.log(model);
});

数据库是mysql,我想使用sql之类的

select * from defray where purchaseId = 2;

错误信息是

var model = this.forge();
^

TypeError: this.forge is not a function
at new Model.(anonymous function).Collection.(anonymous function) (E:\wordspace\javascript\HEKR_END\node_modules\bookshelf\lib\bookshelf.js:329:24)
at Object.<anonymous> (E:\wordspace\javascript\HEKR_END\database\model.js:30:1)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (E:\wordspace\javascript\HEKR_END\routes\index.js:6:13)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (E:\wordspace\javascript\HEKR_END\app.js:15:14)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run-script" "start"
npm ERR! node v4.2.4
npm ERR! npm v2.14.12
npm ERR! code ELIFECYCLE
npm ERR! app9d@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app9d@0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the app9d package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls app9d
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! E:\wordspace\javascript\HEKR_END\npm-debug.log

sql可以在我的cmd上运行,但我无法使用bookshelf来实现我的目标。请帮助我!

最佳答案

查询是一种模型功能,而不是实例功能。因此,只需更改代码以直接在 Defray 模型上查询,例如:

var Defray = db.Model.extend({
tableName: 'defray' // id not needed, is the default PK name
});
Defray.query('where', 'purchaseId', '=', '2').fetch().then(function(model) {
console.dir(model);
});

关于mysql - 问 :Bookshelf. js :How to query by bookshelfjs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36056609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com