vendredi 29 janvier 2016

How can I use RethinkDB with EmberJS framework?

I'm new to EmberJS and RethinkDB. I'm using changefeeds of rethinkDB for user specific data to create web push notification application with emberjs.

I have created the same with nodejs and socket.io. it is working fine. I want to convert it to emberjs code. But when i tried to include rethinkdb in bower.json. Im getting a message "Package RethinkDB not found".

"rethinkdb": "~2.0.0"

enter image description here

The below is my working code for Nodejs with Socket.io and RethinkDB

server.js

var sockio = require("socket.io");
var app = require("express")();
var r = require("rethinkdb");
var http = require('http');

var io = sockio.listen(app.listen(3000), {log: false});

app.get('/', function (req, res) {
    res.sendFile(__dirname + '/home.html');
});



r.connect({host: 'localhost', port: 28015})
.then(function(conn){return r.db('my_db').table('user_feeds').changes().run(conn);})
.then(function(cursor){cursor.each(function(err, data) {         
    io.emit('feeds', data);  
    console.log("after Data >>>>>\n"+JSON.stringify(data));
});});

console.log("server started @ http://127.0.0.1:3000/");

home.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Asset Tracker</title>
<script src="http://ift.tt/1Pmz4oM"></script>
<script type="text/javascript">
window.onload = function() {
var socket = io.connect();
socket.on("feeds", function(data) {  
  document.getElementById("feeds").innerHTML = JSON.stringify(data);

});
};
</script>
</head>
<body>
<div id="feeds"></div>
</body>
</html>

I want the above code to be migrated to emberJS. As I'am new to ember I find it difficult to migrate. Not much of a code sample available for rethinkdb with emberjs online.




Aucun commentaire:

Enregistrer un commentaire