使用persistence.sync.server.js问题

时间:2012-01-24 14:33:34

标签: node.js persistence

我根据persistencejs与MySQL商店的说明设置了http://persistencejs.org/plugin/sync服务器同步。 Node.js服务器代码如下。

   var sys = require('sys');
   var persistence = require('./persistence/persistence').persistence;
   var persistenceStore = require('./persistence/persistence.store.mysql');
   var persistenceSync = require('./persistence/persistence.sync.server');

   var Task = persistence.define("Task", {
     name: "TEXT",
     done: "BOOL"
   });

   persistenceStore.config(persistence, 'localhost', 3306, 'tasks', 'root', 'zx6h1lmp');
   persistenceSync.config(persistence);

   var session = persistenceStore.getSession();
   session.schemaSync();

   var app = require('express').createServer();

   app.get('/taskUpdates', function(req, res) {
     persistenceSync.pushUpdates(req.conn, req.tx, Task, req.query.since, function(updates){
       res.send(updates);
     });
   });

   app.listen(8000);
   console.log('Server running at http://localhost:8000/');

加载/ taskUpdates?since = 1325375000会产生以下错误:

Error: Invalid value for argument: callback Value: undefined
    at Object.getArgs (C:\tasks\persistence\persistence.js:2150:19)
    at Observable.list (C:\tasks\persistence\persistence.store.sql.js:580:24)
    at Object.pushUpdates (C:\tasks\persistence\persistence.sync.server.js:82:53)
    at C:\tasks\tasks.js:20:19
    at callbacks (C:\tasks\node_modules\express\lib\router\index.js:272:11)
    at param (C:\tasks\node_modules\express\lib\router\index.js:246:11)
    at pass (C:\tasks\node_modules\express\lib\router\index.js:253:5)
    at Router._dispatch (C:\tasks\node_modules\express\lib\router\index.js:280:4)
    at Object.handle (C:\tasks\node_modules\express\lib\router\index.js:45:10)
    at next (C:\tasks\node_modules\express\node_modules\connect\lib\http.js:203:15)

非常感谢任何见解!

1 个答案:

答案 0 :(得分:0)

我认为您需要为您处理的每个连接调用persistenceStore.getSession()。获取/taskUpdates的示例如下:

app.get('/taskUpdates',  function(req, res) {
    var session = persistenceStore.getSession();
    session.transaction(function(tx){
        persistenceSync.pushUpdates(session, tx, Task, req.query.since, function(updates) {
            res.send(updates);
        });
    });
});