Skip to content

Commit

Permalink
* the insert_replace operation must return the last inserted id
Browse files Browse the repository at this point in the history
 * reordered some methods
  • Loading branch information
xavierlacot committed Nov 15, 2013
1 parent 061be13 commit 924aaac
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions joli.js
Expand Up @@ -453,6 +453,7 @@ var joliCreator = function() {
rows = joli.connection.execute(query);
return this.getCount(rows);
case 'insert_into':
case 'insert_replace':
joli.connection.execute(query);
return joli.connection.lastInsertRowId();
case 'select':
Expand Down Expand Up @@ -497,10 +498,10 @@ var joliCreator = function() {
return 'delete from ' + this.data.from;
case 'insert_into':
return 'insert into ' + this.data.from + ' (' + this.data.set.join(', ') + ') values (' + this.data.values.join(', ') + ')';
case 'replace':
return 'replace into ' + this.data.from + ' (' + this.data.set.join(', ') + ') values (' + this.data.values.join(', ') + ')';
case 'insert_replace':
return 'insert or replace into ' + this.data.from + ' (' + this.data.set.join(', ') + ') values (' + this.data.values.join(', ') + ')';
case 'replace':
return 'replace into ' + this.data.from + ' (' + this.data.set.join(', ') + ') values (' + this.data.values.join(', ') + ')';
case 'select':
var join = '';

Expand Down Expand Up @@ -663,6 +664,11 @@ var joliCreator = function() {
this.data.from = table;
return this;
},
insertReplace: function(table) {
this.data.operation = 'insert_replace';
this.data.from = table;
return this;
},
join: function(table, local_id, foreign_id) {
this.data.join.push([table, local_id, foreign_id]);
return this;
Expand All @@ -688,11 +694,6 @@ var joliCreator = function() {
this.data.from = table;
return this;
},
insertReplace: function(table) {
this.data.operation = 'insert_replace';
this.data.from = table;
return this;
},
select: function(columns) {
this.data.operation = 'select';

Expand Down

0 comments on commit 924aaac

Please sign in to comment.