我想退回属于用户的所有软件。我有这样的东西
在我拥有的models / software.js中
const options = {
client: 'mysql',
connection: {
...
}
}
const knex = require('knex')(options);
const bookshelf = require('bookshelf');
const db = bookshelf(knex);
//SOFTWARE MODEL
const Software = db.Model.extend({
tableName: 'table_software',
});
function getSoftware(idUser) {
return knex.select('*').from('table_software').join('table_user', 'table_user.id','table_user_id').where('table_user_id', '=', idUser);
};
module.exports = {
Software,
getSoftware
}
在route / software.js中,我拥有
const Software = require("../models/software");
...
router.post("/", verifyToken, (req, res) => {
jwt.verify(req.token, process.env.JWT_ENCRYPTION, (err, authData) => {
if (err) {
res.sendStatus(403);
} else {
console.log(authData.id);
if (req.params.id == authData.id) {
res.json(Software.getSoftware(authData.id));
}
}
});
});
我得到的错误是TypeError: Converting circular structure to JSON
。如果我用console.log结果,我会得到一堆关于表和数据库连接的信息,而不是查询中的数据。我在做什么错了?
这是我创建表格的方式:
return knex.schema.createTable('table_user', table => {
table.increments('id').unsigned().primary();
table.string('email').notNullable();
table.unique('email');
table.string('password_digest').notNullable();
});
return knex.schema.createTable('table_software', table => {
table.increments('id').unsigned().primary();
table.string('name').notNullable();
table.integer('table_user_id').unsigned().notNullable().references('id').inTable('table_user').onDelete('CASCADE').index();
table.unique(['name', 'table_user_id']);
});
我只想做select * from login_software join login_user on login_user.id = login_user_id where login_user_id = 1