@mcpher/gas-fakes 2.3.5 → 2.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/appsscript.json +3 -3
- package/main.js +3 -5
- package/package.json +1 -1
- package/src/cli/setup.js +4 -5
- package/src/cli/utils.js +24 -4
- package/src/services/jdbc/fakejdbcarray.js +37 -0
- package/src/services/jdbc/fakejdbcbigdecimal.js +63 -0
- package/src/services/jdbc/fakejdbcblob.js +67 -0
- package/src/services/jdbc/fakejdbcclob.js +67 -0
- package/src/services/jdbc/fakejdbcconnection.js +28 -7
- package/src/services/jdbc/fakejdbcdatabasemetadata.js +492 -0
- package/src/services/jdbc/fakejdbcpreparedstatement.js +130 -0
- package/src/services/jdbc/fakejdbcresultset.js +227 -5
- package/src/services/jdbc/fakejdbcresultsetmetadata.js +8 -0
- package/src/services/jdbc/fakejdbcservice.js +39 -29
- package/src/services/jdbc/fakejdbcstatement.js +153 -7
- package/src/support/fakeinputstream.js +42 -0
- package/src/support/metadata.js +16 -0
- package/src/support/sxjdbc.js +74 -6
- package/src/support/syncit.js +30 -2
package/src/support/sxjdbc.js
CHANGED
|
@@ -128,22 +128,90 @@ export const sxJdbcQuery = async (Auth, { connectionId, sql }) => {
|
|
|
128
128
|
|
|
129
129
|
if (type === 'pg') {
|
|
130
130
|
const result = await client.query(sql);
|
|
131
|
+
const rows = Array.isArray(result) ? result[result.length - 1].rows : result.rows;
|
|
132
|
+
const fields = Array.isArray(result) ? result[result.length - 1].fields : result.fields;
|
|
133
|
+
const rowCount = Array.isArray(result) ? result[result.length - 1].rowCount : result.rowCount;
|
|
134
|
+
|
|
131
135
|
return {
|
|
132
|
-
rows:
|
|
133
|
-
fields:
|
|
134
|
-
rowCount:
|
|
136
|
+
rows: rows || [],
|
|
137
|
+
fields: fields || [],
|
|
138
|
+
rowCount: rowCount || 0,
|
|
135
139
|
};
|
|
136
140
|
} else if (type === 'mysql') {
|
|
137
141
|
// mysql2 returns [rows, fields]
|
|
138
142
|
const [rows, fields] = await client.query(sql);
|
|
139
143
|
return {
|
|
140
|
-
rows: rows,
|
|
141
|
-
fields: fields, // mysql2 fields are objects with name, columnType, etc.
|
|
142
|
-
rowCount: rows.length || 0,
|
|
144
|
+
rows: rows || [],
|
|
145
|
+
fields: fields || [], // mysql2 fields are objects with name, columnType, etc.
|
|
146
|
+
rowCount: (rows && rows.insertId) ? 1 : (rows && rows.affectedRows) || (rows && rows.length) || 0,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Executes a prepared statement on a given connection.
|
|
153
|
+
* @param {import('./auth.js').Auth} Auth
|
|
154
|
+
* @param {object} params
|
|
155
|
+
* @param {string} params.connectionId The stored connection ID
|
|
156
|
+
* @param {string} params.sql The SQL query with placeholders
|
|
157
|
+
* @param {any[]} params.values The parameter values
|
|
158
|
+
* @returns {object} The query result
|
|
159
|
+
*/
|
|
160
|
+
export const sxJdbcExecutePrepared = async (Auth, { connectionId, sql, values }) => {
|
|
161
|
+
const entry = connections.get(connectionId);
|
|
162
|
+
if (!entry) throw new Error('Invalid or closed JDBC connection.');
|
|
163
|
+
|
|
164
|
+
const { client, type } = entry;
|
|
165
|
+
|
|
166
|
+
if (type === 'pg') {
|
|
167
|
+
// pg uses $1, $2, etc. so we must convert ? to $n
|
|
168
|
+
let index = 1;
|
|
169
|
+
const pgSql = sql.replace(/\?/g, () => `$${index++}`);
|
|
170
|
+
const result = await client.query(pgSql, values);
|
|
171
|
+
return {
|
|
172
|
+
rows: result.rows || [],
|
|
173
|
+
fields: result.fields || [],
|
|
174
|
+
rowCount: result.rowCount || 0,
|
|
175
|
+
};
|
|
176
|
+
} else if (type === 'mysql') {
|
|
177
|
+
// mysql2 natively supports ? placeholders
|
|
178
|
+
const [rows, fields] = await client.execute(sql, values);
|
|
179
|
+
return {
|
|
180
|
+
rows: rows || [],
|
|
181
|
+
fields: fields || [],
|
|
182
|
+
rowCount: (rows && (rows.affectedRows || rows.length)) || 0,
|
|
143
183
|
};
|
|
144
184
|
}
|
|
145
185
|
};
|
|
146
186
|
|
|
187
|
+
export const sxJdbcCommit = async (Auth, { connectionId }) => {
|
|
188
|
+
return sxJdbcQuery(Auth, { connectionId, sql: 'COMMIT' });
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const sxJdbcRollback = async (Auth, { connectionId }) => {
|
|
192
|
+
return sxJdbcQuery(Auth, { connectionId, sql: 'ROLLBACK' });
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Sets auto-commit mode for the connection.
|
|
197
|
+
* Note: Node drivers are technically always in a state where BEGIN is needed for transactions.
|
|
198
|
+
* @param {import('./auth.js').Auth} Auth
|
|
199
|
+
* @param {object} params
|
|
200
|
+
* @param {string} params.connectionId The stored connection ID
|
|
201
|
+
* @param {boolean} params.autoCommit Whether to enable auto-commit
|
|
202
|
+
*/
|
|
203
|
+
export const sxJdbcSetAutoCommit = async (Auth, { connectionId, autoCommit }) => {
|
|
204
|
+
const entry = connections.get(connectionId);
|
|
205
|
+
if (!entry) throw new Error('Invalid or closed JDBC connection.');
|
|
206
|
+
|
|
207
|
+
if (!autoCommit) {
|
|
208
|
+
// If turning off auto-commit, start a transaction
|
|
209
|
+
await sxJdbcQuery(Auth, { connectionId, sql: 'BEGIN' });
|
|
210
|
+
}
|
|
211
|
+
entry.autoCommit = autoCommit;
|
|
212
|
+
return true;
|
|
213
|
+
};
|
|
214
|
+
|
|
147
215
|
/**
|
|
148
216
|
* Closes a given connection.
|
|
149
217
|
* @param {import('./auth.js').Auth} Auth
|
package/src/support/syncit.js
CHANGED
|
@@ -414,8 +414,16 @@ const fxTestRetry = (errorMessage) => {
|
|
|
414
414
|
|
|
415
415
|
const fxJdbcConnect = (url, user, password) => {
|
|
416
416
|
const args = { url };
|
|
417
|
-
if (user
|
|
418
|
-
|
|
417
|
+
if (typeof user === 'object' && user !== null) {
|
|
418
|
+
// Handling info object
|
|
419
|
+
args.user = user.user || user.userName;
|
|
420
|
+
args.password = user.password;
|
|
421
|
+
// We could pass the whole object if the worker was ready for it,
|
|
422
|
+
// but for now let's just stick to user/pass.
|
|
423
|
+
} else {
|
|
424
|
+
if (user !== null && typeof user !== 'undefined') args.user = user;
|
|
425
|
+
if (password !== null && typeof password !== 'undefined') args.password = password;
|
|
426
|
+
}
|
|
419
427
|
return safeCallSync("sxJdbcConnect", args);
|
|
420
428
|
};
|
|
421
429
|
|
|
@@ -423,6 +431,22 @@ const fxJdbcQuery = (connectionId, sql) => {
|
|
|
423
431
|
return safeCallSync("sxJdbcQuery", { connectionId, sql });
|
|
424
432
|
};
|
|
425
433
|
|
|
434
|
+
const fxJdbcExecutePrepared = (connectionId, sql, values) => {
|
|
435
|
+
return safeCallSync("sxJdbcExecutePrepared", { connectionId, sql, values });
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const fxJdbcCommit = (connectionId) => {
|
|
439
|
+
return safeCallSync("sxJdbcCommit", { connectionId });
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const fxJdbcRollback = (connectionId) => {
|
|
443
|
+
return safeCallSync("sxJdbcRollback", { connectionId });
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const fxJdbcSetAutoCommit = (connectionId, autoCommit) => {
|
|
447
|
+
return safeCallSync("sxJdbcSetAutoCommit", { connectionId, autoCommit });
|
|
448
|
+
};
|
|
449
|
+
|
|
426
450
|
const fxJdbcClose = (connectionId) => {
|
|
427
451
|
return safeCallSync("sxJdbcClose", { connectionId });
|
|
428
452
|
};
|
|
@@ -497,5 +521,9 @@ export const Syncit = {
|
|
|
497
521
|
fxTestRetry,
|
|
498
522
|
fxJdbcConnect,
|
|
499
523
|
fxJdbcQuery,
|
|
524
|
+
fxJdbcExecutePrepared,
|
|
525
|
+
fxJdbcCommit,
|
|
526
|
+
fxJdbcRollback,
|
|
527
|
+
fxJdbcSetAutoCommit,
|
|
500
528
|
fxJdbcClose
|
|
501
529
|
}
|