I’m in the process of refactoring the code from mongo
to mysql
by using @numtel 's numtel:mysql
.
The original repo https://github.com/tenzan/blog. Online: http://askar-blog.meteor.com
I’ve created a branch blog-mysql
: https://github.com/tenzan/blog/tree/blog-mysql
For the beginning I’m just trying to:
- List up all
posts
- This is done. - When I remove or add a
post
, the UI has to reflect those changes automatically. Which is not working. (I have another rails app that’s using same DB. So when I was adding or removing a post from there, the meteor app didn’t change the UI automatically.)
The refactored places:
client/main.js:
// Meteor.subscribe('posts');
I’ve comment out the line as it’s related to mongo
. I thought I should replace with something like
MysqlSubscription('posts');
But just this line it seems not sufficient… I’m feeling like this is the place why it’s not getting updating when DB changed.
client/templates/posts/posts_list.js
Template.postsList.helpers({
posts: function () {
//return Posts.find({}, {sort: {submitted: -1}});
return Posts.reactive();
}
});
lib/collections/posts.js
// Posts = new Mongo.Collection('posts');
Posts = new MysqlSubscription('posts');
lib/router.js
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
waitOn: function () {
//return Meteor.subscribe('posts');
return Posts.reactive();
}
});
server/publications.js
// Meteor.publish('posts', function () {
// return Posts.find();
// });
var liveDb = new LiveMysql({
host: 'localhost',
post: 3306,
user: 'root',
password: 'root',
database: 'postag_development'
});
var closeAndExit = function () {
liveDb.end();
process.exit();
};
// Close connections on hot code push
process.on('SIGTERM', closeAndExit);
// Close connections on exit (ctrl + c)
process.on('SIGINT', closeAndExit);
Meteor.publish('posts', function () {
return liveDb.select(
'SELECT * FROM posts ORDER BY created_at DESC',
[{table: 'posts'}]
);
});
I hope this post will be a subject of interest for many people.
Thanks.