coresmart / persistencejs

persistence.js is an asynchronous Javascript database mapper library. You can use it in the browser, as well on the server (and you can share data models between them).
http://persistencejs.org
1.73k stars 240 forks source link

mysql connection handling + sql insert id #37

Closed tg-x closed 13 years ago

tg-x commented 13 years ago

the mysql patch allows to add a callback for connect & listen on errors, so you could have something like: var db = persistenceStore.getSession(function(err) { // ... }); db.conn.on('error', function(err) { console.log('db conn error:', err); setTimeout(connect, 1000); });

the other patch allows for using a custom id instead of the auto-generated one: db.add(new Item({id: 'test', foo: 'bar'}));

zefhemel commented 13 years ago

Hi! Thanks, I integrated the mysql patch. However, the id one I don't think is necessary. You can already set an id when instantiating a new object, like so:

var t = new Task(session, {id: 'blabla', ...});

That's what you're trying to do here right?

tg-x commented 13 years ago

hm, just tested it again, seems like that's not needed anymore

I made that patch a while back for an earlier version, and if I recall correctly in the INSERT query the id appeared twice thus producing an error, but it works now.

zefhemel commented 13 years ago

That's possible. I made this change not too long ok. Alright then, thanks. I'll close this :-)