mysql-live-select
mysql-live-select copied to clipboard
Question: Meteor mysql-live-select as a backend for React-Native
Sorry to add this as an issue but cannot find an answer anywhere.
I am trying to understand how to pass Mysql data from meteor to react-native using mysql-live-select. I can connect using the MysqlSubscription from numtel:mysql but still cannot figure out how to do it using the npm package.
- Can you please create a full server-client example?
- How can I export the received diff data to a react-native client using react-native-meteor?
This is my code so far in meteor server:
import {Meteor} from "meteor/meteor";
import LiveMysql from "mysql-live-select";
Meteor.startup(() => {
var settings = {
host: 'localhost',
user: 'user',
password: 'pass',
database: 'test',
serverId: 1,
minInterval: 200
};
const liveDb = new LiveMysql(settings);
var closeAndExit = function () {
liveDb.end();
process.exit();
};
process.on('SIGTERM', closeAndExit);
process.on('SIGINT', closeAndExit);
const table = 'jp9sa_k2_items';
Meteor.publish('news', () => {
return liveDb.select(
"SELECT * FROM " +
"( " +
"SELECT jp9sa_k2_items.id, " +
"jp9sa_k2_categories.`name` AS category, " +
"jp9sa_k2_categories.id AS catid, " +
"jp9sa_k2_items.alias, " +
"jp9sa_k2_items.title, " +
"jp9sa_k2_items.hits AS hits, " +
"jp9sa_k2_items.introtext AS text, " +
"jp9sa_k2_items.fulltext AS ftext, " +
"CONVERT_TZ(jp9sa_k2_items.publish_up,'+00:00','+03:00') AS date " +
"FROM jp9sa_k2_categories INNER JOIN jp9sa_k2_items " +
"ON jp9sa_k2_categories.id = jp9sa_k2_items.catid " +
"WHERE jp9sa_k2_items.published = 1 " +
"AND CONVERT_TZ(jp9sa_k2_items.publish_up,'+00:00','+03:00') <= NOW() " +
"AND jp9sa_k2_items.trash = 0 " +
"ORDER BY date DESC " +
"LIMIT 0, 20" +
") AS T1 " +
"ORDER BY date ASC",
[{table: table}]
).on('update', function (diff, data) {
// diff contains an object describing the difference since the previous update
// data contains an array of rows of the new result set
console.log(diff);
})
})
});
Many Thanks