Использование @ mysql / xdevapi Я пытаюсь получить результаты необработанного запроса SQL, но получаю следующую ошибку:
{"message":"Error validating selections: s.sql is not a function","level":"error"}
Я следую за документы но я не могу понять, почему я получаю эту ошибку.
Код ошибки ниже ...
const mysqlx = require('@mysql/xdevapi')
const logger = require('./logger')
const {
MYSQL_USER,
MYSQL_PASSWORD,
MYSQL_HOST,
MYSQL_PORT,
MYSQL_SCHEMA
} = process.env
const session = mysqlx.getSession({
user: MYSQL_USER,
password: MYSQL_PASSWORD,
host: MYSQL_HOST,
port: parseInt(MYSQL_PORT)
})
.catch(e => logger.error('Error connecting to database:', e))
exports.validateSelections = selections =>
session
.then(s => s
.getSchema(MYSQL_SCHEMA)
.sql('SELECT * FROM affiliate_links WHERE id = 1')
.execute()
)
И вызывающий код ...
const { body } = require('express-validator/check')
const { validateSelections } = require('../database')
const postcodeValidator = require('postcode-validator');
const logger = require('../logger')
const config = require('../../config/config')
module.exports = [
body('postcode')
.custom(postcode => {
const isValid = postcodeValidator.validate(postcode, 'UK')
logger.info(`Postcode value passed into postcode validator: ${postcode}`)
if(!isValid) {
return Promise.reject(config.errors.invalid_postcode)
}
return Promise.resolve()
}),
body('selections')
.custom(selections => {
logger.info(`Selections passed into validator: ${selections.toString()}`)
if (!Array.isArray(selections)) {
logger.debug('Selections is not an array')
Promise.reject(config.errors.invalid_survey_selection)
}
validateSelections(selections)
.then(result => {
// Check result and resolve
Promise.resolve()
})
.catch(e => {
logger.error(`Error validating selections: ${e.message}`)
Promise.reject(config.errors.invalid_survey_selection)
})
})
]