在 Feathers 应用程序中获取对 knex 客户端的引用
Get a reference to knex client in feathers app
当我有一个导出多个函数的 test.js
文件时,如何获得 app
使用的 knexClient
的引用?例如,test.js 可用于对数据库执行预定操作,它不是服务的一部分。
module.exports = {
const knex = app.get('knexClient');
doThings: function (params) {
//I NEED KNEX HERE
return something;
},
doThings2: function () {
return somethingElse
}
};
在生成的应用程序中 src/app.js
(参见 here)导出 app
对象:
const app = require('./app');
const knex = app.get('knexClient');
module.exports = {
doThings: function (params) {
//I NEED KNEX HERE
return something;
},
doThings2: function () {
return somethingElse
}
};
当我有一个导出多个函数的 test.js
文件时,如何获得 app
使用的 knexClient
的引用?例如,test.js 可用于对数据库执行预定操作,它不是服务的一部分。
module.exports = {
const knex = app.get('knexClient');
doThings: function (params) {
//I NEED KNEX HERE
return something;
},
doThings2: function () {
return somethingElse
}
};
在生成的应用程序中 src/app.js
(参见 here)导出 app
对象:
const app = require('./app');
const knex = app.get('knexClient');
module.exports = {
doThings: function (params) {
//I NEED KNEX HERE
return something;
},
doThings2: function () {
return somethingElse
}
};