Persistencejs automatically inserting data

156 views
Skip to first unread message

Alejandro Such

unread,
Jun 26, 2014, 7:11:20 AM6/26/14
to persis...@googlegroups.com
Hello all!

I have defined the following entities:

    var Event = persistence.define('Event', {
        date: 'DATE',
        additionalData: 'TEXT',
        isVisit: 'BOOLEAN',
        resultData: 'TEXT',
        userId : 'TEXT',
        active: 'BOOLEAN'
    });

    var Holder = persistence.define('Holder', {
        name: 'TEXT',
        middleName: 'TEXT',
        lastName: 'TEXT',
        document: 'TEXT',
        phoneNumber: 'TEXT',
        cellphoneNumber: 'TEXT',
        email: 'TEXT',
        address: 'TEXT',
        city: 'TEXT',
        zip: 'TEXT'
    });

    Holder.hasMany('events', Event, 'holder');

When I create a new event and associate a Holder, persistencejs does all the inserting stuff without making a persistence.add nor a persistence.flush. Given that it's possible that the info won't be saved, can I somehow avoid this inserting until I force a flush?

var e = new Event();
var h = new Holder();
e.holder = h; // <-- insert of the two entities is made.

Thanks!
Alex

Alejandro Such

unread,
Jun 26, 2014, 8:09:11 AM6/26/14
to persis...@googlegroups.com
Excuse me. The auto-flush is performed when i make a SELECT statement, even if its on another table.

Zef Hemel

unread,
Jun 26, 2014, 10:07:36 AM6/26/14
to persis...@googlegroups.com
Short answer: no.

As soon as you assign one persistence model object to a property of another (or a collection) it will automatically be added via persistence.add. This was done to make the implementation simpler. Usually this is not a problem, but in your case it's indeed unfortunate. The only workarounds I can think of is to either delay assigning to the property or by deleting things from the database again later. Neither are ideal, but changing this behavior would be some significant work to change (I think -- it's been a while).

-- Zef


--
You received this message because you are subscribed to the Google Groups "persistence.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to persistencej...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alejandro Such

unread,
Jun 26, 2014, 6:08:33 PM6/26/14
to persis...@googlegroups.com
Thanks Zef.

I sort of solved my problem by making a persistence.clean() after preparing my data. Then I delegated the saving to a DAO.

Regards, 
Alex

Alejandro Such

unread,
Jun 27, 2014, 3:20:05 AM6/27/14
to persis...@googlegroups.com
By the way. I've read you want to leave the project. Do you know any similar persistence framework for webSQL? I had chosen persistencejs because I saw it was the best, but this problem is making me crazy.

Thanks,
Alex

Zef Hemel

unread,
Jun 27, 2014, 4:12:55 AM6/27/14
to persis...@googlegroups.com
I transferred the project to Paul Burgess (coresmart) a few weeks ago (as you can see in the project URL), but he hasn't seem very active thus far.

I'm not aware of alternative projects. The thing is that WebSQL is kind of dead in the water. Many phones still support it, which why people are still interested in it, but "the future" is likely to be IndexedDB (https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) -- although that's not supported on many phones yet.

-- Zef
Reply all
Reply to author
Forward
0 new messages