Giter VIP home page Giter VIP logo

persistencejs's People

Contributors

allain avatar bjouhier avatar brutella avatar budiadiono avatar chrisirhc avatar defunctzombie avatar eugeneware avatar fgrehm avatar flyingdeveloper avatar jacobmumm avatar jordanreiter avatar lukasberns avatar markmyoung avatar mhayashi avatar mikesmullin avatar otype avatar p1nox avatar pixelcort avatar revpriest avatar rsaccon avatar rweng avatar saikirandaripelli avatar staugaard avatar stomlinson avatar superquadratic avatar sylvinus avatar umbrae avatar wilkerlucio avatar willianjusten avatar zefhemel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

persistencejs's Issues

Transparent synchronization support with remote servers

In-browser databases typically contain a subset of data also available on a server. It would be nice to provide frameworks support to automatically synchronize with remote servers, through some JSON-based protocol (for instance).

Many-To-One setting problem: "Cannot read property 'list' of undefined"

Hi, I've got a problem using Many-to-One relationship:

code:

    persistence.store.websql.config(persistence, "testDb", "test", 5 * 1024 * 1024);

    Category = persistence.define("Category", {
        name: "TEXT"
    });

    ParamType = persistence.define("ParamType", {
        name: "TEXT"
    });
    ParamType.hasOne("category", Category, "param_types");

    persistence.schemaSync(function() {

        console.log("created");
        var category1 = new Category ({name: "category1"});
        persistence.add(category1);

        console.log(category1.id);
        var param1 = new ParamType({name: "param1", category: category1});

        //persistence.add(param1);

    });

console:

persistence.store.websql.js:78CREATE TABLE IF NOT EXISTS ParamType (name TEXT, category VARCHAR(32), id VARCHAR(32) PRIMARY KEY) null
persistence.store.websql.js:78CREATE INDEX IF NOT EXISTS ParamType__category ON ParamType (category) null
persistence.store.websql.js:78CREATE TABLE IF NOT EXISTS Category (name TEXT, id VARCHAR(32) PRIMARY KEY) null
empty.html:25created
empty.html:292C19B80A37F548F88E745805FCB5CADA
persistence.js:440Uncaught TypeError: Cannot read property 'list' of undefined

'id' column name should be renamed

It's rather inconvenient for the library to use the 'id' column name since that's likely to be a name that would occur in the user's schema. For instance, I have a bunch of data I received from the server, and they all come with 'id' fields. I would have to go through and rename all the id fields before I can dump it in to the client database. If you named the persistence.js column something else, like 'pid' or '_id', it would be less likely to conflict.

As a workaround for now, I just renamed all the occurrences of 'id' in persistence.js to be 'pid'.

Not working with latest version of node-mysql

I'm trying to get persistence-js working with the lastet version of node-mysql using this code:

var persistence = require('persistencejs/lib/persistence').persistence;
var persistenceStore = require('persistencejs/lib/persistence.store.mysql');

persistenceStore.config(persistence, 'localhost', 3306, 'test2', 'root', 'xxxxxx');
var session = persistenceStore.getSession();

and I'm running into the following error:

node_modules/persistencejs/lib/persistence.store.mysql.js:21
var client = mysql.createClient({
^
TypeError: Object # has no method 'createClient'
at Object.exports.config.exports.getSession (node_modules/persistencejs/lib/persistence.store.mysql.js:21:24)
at Object. (test.js:4:32)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Based on the node-mysql readme file, it looks like the createClient method is no longer supported:

v2.0.0-alpha (2012-05-15)

This release is a rewrite. You should carefully test your application after
upgrading to avoid problems.
...
The first thing you will run into is that the old Client class is gone and
has been replaced with a less ambitious Connection class. So instead of
mysql.createClient(), you now have to:

var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
});

So are we limited to using earlier versions of node-mysql or am I doing something wrong?

Re-delete Bug in Sync Module

Successive deletes produce redundant entries in the _SyncRemovedObject
table.

var SongEntity = persistence.define( 'Song', 
{ 
    number:"INT", 
    artist:"TEXT", 
    title:"TEXT", 
    duration:"INT", 
}); 
SongEntity.index(['number'], {unique:true}); 
SongEntity.enableSync( 'server/synchronize.php?entity=Song' );
persistence.schemaSync( function()
{
    for( var i = 0; i < 4; ++i )
    {
        var songEntity = new SongEntity({ ... }); 
        persistence.add( songEntity ).flush( function()
        {
            persistence.remove( songEntity ).flush();
        });
    }
});
 CREATE TABLE IF NOT EXISTS `Song` (`number` INT, `artist` TEXT, 
 `title` TEXT, `duration` INT, `_lastChange` BIGINT, `id` VARCHAR(32) 
 PRIMARY KEY) null 
 persistence.store.websql.js:78CREATE UNIQUE INDEX IF NOT EXISTS 
 `Song__number` ON `Song` (`number`) null 
 persistence.store.websql.js:78CREATE TABLE IF NOT EXISTS 
 `_SyncRemovedObject` (`entity` VARCHAR(255), `objectId` VARCHAR(32), 
 `id` VARCHAR(32) PRIMARY KEY) null 
 persistence.store.websql.js:78CREATE TABLE IF NOT EXISTS `_Sync` 
 (`entity` VARCHAR(255), `localDate` BIGINT, `serverDate` BIGINT, 
 `serverPushDate` BIGINT, `id` VARCHAR(32) PRIMARY KEY) null 
persistence.store.websql.js:78SELECT `root`.id AS Song_id, 
 `root`.`number` AS `Song_number`, `root`.`artist` AS `Song_artist`, 
 `root`.`title` AS `Song_title`, `root`.`duration` AS `Song_duration`, 
 `root`.`_lastChange` AS `Song__lastChange` FROM `Song` AS `root` 
 WHERE 1=1 ORDER BY `Song_artist` ASC, `Song_title` ASC [] 

One record removed first time, one _SyncRemovedObject record created:

 persistence.store.websql.js:78INSERT INTO `Song` (`_lastChange`, 
 `number`, `artist`, `title`, `duration`, id) VALUES (?, ?, ?, ?, ?, ?) 
 [1326310366172, 0, "", "", 0, "C26F48BB016F46CB8B7DC618DDDD0AA6"] 
 persistence.store.websql.js:78DELETE FROM `Song` WHERE id = 
 '6B7496D2C97C41C2AAEF69E0CDBD406C' null 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "6B7496D2C97C41C2AAEF69E0CDBD406C", 
 "EAD416C0FB9446DC8059211501C09BE6"] 

One record removed second time, two _SyncRemovedObject records created:

 persistence.store.websql.js:78INSERT INTO `Song` (`_lastChange`, 
 `number`, `artist`, `title`, `duration`, id) VALUES (?, ?, ?, ?, ?, ?) 
 [1326310369167, 0, "", "", 0, "712CDFFE8A13430083FBE81A0A747CA7"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "6B7496D2C97C41C2AAEF69E0CDBD406C", 
 "01EEC8F8FD7C40B28A1411A68B18C261"] 
 persistence.store.websql.js:78DELETE FROM `Song` WHERE id = 
 '8399A07307C14CA3BD03440D0C5E0885' null 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "6B7496D2C97C41C2AAEF69E0CDBD406C", 
 "B539AD905DE7444C813E7D5D24648AEE"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "8399A07307C14CA3BD03440D0C5E0885", 
 "3E13FD0DC41E4B51930D117239BEAD6A"] 

One record removed third time, three _SyncRemovedObject records created:

 persistence.store.websql.js:78INSERT INTO `Song` (`_lastChange`, 
 `number`, `artist`, `title`, `duration`, id) VALUES (?, ?, ?, ?, ?, ?) 
 [1326310371783, 0, "", "", 0, "AA62B15DF9184F578C767718650E49CA"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "6B7496D2C97C41C2AAEF69E0CDBD406C", 
 "9756633B10C7459A8043C1A109AC2A1D"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "8399A07307C14CA3BD03440D0C5E0885", 
 "27B18BC25F6346A983088B1BC6D5E48A"] 
 persistence.store.websql.js:78DELETE FROM `Song` WHERE id = 
 '85090A8ACA834991973F960D0F1260C4' null 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "6B7496D2C97C41C2AAEF69E0CDBD406C", 
 "113C466AE36D4C8C87266830CFB79938"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "8399A07307C14CA3BD03440D0C5E0885", 
 "DE309C861070402F92BBB826C026F5F2"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "85090A8ACA834991973F960D0F1260C4", 
 "FF886DECF8B3467D955D5891D7AC0E83"] 

One record removed fourth time, four _SyncRemovedObject records created:

 persistence.store.websql.js:78INSERT INTO `Song` (`_lastChange`, 
 `number`, `artist`, `title`, `duration`, id) VALUES (?, ?, ?, ?, ?, ?) 
 [1326310374808, 0, "", "", 0, "F03B48F5CCF54849AA48225FA6F6726B"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "6B7496D2C97C41C2AAEF69E0CDBD406C", 
 "AD7CA02039CD4D44885E060BEE84A831"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "8399A07307C14CA3BD03440D0C5E0885", 
 "667F1EB1979C401190A7DAFA397608D0"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "85090A8ACA834991973F960D0F1260C4", 
 "A4FC3E8A7BA4439B937B8492BBD0F947"] 
 persistence.store.websql.js:78DELETE FROM `Song` WHERE id = 
 'CE9994918FAD4AFF87ED70D53344270C' null 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "6B7496D2C97C41C2AAEF69E0CDBD406C", 
 "30FF2E3B9ACB4B1B823D06F87A23A627"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "8399A07307C14CA3BD03440D0C5E0885", 
 "38B3DF8EEBE94270825547C7CB4DF513"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "85090A8ACA834991973F960D0F1260C4", 
 "1C65BF43CDFF428B92580DA73F18EE12"] 
 persistence.store.websql.js:78INSERT INTO `_SyncRemovedObject` 
 (`entity`, `objectId`, id) VALUES (?, ?, ?) ["Song", 
 "CE9994918FAD4AFF87ED70D53344270C", 
 "5D27169751214472820C4E1ED793F974"] 

Implement/use asynchronous wrapper around Google Gears

Google Gears has a synchronous database API, it is possible to create an asynchronous wrapper around it, but this is currently not part of persistence.js, therefore calls are currently performed synchronously, which may not have the best performance characteristics. This can possibly be fixed by using e.g. WSPL.

persistence.sync.server - Invalid value for argument: callback Value: undefined

Node.js server with following code:

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', 'pass');
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/');

Throws the following error when http://localhost:8000/taskUpdates?since=1325375000 is loaded:

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)

Any insights are appreciated!

Crashing for parent to child prefetch

I'm working with the sample code, specifically prefetching relationships.

This works:

var allTasks = Task.all(session).prefetch("category");

But this does not work:

var allTasks = Task.all(session).prefetch("tags");

node_modules/persistencejs/lib/persistence.store.sql.js:653
var thisMeta = meta.hasOne[prefetchField].type.meta;
^
TypeError: Cannot read property 'type' of undefined

I see the documentation says

"prefetch(rel)
Returns a new QueryCollection that prefetches entities linked through relationship rel, note that this only works for one-to-one and many-to-one relationships."

Does that mean that given a child you can get the parent (e.g. given a task you can get the category), but given a parent you cannot get the children (given a category you cannot get the tasks)?

id column is mandatory

I'm trying a simple task of extracting an identity from a table. That table doesn't have an id column(it's key column is called Key). Persistence generates sql that expects the id column and then fails.

var File = persistence.define('Components', {
    Key: 'TEXT',
    Published: 'TEXT'
});

//...

File.findBy(session, tx, 'Key', sha, function(obj) { ... });

Results in the sql:

SELECT `root`.id AS Components_id, `root`.`Key` AS `Components_Key`, `root`.`Published` AS `Components_Published`
FROM `Components` AS `root`  WHERE (1=1 AND `root`.`Key` = ?) LIMIT 1

Is there any way to suppress the selection of an id column?

'id' is a varchar?

What was the design decision behind forcing the autocreated id column to be a varchar? Is it configurable? (docs don't give a clue as to the possibility of this being the case).

'id' is a varchar?

What was the design decision behind forcing the autocreated id column to be a varchar? Is it configurable? (docs don't give a clue as to the possibility of this being the case).

.destroyAll() removes ALL Entities

The documentation says:
"destroyAll([tx], callback) Asynchronously removes all the items in the collection. Important: this does not only remove the items from the collection, but removes the items themselves!"

Example:
// get the first 20 entities but skip the very first two
HistoryElement.all().order('lastUsedOn', false).limit(20).skip(2).list( function (r) {
console.log(r);
});

Generates the expected Queries (if you do not forgot the .limit() - otherwise it also does unexpected things):
SELECT root.id AS HistoryElement_id, root.lastUsedOn AS HistoryElement_lastUsedOn, root.project AS HistoryElement_project, root.customer AS HistoryElement_customer, root.activity AS HistoryElement_activity, root.workingPeriod AS HistoryElement_workingPeriod FROM HistoryElement AS root WHERE 1=1 ORDER BY HistoryElement_lastUsedOn DESC LIMIT 20 OFFSET 2 []

If I now want to delete all this (up to 18) entities after my first two I expect i can do it like that:
HistoryElement.all().order('lastUsedOn', false).limit(20).skip(2).destroyAll();

But this is the generated SQL:
SELECT id FROM HistoryElement WHERE 1=1 []
persistence.store.websql.js:78DELETE FROM HistoryElement WHERE 1=1 []

At this point all entities got lost.

Titanium platform bug cause android platform not working

Hi, i have run the Titanium platform on android,but it did not work. After days to find it's a Titanium platform bug. The Ti.Database.Resultset fieldCount() function does not work on android but ok for iOS. https://jira.appcelerator.org/browse/TIMOB-2945
It has not be resloved yet and not likely to be solved in a near future. So the way to pass maybe is add a platform detect code in the Titanium.js.
while (rs.isValidRow()) {
var result = {};
//to sovle the titanium bug,on android ,resultset has a fieldCount attribute but ios it is a method
var fc ;
if(Ti.Platform.osname == 'android'){
fc = rs.fieldCount;
}else{
fc = rs.fieldCount();
}
for ( var i = 0; i < fc; i++) {
result[rs.fieldName(i)] = rs.field(i);
}
results.push(result);
rs.next();
}

missing node_events.h

Compiling against Node 0.8.1, I get this error:
npm install persistencejs -g
.....................................
ranlib libmpool.a
[1/6] cc: deps/sqlite/sqlite3.c -> build/Release/deps/sqlite/sqlite3_1.o
[2/6] cxx: src/sqlite3_bindings.cc -> build/Release/src/sqlite3_bindings_2.o
../src/sqlite3_bindings.cc:19:25: error: node_events.h: No such file or directory
In file included from ../src/sqlite3_bindings.cc:22:
../src/database.h:29: error: expected class-name before ‘{’ token
../src/database.h: In constructor ‘Database::Database()’:
../src/database.h:35: error: class ‘Database’ does not have any field named ‘EventEmitter’
.....................................

Deprecated method called in persistenceStore.getSession()

  p = require('persistencejs/lib/persistence').persistence
  ps = require 'persistencejs/lib/persistence.store.mysql'
  ps.config p, 'localhost', 3306, 'db', 'user', 'pass'
  session = ps.getSession()

gives

Error: deprecated: connect() is now done automatically.
    at Client.connect (/usr/local/lib/node_modules/persistencejs/node_modules/mysql/lib/client.js:40:9)
    at Object.getSession (/usr/local/lib/node_modules/persistencejs/lib/persistence.store.mysql.js:27:10)
    at Object.<anonymous> (eval at <anonymous> (/usr/local/lib/node_modules/zappa/lib/zappa.js:35:12))
    at anonymous (eval at <anonymous> (/usr/local/lib/node_modules/zappa/lib/zappa.js:35:12))
    at /usr/local/lib/node_modules/zappa/lib/zappa.js:640:20
    at callbacks (/usr/local/lib/node_modules/zappa/node_modules/express/lib/router/index.js:272:11)
    at param (/usr/local/lib/node_modules/zappa/node_modules/express/lib/router/index.js:246:11)
    at pass (/usr/local/lib/node_modules/zappa/node_modules/express/lib/router/index.js:253:5)
    at Router._dispatch (/usr/local/lib/node_modules/zappa/node_modules/express/lib/router/index.js:280:4)
    at Object.handle (/usr/local/lib/node_modules/zappa/node_modules/express/lib/router/index.js:45:10)

persistencejs version 0.2.5

Documentation Examples

A decent example of how to use persistencejs from start to finish would be Immensely useful, having to decode sections makes this harder than it needs to be.
Just a bit of information in a useful structure would be extremely beneficial.
example:
HowTo Browser:
start to finish creating, inserting, retrieving, updating, deleting done
HowTo Nodejs:
start to finish creating, inserting, retrieving, updating, deleting done
etc..
I have had to read the code to understand how things work and thats great for people who know the language well, but this would be impossible for anyone starting out, and its just so useful, it'd be a shame to loose out on that.

Migrating downwards goes too far

I have to migrations, 1 and 2. When I call persistence.migrate(2,function(){}), both migrations are moved up.

However, later when I call persistence.migrate(1,function(){}), both migrations' down functions are called.

I was expecting only the down function on migration 2 to be called.

QueryCollection#each is not asynchronous

README.md documentation states that QueryCollection#each asynchronously fetches the results. In reality, it fetches all results from the database at once and then loops over them invoking the callback for each one.

Error: Cannot find module 'persistencejs/persistencejs'

npm install persistencejs goes fine

but
var persistence = require('persistencejs/persistence').persistence;
gives me
Error: Cannot find module 'persistencejs/persistence'

var persistence = require('persistencejs/persistence.min').persistence;
is ok

my node version is v0.5.0-pre

"session" not set for memory store

Code in persistence.store.memory.js should be:
persistence.flush = function (tx, callback) {
var args = argspec.getArgs(arguments, [
{ name: "tx", optional: true, check: persistence.isTransaction },
{ name: "callback", optional: true, check: argspec.isCallback(), defaultValue: function(){} }
]);

var session = this; /*<------ bugfix ---*/
var fns = persistence.flushHooks;
persistence.asyncForEach(fns, function(fn, callback) {
    fn(session, tx, callback); /*<------ else session in undefined here ---*/
  }, function() {
    var trackedObjects = persistence.trackedObjects;
    for(var id in trackedObjects) {
      if(trackedObjects.hasOwnProperty(id)) {
        if (persistence.objectsToRemove.hasOwnProperty(id)) {
          delete trackedObjects[id];
        } else {
          trackedObjects[id]._dirtyProperties = {};
        }
      }
    }
    args.callback();
  });

};

PostgreSQL Support

Are there any plans of supporting PostgreSQL, or is it already supported? As far as I can tell, only MySQL and SQLite databases are supported.

search plugin crashes on null values

when a property of an entity is registered for fulltextsearch (like Note.textIndex('name')) and the object has value 'null' for that property, flush throws an error

Uncaught TypeError: Cannot call method 'toLowerCase' of null :3000/lib/persistence/persistence.search.js:59

Non-database QueryCollections

It would be useful to also have a QueryCollection implementation that simply wraps Javascript arrays, i.e. for collections that are not stored in the database.

Add a 'through' parameter to relationships

I would like to be able to specify the intermediate table in a many to many relationship so it can have some extra fields. What I'm looking for is a ':trough' parameter in ActiveRecord lingo.

skip() behaves strangely

Docs:

skip(n): Returns a new QueryCollection that skips the first n results. Useful for pagination.

Query:

var result = Model.all().filter(“ParentKey”,”=”,5).skip(10).limit(20)

Meaning (for me): Get 11-30 records with Parentkey = 5

The result in life:

Resultset contains 20 rows (itemcount in result.count equals to 20), but if I send the data from result.each to console.log, I can see rows 11-20 only (so limit(20) comes first, then skips the first 10 rows, but only with the pointer).

'node-waf' is not recognized as an internal or external command, with nodejsV0.6.3

D:\mydir>npm install persistencejs

[email protected] preinstall D:\mydir\node_modules\persistencejs\node
_modules\sqlite
node-waf configure build

'node-waf' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! error installing [email protected] Error: [email protected] preinstall: node-waf configure build
npm ERR! error installing [email protected] cmd "/c" "node-waf configure build" fai
led with 1
npm ERR! error installing [email protected] at ChildProcess. (C:\Progr
am Files\nodejs\node_modules\npm\lib\utils\exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:70:17
)
npm ERR! error installing [email protected] at maybeExit (child_process.js:359:16
)
npm ERR! error installing [email protected] at Process.onexit (child_process.js:3
95:5)
npm ERR! error installing [email protected] Error: [email protected] preinstall: n ode-waf configure build
npm ERR! error installing [email protected] cmd "/c" "node-waf configure buil d" failed with 1
npm ERR! error installing [email protected] at ChildProcess. (C
:\Program Files\nodejs\node_modules\npm\lib\utils\exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.j
s:70:17)
npm ERR! error installing [email protected] at maybeExit (child_process.js
:359:16)
npm ERR! error installing [email protected] at Process.onexit (child_proce
ss.js:395:5)
npm ERR! Error: ENOENT, no such file or directory 'D:\mydir\node_m
odules\persistencejs\node_modules___mysql.npm\package\test\unit\test-client.js'

npm ERR! Report this entire log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]
npm ERR!
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install" "persistencejs"
npm ERR! cwd D:\mydir
npm ERR! node -v v0.6.3
npm ERR! npm -v 1.1.0-alpha-2
npm ERR! path D:\mydir\node_modules\persistencejs\node_modules___
mysql.npm\package\test\unit\test-client.js
npm ERR! fstream_path D:\mydir\node_modules\persistencejs\node_mod
ules___mysql.npm\package\test\unit\test-client.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory 'D:\mydir\node_
modules\persistencejs\node_modules___mysql.npm\package\test\unit\test-client.js
'
npm ERR! fstream_stack Object.oncomplete (C:\Program Files\nodejs\node_modules\n
pm\node_modules\fstream\lib\writer.js:203:26)
npm ERR! [email protected] preinstall: node-waf configure build
npm ERR! cmd "/c" "node-waf configure build" failed with 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the sqlite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls sqlite
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install" "persistencejs"
npm ERR! cwd D:\mydir
npm ERR! node -v v0.6.3
npm ERR! npm -v 1.1.0-alpha-2
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] preinstall: node-waf configure build
npm ERR! message cmd "/c" "node-waf configure build" failed with 1
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! D:\mydir\npm-debug.log
npm not ok

Persistence Sync Date

I'm having an issue with persistence.sync.js regarding dates.

I have set the server to send all dates as an Epoch based string as follows:

    $json = new \stdClass();

    foreach ($this as $key => $value) {
        if ($value instanceof \DateTime) {
            $json->$key = $value->format('U');
        } else {
            $json->$key = $value;
        }
    }
    return $json;

Looking at the data that is being sent, this is working as expected, with the date field being sent as an integer.
However, when persistence.sync.js reads the JSON data, the logged INSERT command is as follows:

INSERT INTO `mytable` (`text_field_a`, `text_field_b`, `text_field_c`, `date_field`, id) VALUES (?, ?, ?, ?, ?) ["TestA", "TestB", "TestC", NaN, "ABC049AC6EF144CF99FEFD52A8A47532"]

(note NaN value for date field)

Looking through the sync source, I can't work out where this is occurring as the correct integer value is being read in 'Step 3' (line 169). I'm guessing it's somewhere in persisting the data.

I'm using Chrome 22.0.1201.0

Any help would be appreciated.

Regards

Hayden

migrations removeColumn do not work in chrome

It seems like the RegExp used in "Migration.prototype.removeColumn" do not take into account the quotation characters "`" chrome adds around the table name.

The RegExp today looks like this "CREATE TABLE \w+ ((.+))".

It seems like this small change fixes the bug in chrome "CREATE TABLE \\w+ ((.+))".

Best regards!

error in documentation

The documentation says that there are add and remove functions on the EntityCollection. However as far as I can tell there isnt.
These functions are on session or persistance

Missing Documentation for 'in' Filter

Would it be too much to ask to document what the 'in' filter actually expects? I'm pretty sure it expects an array. This is the only way this would make sense, but.... IT FKING DOESN'T WORK.
Little example:
var toRemove = Foo.all().filter('email','in',toRemoveArray);

toRemove.list(null,function(resultList) {
resultList.forEach(function(currentMail) {
persistence.remove(currentMail);
});
});

I stepped through this god knows how often in the debugger, but after .list is invoked, it never gets inside the callbackhandler ( function(resultList) ...), not to mention the forEach.
And, yes I set breakpoints on the foreach and persistence line. So, if this would actually work, the debugger would actually kick in on those lines of code.
The funny thing is, this worked a few weeks ago (I'm 99.99% sure of that). Since I haven't had the time to talk to my colleagues I can only assume they updated persistence.js some time ago and somewhere in-between the 'in' filter feature has been b0rked.

Object #<Object> has no method 'forEach'

Hi,

I've just started using persistence.js.
Unfortunately, when I try to run sample from your examples, like
<script src="persistence/persistence.js" type="application/javascript"></script>
<script src="persistence/persistence.store.sql.js" type="application/javascript"></script>
<script src="persistence/persistence.store.websql.js" type="application/javascript"></script>

<script language="javascript" type="text/javascript">
    persistence.debug = false;
    persistence.store.websql.config(persistence, 'mydcdb', 'MyDC local database', 5 * 1024 * 1024);

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

    for (var i = 0; i < 5; i++) {
        var t = new Task();
        t.name = 'Task ' + i;
        t.done = i % 2 == 0;
        persistence.add(t);
    }
    persistence.flush(function () {
        console.log('done flushing');
    });

    Task.all().list(function (results) {
                console.log(results);
                results.forEach(function (r) {
                    console.log(r.name);
                });
            });
</script>

I receive next output:
done flushing
Object
executeSql: function (query, args, successFn, errorFn) {
proto: Object
defineGetter: function defineGetter()
defineSetter: function defineSetter()
lookupGetter: function lookupGetter()
lookupSetter: function lookupSetter()
constructor: function Object()
hasOwnProperty: function hasOwnProperty()
isPrototypeOf: function isPrototypeOf()
propertyIsEnumerable: function propertyIsEnumerable()
toLocaleString: function toLocaleString()
toString: function toString()
valueOf: function valueOf()
Uncaught TypeError: Object # has no method 'forEach'
(anonymous function)
persistence.DbQueryCollection.list.entityNamepersistence.store.sql.js:591
persistence.db.html5.connect.that.transaction

I'm using Chrome and latest download of persistence.js.

persistence.flush bottlenecks on session.trackedObjects

Let's say I have the following hypothetical code:

a = [];
for (var i=0;i<8000;i++){var deck = new App.Deck(); a.push(deck);}
persistence.asyncForEach(a, function(d,n){persistence.add(d);persistence.flush(n);},function(){console.log('done');});

The problem that I'm facing is that each successive flush takes longer than the one before it, and memory usage grows linearly.

I've tracked the issue down to the use of session.trackedObjects, which appears to not get cleared out anywhere. It is then used down in persistence.asyncParForEach(persistObjArray, ..., which in turn calls save() on all previously saved entries.

It appears flush clears out session.objectsToRemove; is it safe to also clear out session.trackedObjects here as well?

Syncing down thousands of changes at a time doesn't work

I've got sync set up and working, however I've got thousands of changes that were made server side.

After sync calls GET /api/testSync?since=1344020688591 and gets back the huge changes array, it tries to do a local DB query:

SELECT `root`.id AS Deck_id, `root`.`name` AS `Deck_name`, `root`.`lastUploaded` AS `Deck_lastUploaded`, `root`.`_lastChange` AS `Deck__lastChange` FROM `Deck` AS `root`  WHERE (1=1 AND `root`.`id` IN (?, ?, ?, ?, ?, ?, <snip>

... where the IN clause has thousands of arguments.

I'm betting the issue is that, in Chrome and probably Safari, it appears there is a limit to the number of arguments to an IN clause.

As a workaround, I considered only sending to the client a few records at a time with a forged now key, and then just run sync over and over again, however that won't work in this case since the thousands of changes all have the exact same _lastChange key.

Filtering based on joined table.

I have the following defined.

Ingredient = persistence.define(TABLE_INGREDIENT_NAME, {
    ingredientName: "TEXT"
});
Inventory = persistence.define(TABLE_INVENTORY_NAME, {
    quantity:"TEXT",
    unit:"TEXT"
});
Inventory.hasOne('ingredient',Ingredient);
Ingredient.hasOne('inventory',Inventory);

I would like to fetch an inventory based on the ingredientName, is this not possible ?

Inventory.all().prefetch('ingredient').filter('ingredientName','=',ingredientName).list(null,callback);

findBy() never calls the callback

Whether I have results or not, the callbacks are just not being called, if I use Entity.one() I get the callbacks to be called.

anyone else got that issue? I followed pretty much everything the documentation said and still no go

TypeError: Cannot read property 'prototype' of undefined

I installed persistence.js today with npm. I firstly encountered the issue here: #39 , but fixed it by linking to the files in my "app.js" thusly:

var persistence = require("persistencejs/persistence.min").persistence,
    persistenceStore = require("persistencejs/lib/persistence.store.mysql");

Then I tried running my app again and node coughed up this error:

TypeError: Cannot read property 'prototype' of undefined
    at Object.config (/home/matt/node_modules/persistencejs/lib/persistence.store.sql.js:532:23)
    at Object.config (/home/matt/node_modules/persistencejs/lib/persistence.store.mysql.js:122:7)
    at Object.<anonymous> (/home/matt/Sites/Test/app.js:18:18)
    at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at Array.<anonymous> (module.js:423:10)
    at EventEmitter._tickCallback (node.js:170:26)

Digging into this, it appears that persistence.OrFilter is undefined, although my brief look through the source would indicate that it should be defined. NullFilter, AndFilter & PropertyFilter all seem to be defined according to console.log(persistence);, so I do not understand why this particularly property isn't working.

Commenting out lines 532->535 of persistence.store.sql.js stops the error, but I assume that would break functionality.

/*persistence.OrFilter.prototype.sql = function (meta, alias, values) {
    return "(" + this.left.sql(meta, alias, values) + " OR "
    + this.right.sql(meta, alias, values) + ")";
};*/

Has anyone else encountered this issue?

npm: 1.0.6, node: v0.5.0-pre, persistencejs: 0.2.5.

Using "1" as the entity id

I found that I couldn't set the id to "1" (i.e. a stringified version of the numeral one) as the primary key for an entity. Every operation that I tried would result in it seemingly being ignored.

IE9 support

I tweaked persistence.js slightly and it seems to work in IE9 now (using the in-memory store). Just replace your usages of __defineG/Setter__ like so:

Replace:
myobject.__defineGetter__(field, mycallback);
with:
Object.defineProperty(myobject, field, { get : myGetCallback, set : mySetCallback, enumerable : true, configurable : true });

It appears to work in IE9 and the latest versions of webkit.

The only other change I had to make was in LocalQueryCollection.prototype.add/addAll, I moved this._items.push(obj); to be above this._session.add(obj); instead of below it, because otherwise I was encountering infinite recursion. I don't know why that happened in IE and not Chrome.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.