gpt4 book ai didi

node.js - 我无法通过 sequelize 进行基本的 sql 查询

转载 作者:行者123 更新时间:2023-12-03 22:32:47 30 4
gpt4 key购买 nike

我错过了一些东西,我认为这很简单,但我很挣扎。我关注了一个博客,让 OAuth2.0 与 Node 和 Sequelize 与 Postgres 一起工作。有用...
现在我只是想添加一个基本的 SQL 选择,但我无法让它工作。有人可以帮帮我吗?
模型/index.js

'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};

let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
Controller / Controller .js
const bcrypt = require('bcrypt');
const OAuthTokensModel = require('../models').OAuthTokens;
const OAuthClientsModel = require('../models').OAuthClients;
const OAuthUsersModel = require('../models').OAuthUsers;
const db = require('../models').db;

module.exports.change = function () {
return db.sequelize.query(`
SELECT * FROM "OAuthUsers"
`,
{
type: sequelize.QueryTypes.SELECT
}
)
.catch((error) => console.error(error));
};

module.exports.getAccessToken = function (bearerToken) {
return OAuthTokensModel.findOne(
{
where: {
accessToken: bearerToken
},...
我返回以下错误:
无法读取未定义的属性“Sequelize ”
正如我所说,我确定这很简单,但我是 Sequelize 新手。
安迪

最佳答案

尝试将 sequelize 导入您的 Controller
const sequelize = require('sequelize');

关于node.js - 我无法通过 sequelize 进行基本的 sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65269636/

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