metstrike / meteor-oracle

Oracle Database Driver for Meteor. Translates the meteor collection operations into SQL. Detailed installation instructions are provided. Within 15 minutes you could run fully reactive TODOS application that connects to Oracle database.
MIT License
20 stars 5 forks source link

Reactivity not working? #2

Closed relvar99 closed 8 years ago

relvar99 commented 8 years ago

Hello all,

I have a very simple app expanding on the samples in the readme.md for this package. The app layout is outlined below. Basically, I can output the collections, both the Oracle.Collection one and the mongodb one. When I insert a new document in the mongo collection using a mongo shell, the newly created document appears in the UI as I would expect via meteor's reactivity mechanisms. However, when I insert a new row (in the actual Oracle table) in the Oracle.Collection using sqlplus (or sql developer), I do not see the newly added row in the UI unless I refresh the page. The OpLog tailing process does log the fact that a row is processed, but I do not see the same reactivity ala the mongo collection.

A couple of things, I did not use "meteor" as the Oracle user ( I created my own, and executed the .sql scripts against this user). Therefore, I did modify the

collection.js -> Oracle.resetDefaultOracleOptions to use my user and database connection

and

oracle_db.js line 488 to be trgSql = trgSql + "\t\tns := 'dgslo@oretail.ordbsrv'||'.'||'"+sqlTable+"';\n";

Thanks! Spencer

BTW: This is very exciting. I was able to get this up and running very easily and am very excited to see if this package gets adopted.

approot --client ----hello.html ----hello.js --common ----hello.js --server ----hello.js ----publications.js

The autopublish package was removed. The client html and javascript are ...

hello

Welcome to Meteor!

{{> hello}}

Session.setDefault('counter', 0);

Template.hello.onCreated(function() { let instance = Template.instance(); instance.subscribe("todos"); instance.subscribe("coll3"); });

Template.hello.helpers({ counter: function () { return Session.get('counter'); }, todos: function() { return coll.find(); }, coll3Row: function() { return coll3.find(); } });

Template.hello.events({ 'click button': function () { // increment the counter when button is clicked Session.set('counter', Session.get('counter') + 1); } });

in common ...

coll = new Oracle.Collection("todos"); coll2 = new Oracle.Collection("test"); coll3 = new Mongo.Collection("coll3");

in server...

if (Meteor.isServer) { Meteor.startup(function () { // code to run on server at startup var cursor = coll.find({}); cursor.forEach((row) => { coll.remove({_id: row._id}); }); coll.insert({_id: "1", name: "Get milk", priority:1, userId: "Jane"}); coll.insert({_id: "2",name: "B", priority:2, userId: "Spencer"}); coll.insert({_id: "3",name: "C", priority:3, userId: "SCott"}); var rows = coll.find({priority:1}).fetch(); console.log(rows);

    var cursor2 = coll2.find({});

    coll2.insert({name: "spencer", num: 1});

    coll3.remove({});
    coll3.insert({_id: "1", name: "Get milk", priority:1, userId: "Jane"});
    coll3.insert({_id: "2",name: "B", priority:2, userId: "Spencer"});
    coll3.insert({_id: "3",name: "C", priority:3, userId: "SCott"});
});

}

Meteor.publish("todos", function() { return coll.find() ; });

Meteor.publish("coll3", function() { return coll3.find() ; });

metstrike commented 8 years ago

Connecting to different oracle databases and accounts has been fixed in Release 0.2.0. The reactivity has been tested and here is the simplest example that worked:

myapp.js

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
    Oracle.setDefaultOracleOptions(
    {connection: {
        user: "myapp", 
        password: "myapp", 
        connectString: "host:1521/sid"
        }
    });

    todos = new Oracle.Collection("todos");
    todos.insert({name: "Get milk", priority:1, userId: "Jane"});
    var rows = todos.find({priority:1}).fetch();
    console.log(rows);
  });

  Meteor.publish("todos", function() {
    return todos.find();
  });
}

if (Meteor.isClient) {
  todos = new Mongo.Collection("todos");
  Meteor.subscribe("todos");

  Template.hello.helpers({
    todos: function() {
        return todos.find();
    }
  });
}

myapp.html

<header>
  <h1>Todo List</h1>
</header>

  {{> hello}}
</body>

<template name="hello">  
  <ul>
  {{#each todos}}
    <li>{{name}} (Priority {{priority}})</li>
  {{/each}}
  </ul>
</template>

For more complex sample application that works with meteor-oracle please see https://github.com/metstrike/todos-oracle