From 371acb75a7e1cbbd6b9de8ef437ee31c50c54f69 Mon Sep 17 00:00:00 2001
From: rblalock <rickblalock@mac.com>
Date: Thu, 11 Jul 2013 10:03:15 -0400
Subject: [PATCH 1/3] Added insert or replace via insertReplace()

---
 joli.js | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/joli.js b/joli.js
index 12a7652..76f7407 100644
--- a/joli.js
+++ b/joli.js
@@ -495,6 +495,8 @@ var joliCreator = function() {
                     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 'select':
                     var join = '';
 
@@ -674,6 +676,11 @@ 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';
 

From 061be1331b0a4af5bcbb346c07e64dcbd6fcea7d Mon Sep 17 00:00:00 2001
From: Martin Hipp <martin.hipp@gmail.com>
Date: Wed, 28 Aug 2013 21:17:11 +1200
Subject: [PATCH 2/3] Added .offset() method to joli.query

---
 joli.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/joli.js b/joli.js
index 76f7407..6cfdb5c 100644
--- a/joli.js
+++ b/joli.js
@@ -251,6 +251,10 @@ var joliCreator = function() {
                 q.limit(constraints.limit);
             }
 
+            if (constraints.limit && constraints.offset) {
+                q.offset(constraints.offset);
+            }
+
             return q.execute();
         },
         count: function(constraints) {
@@ -539,6 +543,10 @@ var joliCreator = function() {
                 query += ' limit ' + this.data.limit;
             }
 
+            if (this.data.limit && this.data.offset) {
+                query += ' offset ' + this.data.offset;
+            }
+
             return query;
         },
         groupBy: function(group) {
@@ -663,6 +671,10 @@ var joliCreator = function() {
             this.data.limit = limit;
             return this;
         },
+        offset: function(offset) {
+            this.data.offset = offset;
+            return this;
+        },
         order: function(order) {
             if ('string' === joli.getType(order)) {
                 order = [order];

From 924aaac11fd84ef32a1612a10619302b6f0ebe87 Mon Sep 17 00:00:00 2001
From: Xavier Lacot <xavier@lacot.org>
Date: Fri, 15 Nov 2013 23:17:54 +0100
Subject: [PATCH 3/3]  * the insert_replace operation must return the last
 inserted id  * reordered some methods

---
 joli.js | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/joli.js b/joli.js
index 6cfdb5c..6416476 100644
--- a/joli.js
+++ b/joli.js
@@ -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':
@@ -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 = '';
 
@@ -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;
@@ -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';
 
