Auto commit

上级 53d5f274
......@@ -3,8 +3,8 @@ const egg = require('egg');
module.exports = class IndexController extends egg.Controller {
async ssr() {
const result = this.service.article.getArtilceList();
await this.ctx.render('index/index.js', result);
const result = await this.service.article.getArtilceList();
await this.ctx.render('index/index.js', { list: result });
}
async csr() {
......
......@@ -4,7 +4,7 @@ const DBSymbol = Symbol('Application#db');
module.exports = {
get db() {
if (!this[DBSymbol]) {
this[DBSymbol] = Factory();
this[DBSymbol] = Factory('mysql');
}
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 {
this.instance._.mixin(lodashid);
this.create();
}
create() {
async create() {
this.instance.defaults({
article: [],
user: {}
}).write();
}
get(collectionName) {
async get(collectionName) {
return this.instance.get(collectionName);
}
add(collectionName, json) {
async add(collectionName, json) {
return this.get(collectionName)
.push(json)
.write();
}
update(collectionName, where, json) {
async update(collectionName, where, json) {
return this.get(collectionName).find(where).assign(json).write();
}
delete(collectionName, field) {
async delete(collectionName, field) {
return this.get(collectionName).remove(field).write();
}
getPager(collectionName, json) {
async getPager(collectionName, json) {
const {
where,
like,
......
'use strict';
const mysql = require('mysql');
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 @@
<div class="post-preview">
<div :href="item.url">
<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>
<div class="post-content-preview">{{item.summary}}</div>
<div class="post-content-preview">{{item.id}}</div>
</div>
<div class="post-meta">Posted by hubcarl on 17-09-24</div>
</div>
......@@ -69,6 +69,8 @@
window.addEventListener('scroll', ()=>{
this.loadPage();
}, false);
console.log(400, this)
}
}
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册