Доброго времени суток.
Пишу(или скорее переписываю с Express) приложение на Koa. Использую БД Mysql и модуль koa-mysql(
https://github.com/eladnava/koa-mysql). И возникла проблема со следующей конструкцией:
exports.get=function* (next){
const ctx=this;
let sql = "SELECT * FROM clients_forums_knowledge_base ORDER BY orders ASC";
let forumsKnowledgeBase = yield ctx.locals.db.query(sql);
forumsKnowledgeBase.forEach((elem,idx) => {
let sql='SELECT clients_knowledge_base.name, clients_knowledge_base.id,clients_knowledge_base.file FROM clients_knowledge_base,clients_forums_knowledge_base WHERE clients_forums_knowledge_base.id = clients_knowledge_base.forum AND clients_knowledge_base.forum = ? ORDER BY name ASC';
let rows = yield ctx.locals.db.query(sql,elem.id);
elem.items=rows ;
})
};
При запуске вылетает ошибка:
app-0 /var/www/app/routes/clients/knowledgebase.js:10
app-0 let rows = yield ctx.locals.db.query(sql,elem.id);
app-0 ^^^
app-0 SyntaxError: Unexpected identifier
app-0 at exports.runInThisContext (vm.js:53:16)
app-0 at Module._compile (module.js:511:25)
app-0 at Object.Module._extensions..js (module.js:550:10)
app-0 at Module.load (module.js:456:32)
app-0 at tryModuleLoad (module.js:415:12)
app-0 at Function.Module._load (module.js:407:3)
app-0 at Function._load (/usr/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
app-0 at Module.require (module.js:466:17)
app-0 at require (internal/module.js:20:19)
app-0 at Object.<anonymous> (/var/www/app/routes/index.js:6:43)
На всякий случай app.js:
const koa = require('koa');
const http = require('http');
const path = require('path');
const config = require('./config');
const favicon = require('koa-favicon');
const logger = require('koa-logger');
const locals = require('koa-locals');
const serve = require('koa-static');
const body = require('koa-better-body');
const session = require('koa-generic-session');
const mysql = require('koa-mysql');
const sessionStore=("./sessionStore");
const Pug = require('koa-pug');
const locale = require('koa-locale');
const i18n = require('koa-i18n');
const router = require('./routes');
const app = koa();
locals(app, {
db: mysql.createPool(config.get('db'))
});
locale(app)
app.keys = ['KillerIsJim']
app
.use(favicon(__dirname + '/public/favicon.ico'))
.use(logger())
.use(body())
.use(session({store: sessionStore}))
.use(router.routes())
.use(router.allowedMethods())
.use(serve(__dirname + '/public'))
router.use(i18n(app, {directory: './config/locales',locales: ['en','ru-RU'],modes: ['header']}))
const pug = new Pug({viewPath: __dirname + '/views',noCache:true,app: app})
const io=require('./lib/socket');
io.attach(app)
app.listen(config.get('port'))
И routes/index.js
const router = require('koa-router')();
const koaBody = require('koa-body')()
router.redirect('/','/knowledgebase');
router.get('/knowledgebase',require('./clients/knowledgebase').get);
module.exports = router;
Может ли кто нибудь подсказать в чем может быть проблема?