Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Meteor mysql-live-select as a backend for React-Native #28

Open
cliqer opened this issue Aug 20, 2016 · 0 comments
Open

Question: Meteor mysql-live-select as a backend for React-Native #28

cliqer opened this issue Aug 20, 2016 · 0 comments

Comments

@cliqer
Copy link

cliqer commented Aug 20, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant