Skip to content

Commit b5cd968

Browse files
author
Kyle Farris
committed
Accomplishes #32 - Implement insert_batch as described in docs
1 parent d1c48d7 commit b5cd968

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

drivers/mssql/query_exec.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ class QueryExec extends QueryBuilder {
9999
this._exec(sql,cb);
100100
}
101101

102-
insert(table,set,cb,ignore,suffix) {
103-
const sql = this._insert(table,set,ignore,suffix);
102+
insert(table, set, cb, ignore, suffix) {
103+
const sql = this._insert(table, set, ignore, suffix);
104104
this.reset_query(sql);
105105
this._exec(sql,cb);
106106
}
107107

108-
insert_ignore(table,set,on_dupe,cb) {
109-
throw new Error("This feature is currently unsupported in the MSSQL driver.");
108+
insert_ignore(table, set, on_dupe, cb) {
109+
throw new Error("insert_ignore(): This feature is currently unsupported in the MSSQL driver.");
110110
// if (typeof on_dupe === 'function') {
111111
// cb = on_dupe;
112112
// on_dupe = null;
@@ -116,10 +116,22 @@ class QueryExec extends QueryBuilder {
116116
// this._exec(sql,cb);
117117
}
118118

119-
insert_batch(table,set,cb) {
120-
const sql = this._insert_batch(table,set);
119+
insert_batch(table, set, ignore, on_dupe, cb) {
120+
if (typeof ignore === 'function') {
121+
cb = ignore;
122+
ignore = null;
123+
}
124+
else if (typeof on_dupe === 'function') {
125+
cb = on_dupe;
126+
on_dupe = null;
127+
}
128+
129+
if (ignore) throw new Error("QE insert_batch(): INSERT IGNORE is currently unsupported on the MSSQL driver.");
130+
if (suffix) throw new Error("QE insert_batch(): 'on_dupe' string (4th parameter) is currently unsupported on the MSSQL driver.");
131+
132+
const sql = this._insert_batch(table, set);
121133
this.reset_query(sql);
122-
this._exec(sql,cb);
134+
this._exec(sql, cb);
123135
}
124136

125137
update(table,set,where,cb) {

drivers/mysql/query_exec.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,33 @@ class QueryExec extends QueryBuilder {
8787
}
8888

8989
insert(table,set,cb,ignore,suffix) {
90-
const sql = this._insert(table,set,ignore,suffix);
90+
const sql = this._insert(table, set, ignore, suffix);
9191
this.reset_query(sql);
92-
this._exec(sql,cb);
92+
this._exec(sql, cb);
9393
}
9494

95-
insert_ignore(table,set,on_dupe,cb) {
95+
insert_ignore(table, set, on_dupe, cb) {
9696
if (typeof on_dupe === 'function') {
9797
cb = on_dupe;
9898
on_dupe = null;
9999
}
100-
const sql = this._insert_ignore(table,set,on_dupe);
100+
const sql = this._insert_ignore(table, set, on_dupe);
101101
this.reset_query(sql);
102102
this._exec(sql,cb);
103103
}
104104

105-
insert_batch(table,set,cb) {
106-
const sql = this._insert_batch(table,set);
105+
insert_batch(table, set, ignore, on_dupe, cb) {
106+
if (typeof ignore === 'function') {
107+
cb = ignore;
108+
ignore = null;
109+
}
110+
else if (typeof on_dupe === 'function') {
111+
cb = on_dupe;
112+
on_dupe = null;
113+
}
114+
const sql = this._insert_batch(table, set, ignore, on_dupe);
107115
this.reset_query(sql);
108-
this._exec(sql,cb);
116+
this._exec(sql, cb);
109117
}
110118

111119
update(table,set,where,cb) {
@@ -121,9 +129,9 @@ class QueryExec extends QueryBuilder {
121129
where = null;
122130
}
123131

124-
const sql = this._update(table,set,where);
132+
const sql = this._update(table, set, where);
125133
this.reset_query(sql);
126-
this._exec(sql,cb);
134+
this._exec(sql, cb);
127135
}
128136

129137
// TODO: Write this complicated-ass function
@@ -140,7 +148,7 @@ class QueryExec extends QueryBuilder {
140148
where = null;
141149
}
142150

143-
const sqls = this._update_batch(table,set,index,where);
151+
const sqls = this._update_batch(table, set, index, where);
144152
const results = null;
145153
const errors = [];
146154

0 commit comments

Comments
 (0)