You need to sign in or sign up before continuing.

Auto commit

上级 53d5f274
...@@ -3,8 +3,8 @@ const egg = require('egg'); ...@@ -3,8 +3,8 @@ const egg = require('egg');
module.exports = class IndexController extends egg.Controller { module.exports = class IndexController extends egg.Controller {
async ssr() { async ssr() {
const result = this.service.article.getArtilceList(); const result = await this.service.article.getArtilceList();
await this.ctx.render('index/index.js', result); await this.ctx.render('index/index.js', { list: result });
} }
async csr() { async csr() {
......
...@@ -4,7 +4,7 @@ const DBSymbol = Symbol('Application#db'); ...@@ -4,7 +4,7 @@ const DBSymbol = Symbol('Application#db');
module.exports = { module.exports = {
get db() { get db() {
if (!this[DBSymbol]) { if (!this[DBSymbol]) {
this[DBSymbol] = Factory(); this[DBSymbol] = Factory('mysql');
} }
return this[DBSymbol]; return this[DBSymbol];
}, },
......
const db = {
mysql: {
host: 'mysql.inscode.run',
user: 'root',
password: 'inscode',
database: 'blog'
}
}
exports = module.exports = { db };
...@@ -11,27 +11,27 @@ module.exports = class FileDB extends Base { ...@@ -11,27 +11,27 @@ module.exports = class FileDB extends Base {
this.instance._.mixin(lodashid); this.instance._.mixin(lodashid);
this.create(); this.create();
} }
create() { async create() {
this.instance.defaults({ this.instance.defaults({
article: [], article: [],
user: {} user: {}
}).write(); }).write();
} }
get(collectionName) { async get(collectionName) {
return this.instance.get(collectionName); return this.instance.get(collectionName);
} }
add(collectionName, json) { async add(collectionName, json) {
return this.get(collectionName) return this.get(collectionName)
.push(json) .push(json)
.write(); .write();
} }
update(collectionName, where, json) { async update(collectionName, where, json) {
return this.get(collectionName).find(where).assign(json).write(); return this.get(collectionName).find(where).assign(json).write();
} }
delete(collectionName, field) { async delete(collectionName, field) {
return this.get(collectionName).remove(field).write(); return this.get(collectionName).remove(field).write();
} }
getPager(collectionName, json) { async getPager(collectionName, json) {
const { const {
where, where,
like, like,
......
'use strict'; 'use strict';
const mysql = require('mysql');
const Base = require('./base'); const Base = require('./base');
module.exports = class MySQLDB extends Base {}; const config = require('./config')
module.exports = class MySQLDB extends Base {
constructor() {
super();
this.connection = mysql.createConnection({
...config.db.mysql
});
this.connection.connect();
}
getUserById(id) {
const sql = `select * from user where id = ${id}`;
return new Promise((resolve, reject) => {
this.connection.query(sql, function (err, results, fields) {
err ? reject(err) : resolve(results);
});
});
}
getPager(collectionName, json) {
return this.getUserById(1);
}
};
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
<div class="post-preview"> <div class="post-preview">
<div :href="item.url"> <div :href="item.url">
<h2 class="post-title"> <h2 class="post-title">
<a :href="item.url" target="_blank" style="font-size: 26px;">{{item.title}}</a> <a :href="item.url" target="_blank" style="font-size: 26px;">{{item.name}}</a>
</h2> </h2>
<div class="post-content-preview">{{item.summary}}</div> <div class="post-content-preview">{{item.id}}</div>
</div> </div>
<div class="post-meta">Posted by hubcarl on 17-09-24</div> <div class="post-meta">Posted by hubcarl on 17-09-24</div>
</div> </div>
...@@ -69,6 +69,8 @@ ...@@ -69,6 +69,8 @@
window.addEventListener('scroll', ()=>{ window.addEventListener('scroll', ()=>{
this.loadPage(); this.loadPage();
}, false); }, false);
console.log(400, this)
} }
} }
</script> </script>
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
"lowdb": "^1.0.0", "lowdb": "^1.0.0",
"mockjs": "^1.0.1-beta3", "mockjs": "^1.0.1-beta3",
"moment": "^2.17.1", "moment": "^2.17.1",
"mysql": "^2.18.1",
"shortid": "^2.2.8", "shortid": "^2.2.8",
"showdown": "^1.8.6", "showdown": "^1.8.6",
"simplemde": "^1.11.2", "simplemde": "^1.11.2",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册