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

Last insert Id #156

Open paul-piro opened 9 years ago

paul-piro commented 9 years ago

There is no way to find out LastInsertId because the framework doesn't return the native lastinsertid

persistence.db.html5.transaction = function (t) {
    var that = {};
    that.executeSql = function (query, args, successFn, errorFn) {
      if(persistence.debug) {
        console.log(query, args);
      }
      t.executeSql(query, args, function (_, result) {
          if (successFn) {
            var results = [];
            for ( var i = 0; i < result.rows.length; i++) {
              results.push(result.rows.item(i));
            }
            successFn(results);
          }
        }, errorFn);
    };
    return that;
  };

last insert id is present in results but the results are iterated and this field and affected rows are omitted

zefhemel commented 9 years ago

persistence.js generates its own IDs so there's no need for lastinsertid. Trying to use lastinsertids anyway will only result in a lot of pain working with persistence.js.

paul-piro commented 9 years ago

and if a do a manual insert how do i get the last id?